From d99e76461c5a3081e26abf62488f5084edfe62f9 Mon Sep 17 00:00:00 2001 From: Vikrant Kumar Sinha <96419531+VikrantKS@users.noreply.github.com> Date: Thu, 4 Aug 2022 12:07:04 +0530 Subject: [PATCH] fix remarks for tas yml segregation (#232) --- pkg/core/interfaces.go | 3 ++- pkg/driver/driver_v1.go | 4 +-- pkg/driver/driver_v2.go | 4 +-- pkg/tasconfigdownloader/setup.go | 2 +- pkg/tasconfigmanager/setup.go | 41 ++++++++---------------------- pkg/tasconfigmanager/setup_test.go | 4 +-- 6 files changed, 20 insertions(+), 38 deletions(-) diff --git a/pkg/core/interfaces.go b/pkg/core/interfaces.go index acef7bd..ed5499f 100644 --- a/pkg/core/interfaces.go +++ b/pkg/core/interfaces.go @@ -16,7 +16,8 @@ type PayloadManager interface { // TASConfigManager defines operations for tas config type TASConfigManager interface { // LoadAndValidate loads and returns the tas config - LoadAndValidate(ctx context.Context, version int, path string, eventType EventType, licenseTier Tier) (interface{}, error) + LoadAndValidate(ctx context.Context, version int, path string, eventType EventType, licenseTier Tier, + tasFilePathInRepo string) (interface{}, error) // GetVersion returns TAS yml version GetVersion(path string) (int, error) diff --git a/pkg/driver/driver_v1.go b/pkg/driver/driver_v1.go index c508e92..de2d7ae 100644 --- a/pkg/driver/driver_v1.go +++ b/pkg/driver/driver_v1.go @@ -46,7 +46,7 @@ type ( func (d *driverV1) RunDiscovery(ctx context.Context, payload *core.Payload, taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error { - tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier) + tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier, d.TASFilePath) if err != nil { d.logger.Errorf("Unable to load tas yaml file, error: %v", err) err = &errs.StatusFailed{Remark: err.Error()} @@ -120,7 +120,7 @@ func (d *driverV1) RunDiscovery(ctx context.Context, payload *core.Payload, func (d *driverV1) RunExecution(ctx context.Context, payload *core.Payload, taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error { - tas, err := d.TASConfigManager.LoadAndValidate(ctx, 1, d.TASFilePath, payload.EventType, payload.LicenseTier) + tas, err := d.TASConfigManager.LoadAndValidate(ctx, 1, d.TASFilePath, payload.EventType, payload.LicenseTier, d.TASFilePath) if err != nil { d.logger.Errorf("Unable to load tas yaml file, error: %v", err) err = &errs.StatusFailed{Remark: err.Error()} diff --git a/pkg/driver/driver_v2.go b/pkg/driver/driver_v2.go index 34bb8be..6baf5d7 100644 --- a/pkg/driver/driver_v2.go +++ b/pkg/driver/driver_v2.go @@ -52,7 +52,7 @@ func (d *driverV2) RunDiscovery(ctx context.Context, payload *core.Payload, taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error { // do something d.logger.Debugf("Running in %d version", d.TASVersion) - tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier) + tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier, d.TASFilePath) if err != nil { d.logger.Errorf("Unable to load tas yaml file, error: %v", err) err = &errs.StatusFailed{Remark: err.Error()} @@ -97,7 +97,7 @@ func (d *driverV2) RunDiscovery(ctx context.Context, payload *core.Payload, func (d *driverV2) RunExecution(ctx context.Context, payload *core.Payload, taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error { - tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier) + tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier, d.TASFilePath) if err != nil { d.logger.Errorf("Unable to load tas yaml file, error: %v", err) err = &errs.StatusFailed{Remark: err.Error()} diff --git a/pkg/tasconfigdownloader/setup.go b/pkg/tasconfigdownloader/setup.go index c666734..312d603 100644 --- a/pkg/tasconfigdownloader/setup.go +++ b/pkg/tasconfigdownloader/setup.go @@ -38,7 +38,7 @@ func (t *TASConfigDownloader) GetTASConfig(ctx context.Context, gitProvider, com return nil, err } - tasConfig, err := t.tasconfigmanager.LoadAndValidate(ctx, version, ymlPath, eventType, licenseTier) + tasConfig, err := t.tasconfigmanager.LoadAndValidate(ctx, version, ymlPath, eventType, licenseTier, filePath) if err != nil { t.logger.Errorf("error while parsing yml for commitID %s error %v", commitID, err) return nil, err diff --git a/pkg/tasconfigmanager/setup.go b/pkg/tasconfigmanager/setup.go index 025ad97..3beee82 100644 --- a/pkg/tasconfigmanager/setup.go +++ b/pkg/tasconfigmanager/setup.go @@ -39,23 +39,19 @@ func (tc *tasConfigManager) LoadAndValidate(ctx context.Context, version int, path string, eventType core.EventType, - licenseTier core.Tier) (interface{}, error) { - if version < global.NewTASVersion { - return tc.loadAndValidateV1(ctx, path, eventType, licenseTier) - } - return tc.loadAndValidateV2(ctx, path, eventType, licenseTier) -} - -func (tc *tasConfigManager) loadAndValidateV1(ctx context.Context, - filePath string, - eventType core.EventType, - licenseTier core.Tier) (*core.TASConfig, error) { - yamlFile, err := os.ReadFile(filePath) + licenseTier core.Tier, tasFilePathInRepo string) (interface{}, error) { + yamlFile, err := os.ReadFile(path) if err != nil { - tc.logger.Errorf("Error while reading file %s, error %v", filePath, err) - return nil, errs.New(fmt.Sprintf("Error while reading configuration file at path: %s", filePath)) + if errors.Is(err, os.ErrNotExist) { + return nil, errs.New(fmt.Sprintf("Configuration file not found at path: %s", tasFilePathInRepo)) + } + tc.logger.Errorf("Error while reading file, error %v", err) + return nil, errs.New(fmt.Sprintf("Error while reading configuration file at path: %s", tasFilePathInRepo)) } - return tc.validateYMLV1(ctx, yamlFile, eventType, licenseTier, filePath) + if version < global.NewTASVersion { + return tc.validateYMLV1(ctx, yamlFile, eventType, licenseTier, tasFilePathInRepo) + } + return tc.validateYMLV2(ctx, yamlFile, eventType, licenseTier, tasFilePathInRepo) } func (tc *tasConfigManager) validateYMLV1(ctx context.Context, @@ -170,21 +166,6 @@ func (tc *tasConfigManager) GetVersion(path string) (int, error) { return versionYml, nil } -func (tc *tasConfigManager) loadAndValidateV2(ctx context.Context, - yamlFilePath string, - eventType core.EventType, - licenseTier core.Tier) (*core.TASConfigV2, error) { - yamlFile, err := os.ReadFile(yamlFilePath) - if err != nil { - if errors.Is(err, os.ErrNotExist) { - return nil, errs.New(fmt.Sprintf("Configuration file not found at path: %s", yamlFilePath)) - } - tc.logger.Errorf("Error while reading file, error %v", err) - return nil, errs.New(fmt.Sprintf("Error while reading configuration file at path: %s", yamlFilePath)) - } - return tc.validateYMLV2(ctx, yamlFile, eventType, licenseTier, yamlFilePath) -} - func (tc *tasConfigManager) GetTasConfigFilePath(payload *core.Payload) (string, error) { // load tas yaml file filePath, err := utils.GetTASFilePath(payload.TasFileName) diff --git a/pkg/tasconfigmanager/setup_test.go b/pkg/tasconfigmanager/setup_test.go index 1cf13b5..f6ee984 100644 --- a/pkg/tasconfigmanager/setup_test.go +++ b/pkg/tasconfigmanager/setup_test.go @@ -157,7 +157,7 @@ func TestLoadAndValidateV1(t *testing.T) { }, } for _, tt := range tests { - tas, err := tasConfigManager.LoadAndValidate(ctx, 1, tt.FilePath, tt.EventType, core.Small) + tas, err := tasConfigManager.LoadAndValidate(ctx, 1, tt.FilePath, tt.EventType, core.Small, tt.FilePath) if err != nil { assert.Equal(t, err.Error(), tt.wantErr.Error(), "error mismatch") } else { @@ -280,7 +280,7 @@ func TestLoadAndValidateV2(t *testing.T) { }, } for _, tt := range tests { - tas, err := tasConfigManager.LoadAndValidate(ctx, 2, tt.FilePath, tt.EventType, core.Small) + tas, err := tasConfigManager.LoadAndValidate(ctx, 2, tt.FilePath, tt.EventType, core.Small, tt.FilePath) if err != nil { assert.Equal(t, err.Error(), tt.wantErr.Error(), "error mismatch") } else {
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: