Skip to content

Commit

Permalink
fix: remove deprecated 0-keys placeholder behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Meier <ben.meier@humanitec.com>
  • Loading branch information
astromechza committed Apr 5, 2024
1 parent 5022dc8 commit df173b3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions framework/resource_uid.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ func NewResourceUid(workloadName string, resName string, resType string, resClas
return ResourceUid(fmt.Sprintf("%s.%s#%s.%s", resType, *resClass, workloadName, resName))
}

// Type returns the type of the resource
func (r ResourceUid) Type() string {
return string(r)[0:strings.Index(string(r), ".")]
}

// Class returns the class of the resource, defaulted to "default"
func (r ResourceUid) Class() string {
return string(r)[strings.Index(string(r), ".")+1 : strings.Index(string(r), "#")]
}

// Id returns the id of the resource, either <workload>.<name> or <id> if id is specified
func (r ResourceUid) Id() string {
return string(r)[strings.Index(string(r), "#")+1:]
}
2 changes: 1 addition & 1 deletion framework/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type ScoreResourceState struct {
Type string `yaml:"type"`
// Class is the resource class or 'default' if not provided.
Class string `yaml:"class"`
// Id is the generated id for the resource, either <workload>.<resName> or <shared>.<id>. This is tracked so that
// Id is the generated id for the resource, either <workload>.<resName> or <id>. This is tracked so that
// we can deduplicate and work out where a resource came from.
Id string `yaml:"id"`

Expand Down
3 changes: 0 additions & 3 deletions framework/substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ func BuildSubstitutionFunction(metadata map[string]interface{}, resources map[st
rv, ok := resources[parts[1]]
if !ok {
return "", fmt.Errorf("invalid ref '%s': no known resource '%s'", ref, parts[1])
} else if len(parts) == 2 {
// TODO: deprecate this - this is an annoying and nonsensical legacy thing
return parts[1], nil
} else if rv2, err := rv(parts[2:]...); err != nil {
return "", fmt.Errorf("invalid ref '%s': %w", ref, err)
} else {
Expand Down
15 changes: 12 additions & 3 deletions framework/substitution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,27 @@ func init() {
},
}, map[string]OutputLookupFunc{
"env": func(keys ...string) (interface{}, error) {
if len(keys) != 1 {
if len(keys) == 0 {
return "env", nil
} else if len(keys) != 1 {
return nil, fmt.Errorf("fail")
}
return "${" + keys[0] + "}", nil
},
"db": func(keys ...string) (interface{}, error) {
if len(keys) < 1 {
if len(keys) == 0 {
return "db", nil
} else if len(keys) < 1 {
return nil, fmt.Errorf("fail")
}
return "${DB_" + strings.ToUpper(strings.Join(keys, "_")) + "?required}", nil
},
"static": mapLookupOutput(map[string]interface{}{"x": "a"}),
"static": func(keys ...string) (interface{}, error) {
if len(keys) == 0 {
return "static", nil
}
return mapLookupOutput(map[string]interface{}{"x": "a"})(keys...)
},
})
}

Expand Down

0 comments on commit df173b3

Please sign in to comment.