Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/cluster/EnvironmentService.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,11 @@ func (impl EnvironmentServiceImpl) GetEnvironmentListForAutocomplete(isDeploymen
allowedDeploymentConfigString []string
)
deploymentConfigValues, _ := impl.attributesRepository.FindByKey(fmt.Sprintf("%d", model.Id))
if err = json.Unmarshal([]byte(deploymentConfigValues.Value), &deploymentConfig); err != nil {
return nil, err
//if empty config received(doesn't exist in table) which can't be parsed
if deploymentConfigValues.Value != "" {
if err = json.Unmarshal([]byte(deploymentConfigValues.Value), &deploymentConfig); err != nil {
return nil, err
}
}

// if real config along with absurd values exist in table {"argo_cd": true, "helm": false, "absurd": false}",
Expand Down
15 changes: 9 additions & 6 deletions pkg/pipeline/PipelineBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1856,13 +1856,16 @@ func (impl PipelineBuilderImpl) CreateCdPipelines(pipelineCreateRequest *bean.Cd
func (impl PipelineBuilderImpl) validateDeploymentAppType(pipeline *bean.CDPipelineConfigObject) error {
var deploymentConfig map[string]bool
deploymentConfigValues, _ := impl.attributesRepository.FindByKey(fmt.Sprintf("%d", pipeline.EnvironmentId))
if err := json.Unmarshal([]byte(deploymentConfigValues.Value), &deploymentConfig); err != nil {
rerr := &util.ApiError{
HttpStatusCode: http.StatusInternalServerError,
InternalMessage: err.Error(),
UserMessage: "Failed to fetch deployment config values from the attributes table",
//if empty config received(doesn't exist in table) which can't be parsed
if deploymentConfigValues.Value != "" {
if err := json.Unmarshal([]byte(deploymentConfigValues.Value), &deploymentConfig); err != nil {
rerr := &util.ApiError{
HttpStatusCode: http.StatusInternalServerError,
InternalMessage: err.Error(),
UserMessage: "Failed to fetch deployment config values from the attributes table",
}
return rerr
}
return rerr
}

// Config value doesn't exist in attribute table
Expand Down
27 changes: 26 additions & 1 deletion pkg/pipeline/PipelineBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,32 @@ func TestPipelineBuilderImpl_validateDeploymentAppType(t *testing.T) {
mockDeploymentConfigConfig := &repository.Attributes{
Id: 1,
Key: "2",
Value: "",
Value: "{\"argo_cd\": true, \"helm\": true}",
Active: false,
AuditLog: sql.AuditLog{},
}
mockError := error(nil)
attributesRepoMock.On("FindByKey", mock.Anything).Return(mockDeploymentConfigConfig, mockError)

err := impl.validateDeploymentAppType(pipeline)
assert.Nil(t, err)
})

t.Run("JsonUnmarshalThrowsErrorParsingDeploymentConfigValue", func(t *testing.T) {
attributesRepoMock := mocks.NewAttributesRepository(t)

impl := PipelineBuilderImpl{
attributesRepository: attributesRepoMock, // Provide a mock implementation of attributesRepository
}
pipeline := &bean.CDPipelineConfigObject{
EnvironmentId: 123,
DeploymentAppType: "SomeAppType",
}

mockDeploymentConfigConfig := &repository.Attributes{
Id: 1,
Key: "2",
Value: "absurd_value",
Active: false,
AuditLog: sql.AuditLog{},
}
Expand Down