Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove deprecated 0-keys placeholder behavior #33

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading