diff --git a/api/appbean/AppDetail.go b/api/appbean/AppDetail.go index e4f580b0fd6..7da09df2529 100644 --- a/api/appbean/AppDetail.go +++ b/api/appbean/AppDetail.go @@ -179,9 +179,10 @@ type Secret struct { } type ConfigMapSecretDataVolumeUsageConfig struct { - MountPath string `json:"mountPath"` - SubPath bool `json:"subPath"` - FilePermission string `json:"filePermission"` + MountPath string `json:"mountPath"` + SubPath bool `json:"subPath"` + FilePermission string `json:"filePermission"` + ESOSubPath []string `json:"esoSubPath"` } type ExternalSecret struct { diff --git a/api/bean/ConfigMapAndSecret.go b/api/bean/ConfigMapAndSecret.go index aad1a66ff95..abb1714b24c 100644 --- a/api/bean/ConfigMapAndSecret.go +++ b/api/bean/ConfigMapAndSecret.go @@ -54,6 +54,7 @@ type ConfigSecretMap struct { RoleARN string `json:"roleARN"` SecretData json.RawMessage `json:"secretData,omitempty"` SubPath bool `json:"subPath"` + ESOSubPath []string `json:"esoSubPath"` FilePermission string `json:"filePermission"` } @@ -70,7 +71,7 @@ func (configSecretJson *ConfigSecretJson) SetReferencedSecrets(secrets []ConfigS configSecretJson.Secrets = util.GetReferencedArray(secrets) } -func (ConfigSecretRootJson) GetTransformedDataForSecretData(data string, mode util.SecretTransformMode) (string, error) { +func GetTransformedDataForSecretData(data string, mode util.SecretTransformMode) (string, error) { secretsJson := ConfigSecretRootJson{} err := json.Unmarshal([]byte(data), &secretsJson) if err != nil { diff --git a/api/restHandler/CoreAppRestHandler.go b/api/restHandler/CoreAppRestHandler.go index 7e1565c6dc5..efac7046514 100644 --- a/api/restHandler/CoreAppRestHandler.go +++ b/api/restHandler/CoreAppRestHandler.go @@ -891,7 +891,7 @@ func (handler CoreAppRestHandlerImpl) buildAppConfigMaps(appId int, envId int, c } var dataObj map[string]interface{} if data != nil { - err := json.Unmarshal([]byte(data), &dataObj) + err := json.Unmarshal(data, &dataObj) if err != nil { handler.logger.Errorw("service err, un-marshaling of data fail in config map", "err", err, "appId", appId) return nil, err, http.StatusInternalServerError @@ -1041,6 +1041,7 @@ func (handler CoreAppRestHandlerImpl) buildAppSecrets(appId int, envId int, secr globalSecret.DataVolumeUsageConfig = &appBean.ConfigMapSecretDataVolumeUsageConfig{ SubPath: secret.SubPath, FilePermission: secret.FilePermission, + ESOSubPath: secret.ESOSubPath, } considerGlobalDefaultData := envId > 0 && secret.Data == nil if considerGlobalDefaultData { @@ -1486,6 +1487,7 @@ func (handler CoreAppRestHandlerImpl) createGlobalSecrets(appId int, userId int3 secretData.MountPath = dataVolumeUsageConfig.MountPath secretData.SubPath = dataVolumeUsageConfig.SubPath secretData.FilePermission = dataVolumeUsageConfig.FilePermission + secretData.ESOSubPath = dataVolumeUsageConfig.ESOSubPath } if secret.IsExternal { @@ -1989,6 +1991,7 @@ func (handler CoreAppRestHandlerImpl) createEnvSecret(appId int, userId int32, e secretData.MountPath = secretOverrideDataVolumeUsageConfig.MountPath secretData.SubPath = secretOverrideDataVolumeUsageConfig.SubPath secretData.FilePermission = secretOverrideDataVolumeUsageConfig.FilePermission + secretData.ESOSubPath = secretOverrideDataVolumeUsageConfig.ESOSubPath } var secretDataRequest []*bean2.ConfigData secretDataRequest = append(secretDataRequest, secretData) diff --git a/pkg/appClone/AppCloneService.go b/pkg/appClone/AppCloneService.go index 84db1d25639..952d94165af 100644 --- a/pkg/appClone/AppCloneService.go +++ b/pkg/appClone/AppCloneService.go @@ -556,6 +556,7 @@ func (impl *AppCloneServiceImpl) configDataClone(cfData []*bean3.ConfigData) []* ExternalSecretType: refdata.ExternalSecretType, FilePermission: refdata.FilePermission, SubPath: refdata.SubPath, + ESOSubPath: refdata.ESOSubPath, } copiedData = append(copiedData, data) } diff --git a/pkg/bean/configSecretData.go b/pkg/bean/configSecretData.go index 61e55db588f..d172859dc23 100644 --- a/pkg/bean/configSecretData.go +++ b/pkg/bean/configSecretData.go @@ -19,6 +19,7 @@ package bean import ( "encoding/json" "github.com/devtron-labs/devtron/util" + "strings" ) type ConfigList struct { @@ -29,6 +30,7 @@ type SecretList struct { ConfigData []*ConfigData `json:"secrets"` } +// TODO refactoring: duplicate struct of ConfigData in ConfigMapBean.go type ConfigData struct { Name string `json:"name"` Type string `json:"type"` @@ -45,9 +47,14 @@ type ConfigData struct { DefaultESOSecretData ESOSecretData `json:"defaultESOSecretData,omitempty"` RoleARN string `json:"roleARN"` SubPath bool `json:"subPath"` + ESOSubPath []string `json:"esoSubPath"` FilePermission string `json:"filePermission"` } +func (c *ConfigData) IsESOExternalSecretType() bool { + return strings.HasPrefix(c.ExternalSecretType, "ESO") +} + type ExternalSecret struct { Key string `json:"key"` Name string `json:"name"` @@ -58,8 +65,10 @@ type ExternalSecret struct { type ESOSecretData struct { SecretStore json.RawMessage `json:"secretStore,omitempty"` SecretStoreRef json.RawMessage `json:"secretStoreRef,omitempty"` - EsoData []ESOData `json:"esoData"` + ESOData []ESOData `json:"esoData"` RefreshInterval string `json:"refreshInterval,omitempty"` + ESODataFrom json.RawMessage `json:"esoDataFrom,omitempty"` + Template json.RawMessage `json:"template,omitempty"` } type ESOData struct { @@ -68,7 +77,7 @@ type ESOData struct { Property string `json:"property,omitempty"` } -func (ConfigData) GetTransformedDataForSecretData(data string, mode util.SecretTransformMode) (string, error) { +func GetTransformedDataForSecretData(data string, mode util.SecretTransformMode) (string, error) { secretDataMap := make(map[string]*ConfigData) err := json.Unmarshal([]byte(data), &secretDataMap) if err != nil { diff --git a/pkg/pipeline/ConfigMapService.go b/pkg/pipeline/ConfigMapService.go index 906aaf31933..d2e0bb883c9 100644 --- a/pkg/pipeline/ConfigMapService.go +++ b/pkg/pipeline/ConfigMapService.go @@ -487,8 +487,6 @@ func (impl ConfigMapServiceImpl) CMEnvironmentFetch(appId int, envId int) (*bean item.DefaultMountPath = item.MountPath item.Data = nil item.MountPath = "" - item.SubPath = item.SubPath - item.FilePermission = item.FilePermission configDataRequest.ConfigData = append(configDataRequest.ConfigData, item) } } @@ -580,6 +578,7 @@ func (impl ConfigMapServiceImpl) CSGlobalAddUpdate(configMapRequest *bean.Config item.ExternalSecret = configData.ExternalSecret item.RoleARN = configData.RoleARN item.SubPath = configData.SubPath + item.ESOSubPath = configData.ESOSubPath item.FilePermission = configData.FilePermission } configs = append(configs, item) @@ -736,6 +735,7 @@ func (impl ConfigMapServiceImpl) CSEnvironmentAddUpdate(configMapRequest *bean.C item.ExternalSecret = configData.ExternalSecret item.RoleARN = configData.RoleARN item.SubPath = configData.SubPath + item.ESOSubPath = configData.ESOSubPath item.FilePermission = configData.FilePermission found = true } @@ -873,16 +873,16 @@ func (impl ConfigMapServiceImpl) CSEnvironmentFetch(appId int, envId int) (*bean item.DefaultExternalSecret = item.ExternalSecret } item.DefaultESOSecretData = item.ESOSecretData - item.ESOSecretData.EsoData = nil + item.ESOSecretData.ESOData = nil item.ESOSecretData.SecretStore = nil + item.ESOSecretData.ESODataFrom = nil + item.ESOSecretData.Template = nil item.ESOSecretData.SecretStoreRef = nil item.ESOSecretData.RefreshInterval = "" item.DefaultMountPath = item.MountPath item.Data = nil item.ExternalSecret = nil item.MountPath = "" - item.SubPath = item.SubPath - item.FilePermission = item.FilePermission configDataRequest.ConfigData = append(configDataRequest.ConfigData, item) } } @@ -1455,7 +1455,24 @@ func (impl ConfigMapServiceImpl) validateConfigDataForSecretsOnly(configData *be if err != nil { impl.logger.Errorw("error in decoding secret data", "error", err) return false, util.NewApiError().WithHttpStatusCode(http.StatusUnprocessableEntity).WithCode(strconv.Itoa(http.StatusUnprocessableEntity)). - WithUserMessage("error in decoding data, make sure the secret data is encoded properly") + WithUserMessage("error in decoding data, make sure the secret data is encoded properly"). + WithInternalMessage("error in decoding data, make sure the secret data is encoded properly") + } + } + if configData.IsESOExternalSecretType() { + if !configData.External { + return false, util.NewApiError().WithHttpStatusCode(http.StatusBadRequest).WithCode(strconv.Itoa(http.StatusBadRequest)). + WithUserMessage(fmt.Sprintf("external flag should be true for '%s' secret type", configData.ExternalSecretType)). + WithInternalMessage(fmt.Sprintf("external flag should be true for '%s' secret type", configData.ExternalSecretType)) + } + if configData.ESOSecretData.ESODataFrom == nil && configData.ESOSecretData.ESOData == nil { + return false, util.NewApiError().WithHttpStatusCode(http.StatusBadRequest).WithCode(strconv.Itoa(http.StatusBadRequest)). + WithUserMessage("both esoSecretData.esoDataFrom and esoSecretData.esoData can't be empty"). + WithInternalMessage("both esoSecretData.esoDataFrom and esoSecretData.esoData can't be empty") + } else if configData.ESOSecretData.SecretStore == nil && configData.ESOSecretData.SecretStoreRef == nil { + return false, util.NewApiError().WithHttpStatusCode(http.StatusBadRequest).WithCode(strconv.Itoa(http.StatusBadRequest)). + WithUserMessage("both esoSecretData.secretStore and esoSecretData.secretStoreRef can't be empty"). + WithInternalMessage("both esoSecretData.secretStore and esoSecretData.secretStoreRef can't be empty") } } return true, nil diff --git a/pkg/pipeline/bean/ConfigMapBean.go b/pkg/pipeline/bean/ConfigMapBean.go index 2f572bd6058..8a9e78a5ee3 100644 --- a/pkg/pipeline/bean/ConfigMapBean.go +++ b/pkg/pipeline/bean/ConfigMapBean.go @@ -18,6 +18,7 @@ package bean import ( "encoding/json" + "strings" ) type ConfigDataRequest struct { @@ -31,8 +32,10 @@ type ConfigDataRequest struct { type ESOSecretData struct { SecretStore json.RawMessage `json:"secretStore,omitempty"` SecretStoreRef json.RawMessage `json:"secretStoreRef,omitempty"` - EsoData []ESOData `json:"esoData,omitempty"` + ESOData []ESOData `json:"esoData,omitempty"` RefreshInterval string `json:"refreshInterval,omitempty"` + ESODataFrom json.RawMessage `json:"esoDataFrom,omitempty"` + Template json.RawMessage `json:"template,omitempty"` } type ESOData struct { @@ -57,9 +60,15 @@ type ConfigData struct { DefaultExternalSecret []ExternalSecret `json:"defaultSecretData,omitempty"` RoleARN string `json:"roleARN"` SubPath bool `json:"subPath"` + ESOSubPath []string `json:"esoSubPath"` FilePermission string `json:"filePermission"` Overridden bool `json:"overridden"` } + +func (c *ConfigData) IsESOExternalSecretType() bool { + return strings.HasPrefix(c.ExternalSecretType, "ESO") +} + type ExternalSecret struct { Key string `json:"key"` Name string `json:"name"` diff --git a/pkg/pipeline/history/ConfigMapHistoryService.go b/pkg/pipeline/history/ConfigMapHistoryService.go index ad7a20ec9d9..4f56673bd1e 100644 --- a/pkg/pipeline/history/ConfigMapHistoryService.go +++ b/pkg/pipeline/history/ConfigMapHistoryService.go @@ -20,7 +20,7 @@ import ( "context" "encoding/json" "errors" - "strings" + globalUtil "github.com/devtron-labs/devtron/util" "time" "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" @@ -490,7 +490,7 @@ func (impl ConfigMapHistoryServiceImpl) GetHistoryForDeployedCMCSById(ctx contex SubPath: &config.SubPath, FilePermission: config.FilePermission, CodeEditorValue: &HistoryDetailConfig{ - DisplayName: "Data", + DisplayName: DataDisplayName, Value: string(config.Data), VariableSnapshot: variableSnapshotMap, ResolvedValue: resolvedTemplate, @@ -521,13 +521,27 @@ func (impl ConfigMapHistoryServiceImpl) GetHistoryForDeployedCMCSById(ctx contex } historyDto.ExternalSecretType = config.ExternalSecretType historyDto.RoleARN = config.RoleARN + historyDto.ESOSubPath = config.ESOSubPath if config.External { - externalSecretData, err := json.Marshal(config.ExternalSecret) - if err != nil { - impl.logger.Errorw("error in marshaling external secret data", "err", err) - } - if len(externalSecretData) > 0 { - historyDto.CodeEditorValue.Value = string(externalSecretData) + if config.ExternalSecretType == globalUtil.KubernetesSecret { + externalSecretData, err := json.Marshal(config.ExternalSecret) + if err != nil { + impl.logger.Errorw("error in marshaling external secret data", "err", err) + } + if len(externalSecretData) > 0 { + historyDto.CodeEditorValue.DisplayName = ExternalSecretDisplayName + historyDto.CodeEditorValue.Value = string(externalSecretData) + } + } else if config.IsESOExternalSecretType() { + externalSecretDataBytes, jErr := json.Marshal(config.ESOSecretData) + if jErr != nil { + impl.logger.Errorw("error in marshaling eso secret data", "esoSecretData", config.ESOSecretData, "err", jErr) + return nil, jErr + } + if len(externalSecretDataBytes) > 0 { + historyDto.CodeEditorValue.DisplayName = ESOSecretDataDisplayName + historyDto.CodeEditorValue.Value = string(externalSecretDataBytes) + } } } } @@ -593,7 +607,7 @@ func (impl ConfigMapHistoryServiceImpl) ConvertConfigDataToComponentLevelDto(con SubPath: &config.SubPath, FilePermission: config.FilePermission, CodeEditorValue: &HistoryDetailConfig{ - DisplayName: "Data", + DisplayName: DataDisplayName, Value: string(config.Data), }, } @@ -623,15 +637,19 @@ func (impl ConfigMapHistoryServiceImpl) ConvertConfigDataToComponentLevelDto(con } historyDto.ExternalSecretType = config.ExternalSecretType historyDto.RoleARN = config.RoleARN + historyDto.ESOSubPath = config.ESOSubPath if config.External { var externalSecretData []byte - if strings.HasPrefix(config.ExternalSecretType, "ESO") { + displayName := historyDto.CodeEditorValue.DisplayName + if config.IsESOExternalSecretType() { + displayName = ESOSecretDataDisplayName externalSecretData, err = json.Marshal(config.ESOSecretData) if err != nil { impl.logger.Errorw("error in marshaling external secret data", "err", err) return nil, err } } else { + displayName = ExternalSecretDisplayName externalSecretData, err = json.Marshal(config.ExternalSecret) if err != nil { impl.logger.Errorw("error in marshaling external secret data", "err", err) @@ -639,6 +657,7 @@ func (impl ConfigMapHistoryServiceImpl) ConvertConfigDataToComponentLevelDto(con } } if len(externalSecretData) > 0 { + historyDto.CodeEditorValue.DisplayName = displayName historyDto.CodeEditorValue.Value = string(externalSecretData) } } diff --git a/pkg/pipeline/history/bean.go b/pkg/pipeline/history/bean.go index 1b59ab0f14e..61b6e10a99c 100644 --- a/pkg/pipeline/history/bean.go +++ b/pkg/pipeline/history/bean.go @@ -72,6 +72,7 @@ type HistoryDetailDto struct { ExternalSecretType string `json:"externalType,omitempty"` RoleARN string `json:"roleARN,omitempty"` SubPath *bool `json:"subPath,omitempty"` + ESOSubPath []string `json:"esoSubPath,omitempty"` FilePermission string `json:"filePermission,omitempty"` CodeEditorValue *HistoryDetailConfig `json:"codeEditorValue"` SecretViewAccess bool `json:"secretViewAccess"` // this is being used to check whether a user can see obscured secret values or not. @@ -84,6 +85,12 @@ type HistoryDetailConfig struct { ResolvedValue string `json:"resolvedValue"` } +const ( + DataDisplayName = "Data" + ESOSecretDataDisplayName = "ESO Secret Data" + ExternalSecretDisplayName = "External Secret Data" +) + //history components(deployment template, configMaps, secrets, pipeline strategy) components below type ConfigMapAndSecretHistoryDto struct { diff --git a/pkg/variables/ScopedVariableCMCSManager.go b/pkg/variables/ScopedVariableCMCSManager.go index b7fd8793645..ada82f32453 100644 --- a/pkg/variables/ScopedVariableCMCSManager.go +++ b/pkg/variables/ScopedVariableCMCSManager.go @@ -21,7 +21,7 @@ import ( "encoding/json" "github.com/devtron-labs/devtron/api/bean" "github.com/devtron-labs/devtron/internal/sql/repository/chartConfig" - bean2 "github.com/devtron-labs/devtron/pkg/bean" + serviceBean "github.com/devtron-labs/devtron/pkg/bean" "github.com/devtron-labs/devtron/pkg/pipeline/history/repository" "github.com/devtron-labs/devtron/pkg/resourceQualifiers" models2 "github.com/devtron-labs/devtron/pkg/variables/models" @@ -34,8 +34,8 @@ import ( type ScopedVariableCMCSManager interface { ScopedVariableManager - GetResolvedCMCSHistoryDtos(ctx context.Context, configType repository.ConfigType, configList bean2.ConfigList, history *repository.ConfigmapAndSecretHistory, secretList bean2.SecretList) (map[string]bean2.ConfigData, map[string]map[string]string, error) - ResolveCMCSHistoryDto(ctx context.Context, configType repository.ConfigType, configList bean2.ConfigList, history *repository.ConfigmapAndSecretHistory, componentName string, secretList bean2.SecretList) (map[string]string, string, error) + GetResolvedCMCSHistoryDtos(ctx context.Context, configType repository.ConfigType, configList serviceBean.ConfigList, history *repository.ConfigmapAndSecretHistory, secretList serviceBean.SecretList) (map[string]serviceBean.ConfigData, map[string]map[string]string, error) + ResolveCMCSHistoryDto(ctx context.Context, configType repository.ConfigType, configList serviceBean.ConfigList, history *repository.ConfigmapAndSecretHistory, componentName string, secretList serviceBean.SecretList) (map[string]string, string, error) CreateVariableMappingsForCMApp(model *chartConfig.ConfigMapAppModel) error CreateVariableMappingsForCMEnv(model *chartConfig.ConfigMapEnvModel) error @@ -46,8 +46,8 @@ type ScopedVariableCMCSManager interface { ResolveCMCS(ctx context.Context, scope resourceQualifiers.Scope, configAppLevelId int, configEnvLevelId int, - mergedConfigMap map[string]*bean2.ConfigData, - mergedSecret map[string]*bean2.ConfigData) (map[string]*bean2.ConfigData, map[string]*bean2.ConfigData, map[string]map[string]string, map[string]map[string]string, error) + mergedConfigMap map[string]*serviceBean.ConfigData, + mergedSecret map[string]*serviceBean.ConfigData) (map[string]*serviceBean.ConfigData, map[string]*serviceBean.ConfigData, map[string]map[string]string, map[string]map[string]string, error) ResolveForPrePostStageTrigger(scope resourceQualifiers.Scope, configResponse bean.ConfigMapJson, secretResponse bean.ConfigSecretJson, cmAppId int, cmEnvId int) (*bean.ConfigMapJson, *bean.ConfigSecretJson, error) } @@ -77,9 +77,9 @@ func NewScopedVariableCMCSManagerImpl(logger *zap.SugaredLogger, return scopedVariableCMCSManagerImpl, nil } -func (impl *ScopedVariableCMCSManagerImpl) ResolveCMCSHistoryDto(ctx context.Context, configType repository.ConfigType, configList bean2.ConfigList, history *repository.ConfigmapAndSecretHistory, componentName string, secretList bean2.SecretList) (map[string]string, string, error) { +func (impl *ScopedVariableCMCSManagerImpl) ResolveCMCSHistoryDto(ctx context.Context, configType repository.ConfigType, configList serviceBean.ConfigList, history *repository.ConfigmapAndSecretHistory, componentName string, secretList serviceBean.SecretList) (map[string]string, string, error) { var variableSnapshotMapGranular map[string]map[string]string - var cMCSData map[string]bean2.ConfigData + var cMCSData map[string]serviceBean.ConfigData var err error if configType == repository.CONFIGMAP_TYPE { cMCSData, variableSnapshotMapGranular, err = impl.ResolveCMHistoryDto(ctx, configList, history) @@ -93,7 +93,7 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolveCMCSHistoryDto(ctx context.Con return variableSnapshotMapGranular[componentName], string(cMCSData[componentName].Data), nil } -func (impl *ScopedVariableCMCSManagerImpl) getGranularSnapshotDataForConfigDataList(configList []*bean2.ConfigData, snapshot map[string]string) (map[string]map[string]string, error) { +func (impl *ScopedVariableCMCSManagerImpl) getGranularSnapshotDataForConfigDataList(configList []*serviceBean.ConfigData, snapshot map[string]string) (map[string]map[string]string, error) { expandedVariableSnapshot := make(map[string]map[string]string) for _, config := range configList { @@ -115,14 +115,14 @@ func (impl *ScopedVariableCMCSManagerImpl) getGranularSnapshotDataForConfigDataL return expandedVariableSnapshot, nil } -func (impl *ScopedVariableCMCSManagerImpl) getGranularSnapshotDataForCS(secretList bean2.SecretList, snapshot map[string]string) (map[string]map[string]string, error) { +func (impl *ScopedVariableCMCSManagerImpl) getGranularSnapshotDataForCS(secretList serviceBean.SecretList, snapshot map[string]string) (map[string]map[string]string, error) { expandedVariableSnapshot := make(map[string]map[string]string) secretListJson, err := json.Marshal(secretList) if err != nil { return expandedVariableSnapshot, err } data, err := secretList.GetTransformedDataForSecret(string(secretListJson), util.DecodeSecret) - decodedSecretList := bean2.SecretList{} + decodedSecretList := serviceBean.SecretList{} err = json.Unmarshal([]byte(data), &decodedSecretList) if err != nil { return expandedVariableSnapshot, err @@ -130,8 +130,8 @@ func (impl *ScopedVariableCMCSManagerImpl) getGranularSnapshotDataForCS(secretLi return impl.getGranularSnapshotDataForConfigDataList(decodedSecretList.ConfigData, snapshot) } -func (impl *ScopedVariableCMCSManagerImpl) ResolveSecretHistoryDto(ctx context.Context, secretList bean2.SecretList, history *repository.ConfigmapAndSecretHistory) (map[string]bean2.ConfigData, map[string]map[string]string, error) { - cMCSData := make(map[string]bean2.ConfigData, 0) +func (impl *ScopedVariableCMCSManagerImpl) ResolveSecretHistoryDto(ctx context.Context, secretList serviceBean.SecretList, history *repository.ConfigmapAndSecretHistory) (map[string]serviceBean.ConfigData, map[string]map[string]string, error) { + cMCSData := make(map[string]serviceBean.ConfigData, 0) secretListJson, err := json.Marshal(secretList) reference := repository1.HistoryReference{ HistoryReferenceId: history.Id, @@ -152,7 +152,7 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolveSecretHistoryDto(ctx context.C return cMCSData, nil, err } - resolvedSecretList := bean2.SecretList{} + resolvedSecretList := serviceBean.SecretList{} err = json.Unmarshal([]byte(resolvedTemplate), &resolvedSecretList) if err != nil { return cMCSData, nil, err @@ -167,8 +167,8 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolveSecretHistoryDto(ctx context.C return cMCSData, variableSnapshotMapGranular, nil } -func (impl *ScopedVariableCMCSManagerImpl) ResolveCMHistoryDto(ctx context.Context, configList bean2.ConfigList, history *repository.ConfigmapAndSecretHistory) (map[string]bean2.ConfigData, map[string]map[string]string, error) { - cMCSData := make(map[string]bean2.ConfigData, 0) +func (impl *ScopedVariableCMCSManagerImpl) ResolveCMHistoryDto(ctx context.Context, configList serviceBean.ConfigList, history *repository.ConfigmapAndSecretHistory) (map[string]serviceBean.ConfigData, map[string]map[string]string, error) { + cMCSData := make(map[string]serviceBean.ConfigData, 0) configListJson, err := json.Marshal(configList) reference := repository1.HistoryReference{ HistoryReferenceId: history.Id, @@ -183,7 +183,7 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolveCMHistoryDto(ctx context.Conte return cMCSData, nil, err } - resolvedConfigList := bean2.ConfigList{} + resolvedConfigList := serviceBean.ConfigList{} err = json.Unmarshal([]byte(resolvedTemplate), &resolvedConfigList) if err != nil { return cMCSData, nil, err @@ -200,8 +200,8 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolveCMHistoryDto(ctx context.Conte return cMCSData, variableSnapshotMapGranular, nil } -func (impl *ScopedVariableCMCSManagerImpl) GetResolvedCMCSHistoryDtos(ctx context.Context, configType repository.ConfigType, configList bean2.ConfigList, history *repository.ConfigmapAndSecretHistory, secretList bean2.SecretList) (map[string]bean2.ConfigData, map[string]map[string]string, error) { - resolvedData := make(map[string]bean2.ConfigData, 0) +func (impl *ScopedVariableCMCSManagerImpl) GetResolvedCMCSHistoryDtos(ctx context.Context, configType repository.ConfigType, configList serviceBean.ConfigList, history *repository.ConfigmapAndSecretHistory, secretList serviceBean.SecretList) (map[string]serviceBean.ConfigData, map[string]map[string]string, error) { + resolvedData := make(map[string]serviceBean.ConfigData, 0) var variableSnapshotMapGranular map[string]map[string]string var err error if configType == repository.CONFIGMAP_TYPE { @@ -226,7 +226,7 @@ func (impl *ScopedVariableCMCSManagerImpl) CreateVariableMappingsForCMApp(model } func (impl *ScopedVariableCMCSManagerImpl) CreateVariableMappingsForSecretEnv(model *chartConfig.ConfigMapEnvModel) error { //VARIABLE_MAPPING_UPDATE - sl := bean2.SecretList{} + sl := serviceBean.SecretList{} data, err := sl.GetTransformedDataForSecret(model.SecretData, util.DecodeSecret) if err != nil { return err @@ -235,7 +235,7 @@ func (impl *ScopedVariableCMCSManagerImpl) CreateVariableMappingsForSecretEnv(mo } func (impl *ScopedVariableCMCSManagerImpl) CreateVariableMappingsForSecretApp(model *chartConfig.ConfigMapAppModel) error { //VARIABLE_MAPPING_UPDATE - sl := bean2.SecretList{} + sl := serviceBean.SecretList{} data, err := sl.GetTransformedDataForSecret(model.SecretData, util.DecodeSecret) if err != nil { return err @@ -247,13 +247,13 @@ func (impl *ScopedVariableCMCSManagerImpl) extractAndMapVariables(template strin return impl.ExtractAndMapVariables(template, entityId, entityType, userId, nil) } -func GetResolvedCMCSList(resolvedCS string, resolvedCM string) (map[string]*bean2.ConfigData, map[string]*bean2.ConfigData, error) { - resolvedSecretList := map[string]*bean2.ConfigData{} +func GetResolvedCMCSList(resolvedCS string, resolvedCM string) (map[string]*serviceBean.ConfigData, map[string]*serviceBean.ConfigData, error) { + resolvedSecretList := map[string]*serviceBean.ConfigData{} err := json.Unmarshal([]byte(resolvedCS), &resolvedSecretList) if err != nil { return nil, nil, err } - resolvedConfigList := map[string]*bean2.ConfigData{} + resolvedConfigList := map[string]*serviceBean.ConfigData{} err = json.Unmarshal([]byte(resolvedCM), &resolvedConfigList) if err != nil { return nil, nil, err @@ -264,8 +264,8 @@ func GetResolvedCMCSList(resolvedCS string, resolvedCM string) (map[string]*bean func (impl *ScopedVariableCMCSManagerImpl) ResolveCMCS(ctx context.Context, scope resourceQualifiers.Scope, configAppLevelId int, configEnvLevelId int, - mergedConfigMap map[string]*bean2.ConfigData, - mergedSecret map[string]*bean2.ConfigData) (map[string]*bean2.ConfigData, map[string]*bean2.ConfigData, map[string]map[string]string, map[string]map[string]string, error) { + mergedConfigMap map[string]*serviceBean.ConfigData, + mergedSecret map[string]*serviceBean.ConfigData) (map[string]*serviceBean.ConfigData, map[string]*serviceBean.ConfigData, map[string]map[string]string, map[string]map[string]string, error) { isSuperAdmin, err := util.GetIsSuperAdminFromContext(ctx) @@ -288,13 +288,12 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolveCMCS(ctx context.Context, } variableMapCM = parsers.GetVariableMapForUsedVariables(scopedVariables, varNamesCM) - configData := bean2.ConfigData{} mergedSecretJson, err := json.Marshal(mergedSecret) if err != nil { return nil, nil, nil, nil, err } - decodedSecrets, err := configData.GetTransformedDataForSecretData(string(mergedSecretJson), util.DecodeSecret) + decodedSecrets, err := serviceBean.GetTransformedDataForSecretData(string(mergedSecretJson), util.DecodeSecret) if err != nil { return nil, nil, nil, nil, err } @@ -305,7 +304,7 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolveCMCS(ctx context.Context, return nil, nil, nil, nil, err } variableMapCS = parsers.GetVariableMapForUsedVariables(scopedVariables, varNamesCS) - encodedSecretData, err = configData.GetTransformedDataForSecretData(resolvedTemplateCS, util.EncodeSecret) + encodedSecretData, err = serviceBean.GetTransformedDataForSecretData(resolvedTemplateCS, util.EncodeSecret) if err != nil { return nil, nil, nil, nil, err } @@ -316,7 +315,7 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolveCMCS(ctx context.Context, if err != nil { return nil, nil, nil, nil, err } - secretList := bean2.SecretList{ConfigData: util.GetMapValuesPtr(mergedSecret)} + secretList := serviceBean.SecretList{ConfigData: util.GetMapValuesPtr(mergedSecret)} granularSnapshotCS, err := impl.getGranularSnapshotDataForCS(secretList, variableMapCS) if err != nil { return nil, nil, nil, nil, err @@ -363,15 +362,14 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolvedVariableForLastSaved(scope re } if secretDataByte != nil && len(varNamesCS) > 0 { - ab := bean.ConfigSecretRootJson{} - data, err := ab.GetTransformedDataForSecretData(string(secretDataByte), util.DecodeSecret) + data, err := bean.GetTransformedDataForSecretData(string(secretDataByte), util.DecodeSecret) if err != nil { return resolvedCM, string(secretDataByte), variableSnapshotForCM, variableSnapshotForCS, err } parserRequest := parsers.CreateParserRequest(data, parsers.StringVariableTemplate, scopedVariables, true) resolvedCSDecoded, err := impl.ParseTemplateWithScopedVariables(parserRequest) variableSnapshotForCS = parsers.GetVariableMapForUsedVariables(scopedVariables, varNamesCS) - resolvedCS, err = ab.GetTransformedDataForSecretData(resolvedCSDecoded, util.EncodeSecret) + resolvedCS, err = bean.GetTransformedDataForSecretData(resolvedCSDecoded, util.EncodeSecret) if err != nil { return resolvedCM, resolvedCM, variableSnapshotForCM, variableSnapshotForCS, err } @@ -410,13 +408,12 @@ func (impl *ScopedVariableCMCSManagerImpl) ResolvedVariableForSpecificType(confi HistoryReferenceId: secretHistoryId, HistoryReferenceType: repository1.HistoryReferenceTypeSecret, } - ab := bean.ConfigSecretRootJson{} - data, err := ab.GetTransformedDataForSecretData(string(secretDataByte), util.DecodeSecret) + data, err := bean.GetTransformedDataForSecretData(string(secretDataByte), util.DecodeSecret) if err != nil { return "", "", nil, nil, err } variableMapCS, resolvedTemplateCS, err := impl.GetVariableSnapshotAndResolveTemplate(data, parsers.StringVariableTemplate, reference, true, true) - encodedSecretData, err := ab.GetTransformedDataForSecretData(resolvedTemplateCS, util.EncodeSecret) + encodedSecretData, err := bean.GetTransformedDataForSecretData(resolvedTemplateCS, util.EncodeSecret) if err != nil { return "", "", nil, nil, err }