Skip to content

Commit

Permalink
Per the fashion police
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannDickson authored and ekini committed Sep 12, 2022
1 parent ae76fa0 commit 8029a11
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -102,7 +102,7 @@ Template transformation uses [Go templates](https://golang.org/pkg/text/template

There are the following extra functions available in templates: url_host, url_user, url_password, url_path, url_scheme and trim_prefix. The current list of the custom functions can be found here https://github.com/springload/ssm-parent/blob/master/ssm/transformations/template_funcs.go#L9

trim_name_prefix will match any variables starting with `startswith` and will remove the `trim` string from the start of the corresponding variable names.
trim_name_prefix will match any variables starting with `starts_with` and will remove the `trim` string from the start of the corresponding variable names.

There is practically no limit on the number of transformations and they are applied in order from top to the bottom.

Expand Down Expand Up @@ -131,7 +131,7 @@ transformations:
- action: trim_name_prefix
rule:
trim: "_"
startswith: "_PHP"
starts_with: "_PHP"
```

### Example Dockerfile part
Expand Down
6 changes: 3 additions & 3 deletions ssm/transformations/actions.go
Expand Up @@ -80,10 +80,10 @@ func (t *TrimTransformation) Transform(source map[string]string) (map[string]str
if _, found := t.Rule["trim"]; !found {
return source, fmt.Errorf("\"trim\" rule not set")
}
if _, found := t.Rule["startswith"]; !found {
return source, fmt.Errorf("\"startswith\" rule not set")
if _, found := t.Rule["starts_with"]; !found {
return source, fmt.Errorf("\"starts_with\" rule not set")
}
TrimKeys(source, t.Rule["trim"], t.Rule["startswith"])
TrimKeys(source, t.Rule["trim"], t.Rule["starts_with"])

return source, nil
}
4 changes: 2 additions & 2 deletions ssm/transformations/trim.go
Expand Up @@ -4,10 +4,10 @@ import (
"strings"
)

func TrimKeys(parameters map[string]string, trim string, startswith string) error {
func TrimKeys(parameters map[string]string, trim string, startsWith string) error {

for key, value := range parameters {
if strings.HasPrefix(key, startswith) {
if strings.HasPrefix(key, startsWith) {
parameters[strings.TrimPrefix(key, trim)] = value
delete(parameters, key)
}
Expand Down
6 changes: 3 additions & 3 deletions ssm/transformations/trim_test.go
Expand Up @@ -27,9 +27,9 @@ func TestTrimKeys(t *testing.T) {
result[value] = key
}

for val, expected_param := range expecting {
if result[val] != expected_param {
t.Errorf("'%s's key should be '%s', but got '%s'", val, expected_param, result[val])
for val, expectedParam := range expecting {
if result[val] != expectedParam {
t.Errorf("'%s's key should be '%s', but got '%s'", val, expectedParam, result[val])
}
}
}

0 comments on commit 8029a11

Please sign in to comment.