Skip to content

Commit

Permalink
Merge pull request #3 from mashiike/feature/fix-env-overwrite
Browse files Browse the repository at this point in the history
fix env overwrite
  • Loading branch information
mashiike authored Feb 7, 2022
2 parents 9cde17a + dc7ba1e commit d13af08
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions flexentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,30 @@ func (e *Entrypoint) DetectEnviron(ctx context.Context, event Event) ([]string,
environ = MergeEnv(environ, es)
continue
}
if is, ok := v.([]interface{}); ok {
es := make([]string, 0, len(is))
for _, i := range is {
if s, ok := i.(string); ok {
es = append(es, s)
}
}
environ = MergeEnv(environ, es)
continue
}
if es, ok := v.(map[string]string); ok {
environ = MergeEnvWithMap(environ, es)
continue
}
if is, ok := v.(map[string]interface{}); ok {
es := make(map[string]string, len(is))
for key, value := range is {
if s, ok := value.(string); ok {
es[key] = s
}
}
environ = MergeEnvWithMap(environ, es)
continue
}
}
return environ, nil
}
Expand Down
22 changes: 22 additions & 0 deletions flexentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ func TestEntrypointDetectEnviron(t *testing.T) {
"FUGA=hoge",
},
},
{
event: map[string]interface{}{
"cmd": "echo hoge",
"env": []interface{}{
"HOGE=fuga",
"FUGA=hoge",
},
},
expected: []string{
"HOGE=fuga",
"FUGA=hoge",
},
},
{
event: map[string]interface{}{
"cmd": "echo hoge",
"env": map[string]interface{}{
"HOGE": "fuga",
},
},
expected: []string{"HOGE=fuga"},
},
}

for i, c := range cases {
Expand Down

0 comments on commit d13af08

Please sign in to comment.