Skip to content

Commit 5769840

Browse files
idsulikglours
authored andcommitted
fix(secrets): Fix secrets environment to content mapping
Signed-off-by: Suleiman Dibirov <[email protected]>
1 parent aa1db26 commit 5769840

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

loader/environment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func resolveSecretsEnvironment(dict map[string]any, environment types.Mapping) {
7979
continue
8080
}
8181
if found, ok := environment[env]; ok {
82-
secret["content"] = found
82+
secret[types.SecretConfigXValue] = found
8383
}
8484
secrets[name] = secret
8585
}

loader/loader.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,9 @@ func Transform(source interface{}, target interface{}) error {
738738
DecodeHook: mapstructure.ComposeDecodeHookFunc(
739739
nameServices,
740740
decoderHook,
741-
cast),
741+
cast,
742+
secretConfigDecoderHook,
743+
),
742744
Result: target,
743745
TagName: "yaml",
744746
Metadata: &data,
@@ -764,6 +766,23 @@ func nameServices(from reflect.Value, to reflect.Value) (interface{}, error) {
764766
return from.Interface(), nil
765767
}
766768

769+
func secretConfigDecoderHook(from, to reflect.Type, data interface{}) (interface{}, error) {
770+
// Check if the input is a map and we're decoding into a SecretConfig
771+
if from.Kind() == reflect.Map && to == reflect.TypeOf(types.SecretConfig{}) {
772+
if v, ok := data.(map[string]interface{}); ok {
773+
if ext, ok := v["#extensions"].(map[string]interface{}); ok {
774+
if val, ok := ext[types.SecretConfigXValue].(string); ok {
775+
// Return a map with the Content field populated
776+
v["Content"] = val
777+
}
778+
}
779+
}
780+
}
781+
782+
// Return the original data so the rest is handled by default mapstructure logic
783+
return data, nil
784+
}
785+
767786
// keys need to be converted to strings for jsonschema
768787
func convertToStringKeysRecursive(value interface{}, keyPrefix string) (interface{}, error) {
769788
if mapping, ok := value.(map[string]interface{}); ok {

types/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ const (
239239
NetworkModeContainerPrefix = ContainerPrefix
240240
)
241241

242+
const (
243+
SecretConfigXValue = "x-#value"
244+
)
245+
242246
// GetDependencies retrieves all services this service depends on
243247
func (s ServiceConfig) GetDependencies() []string {
244248
var dependencies []string

0 commit comments

Comments
 (0)