Skip to content

Commit d99e764

Browse files
authored
fix remarks for tas yml segregation (#232)
1 parent 7ab24a3 commit d99e764

File tree

6 files changed

+20
-38
lines changed

6 files changed

+20
-38
lines changed

pkg/core/interfaces.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type PayloadManager interface {
1616
// TASConfigManager defines operations for tas config
1717
type TASConfigManager interface {
1818
// LoadAndValidate loads and returns the tas config
19-
LoadAndValidate(ctx context.Context, version int, path string, eventType EventType, licenseTier Tier) (interface{}, error)
19+
LoadAndValidate(ctx context.Context, version int, path string, eventType EventType, licenseTier Tier,
20+
tasFilePathInRepo string) (interface{}, error)
2021

2122
// GetVersion returns TAS yml version
2223
GetVersion(path string) (int, error)

pkg/driver/driver_v1.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type (
4646

4747
func (d *driverV1) RunDiscovery(ctx context.Context, payload *core.Payload,
4848
taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error {
49-
tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier)
49+
tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier, d.TASFilePath)
5050
if err != nil {
5151
d.logger.Errorf("Unable to load tas yaml file, error: %v", err)
5252
err = &errs.StatusFailed{Remark: err.Error()}
@@ -120,7 +120,7 @@ func (d *driverV1) RunDiscovery(ctx context.Context, payload *core.Payload,
120120

121121
func (d *driverV1) RunExecution(ctx context.Context, payload *core.Payload,
122122
taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error {
123-
tas, err := d.TASConfigManager.LoadAndValidate(ctx, 1, d.TASFilePath, payload.EventType, payload.LicenseTier)
123+
tas, err := d.TASConfigManager.LoadAndValidate(ctx, 1, d.TASFilePath, payload.EventType, payload.LicenseTier, d.TASFilePath)
124124
if err != nil {
125125
d.logger.Errorf("Unable to load tas yaml file, error: %v", err)
126126
err = &errs.StatusFailed{Remark: err.Error()}

pkg/driver/driver_v2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (d *driverV2) RunDiscovery(ctx context.Context, payload *core.Payload,
5252
taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error {
5353
// do something
5454
d.logger.Debugf("Running in %d version", d.TASVersion)
55-
tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier)
55+
tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier, d.TASFilePath)
5656
if err != nil {
5757
d.logger.Errorf("Unable to load tas yaml file, error: %v", err)
5858
err = &errs.StatusFailed{Remark: err.Error()}
@@ -97,7 +97,7 @@ func (d *driverV2) RunDiscovery(ctx context.Context, payload *core.Payload,
9797

9898
func (d *driverV2) RunExecution(ctx context.Context, payload *core.Payload,
9999
taskPayload *core.TaskPayload, oauth *core.Oauth, coverageDir string, secretMap map[string]string) error {
100-
tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier)
100+
tas, err := d.TASConfigManager.LoadAndValidate(ctx, d.TASVersion, d.TASFilePath, payload.EventType, payload.LicenseTier, d.TASFilePath)
101101
if err != nil {
102102
d.logger.Errorf("Unable to load tas yaml file, error: %v", err)
103103
err = &errs.StatusFailed{Remark: err.Error()}

pkg/tasconfigdownloader/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (t *TASConfigDownloader) GetTASConfig(ctx context.Context, gitProvider, com
3838
return nil, err
3939
}
4040

41-
tasConfig, err := t.tasconfigmanager.LoadAndValidate(ctx, version, ymlPath, eventType, licenseTier)
41+
tasConfig, err := t.tasconfigmanager.LoadAndValidate(ctx, version, ymlPath, eventType, licenseTier, filePath)
4242
if err != nil {
4343
t.logger.Errorf("error while parsing yml for commitID %s error %v", commitID, err)
4444
return nil, err

pkg/tasconfigmanager/setup.go

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,19 @@ func (tc *tasConfigManager) LoadAndValidate(ctx context.Context,
3939
version int,
4040
path string,
4141
eventType core.EventType,
42-
licenseTier core.Tier) (interface{}, error) {
43-
if version < global.NewTASVersion {
44-
return tc.loadAndValidateV1(ctx, path, eventType, licenseTier)
45-
}
46-
return tc.loadAndValidateV2(ctx, path, eventType, licenseTier)
47-
}
48-
49-
func (tc *tasConfigManager) loadAndValidateV1(ctx context.Context,
50-
filePath string,
51-
eventType core.EventType,
52-
licenseTier core.Tier) (*core.TASConfig, error) {
53-
yamlFile, err := os.ReadFile(filePath)
42+
licenseTier core.Tier, tasFilePathInRepo string) (interface{}, error) {
43+
yamlFile, err := os.ReadFile(path)
5444
if err != nil {
55-
tc.logger.Errorf("Error while reading file %s, error %v", filePath, err)
56-
return nil, errs.New(fmt.Sprintf("Error while reading configuration file at path: %s", filePath))
45+
if errors.Is(err, os.ErrNotExist) {
46+
return nil, errs.New(fmt.Sprintf("Configuration file not found at path: %s", tasFilePathInRepo))
47+
}
48+
tc.logger.Errorf("Error while reading file, error %v", err)
49+
return nil, errs.New(fmt.Sprintf("Error while reading configuration file at path: %s", tasFilePathInRepo))
5750
}
58-
return tc.validateYMLV1(ctx, yamlFile, eventType, licenseTier, filePath)
51+
if version < global.NewTASVersion {
52+
return tc.validateYMLV1(ctx, yamlFile, eventType, licenseTier, tasFilePathInRepo)
53+
}
54+
return tc.validateYMLV2(ctx, yamlFile, eventType, licenseTier, tasFilePathInRepo)
5955
}
6056

6157
func (tc *tasConfigManager) validateYMLV1(ctx context.Context,
@@ -170,21 +166,6 @@ func (tc *tasConfigManager) GetVersion(path string) (int, error) {
170166
return versionYml, nil
171167
}
172168

173-
func (tc *tasConfigManager) loadAndValidateV2(ctx context.Context,
174-
yamlFilePath string,
175-
eventType core.EventType,
176-
licenseTier core.Tier) (*core.TASConfigV2, error) {
177-
yamlFile, err := os.ReadFile(yamlFilePath)
178-
if err != nil {
179-
if errors.Is(err, os.ErrNotExist) {
180-
return nil, errs.New(fmt.Sprintf("Configuration file not found at path: %s", yamlFilePath))
181-
}
182-
tc.logger.Errorf("Error while reading file, error %v", err)
183-
return nil, errs.New(fmt.Sprintf("Error while reading configuration file at path: %s", yamlFilePath))
184-
}
185-
return tc.validateYMLV2(ctx, yamlFile, eventType, licenseTier, yamlFilePath)
186-
}
187-
188169
func (tc *tasConfigManager) GetTasConfigFilePath(payload *core.Payload) (string, error) {
189170
// load tas yaml file
190171
filePath, err := utils.GetTASFilePath(payload.TasFileName)

pkg/tasconfigmanager/setup_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestLoadAndValidateV1(t *testing.T) {
157157
},
158158
}
159159
for _, tt := range tests {
160-
tas, err := tasConfigManager.LoadAndValidate(ctx, 1, tt.FilePath, tt.EventType, core.Small)
160+
tas, err := tasConfigManager.LoadAndValidate(ctx, 1, tt.FilePath, tt.EventType, core.Small, tt.FilePath)
161161
if err != nil {
162162
assert.Equal(t, err.Error(), tt.wantErr.Error(), "error mismatch")
163163
} else {
@@ -280,7 +280,7 @@ func TestLoadAndValidateV2(t *testing.T) {
280280
},
281281
}
282282
for _, tt := range tests {
283-
tas, err := tasConfigManager.LoadAndValidate(ctx, 2, tt.FilePath, tt.EventType, core.Small)
283+
tas, err := tasConfigManager.LoadAndValidate(ctx, 2, tt.FilePath, tt.EventType, core.Small, tt.FilePath)
284284
if err != nil {
285285
assert.Equal(t, err.Error(), tt.wantErr.Error(), "error mismatch")
286286
} else {

0 commit comments

Comments
 (0)