Skip to content

Commit

Permalink
address comments and fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
amandavialva01 committed Oct 21, 2024
1 parent 84f1366 commit b82cf31
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions master/internal/configpolicy/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,39 @@ func ValidWorkloadType(val string) bool {
}
}

func UnmarshalConfigPolicies[T any](errMsg string, constraints,
invariantConfig *string) (*model.Constraints, *T,
// UnmarshalConfigPolicies unmarshals optionally specified invariant config and constraint
// configurations presented as YAML or JSON strings.
func UnmarshalConfigPolicies[T any](errMsg string, constraintsStr,
configStr *string) (*model.Constraints, *T,
error,
) {
var globalConstraints *model.Constraints
var globalConfig *T
var constraints *model.Constraints
var config *T

if constraints != nil {
if constraintsStr != nil {
unmarshaledConstraints, err := UnmarshalConfigPolicy[model.Constraints](
*constraints,
*constraintsStr,
errMsg,
)
if err != nil {
ConfigPolicyWarning(err.Error())
return nil, nil, err
}
globalConstraints = unmarshaledConstraints
constraints = unmarshaledConstraints
}

if invariantConfig != nil {
if configStr != nil {
unmarshaledConfig, err := UnmarshalConfigPolicy[T](
*invariantConfig,
*configStr,
errMsg,
)
if err != nil {
ConfigPolicyWarning(err.Error())
return nil, nil, err
}
globalConfig = unmarshaledConfig
config = unmarshaledConfig
}
return globalConstraints, globalConfig, nil
return constraints, config, nil
}

// UnmarshalConfigPolicy is a generic helper function to unmarshal both JSON and YAML strings.
Expand Down

0 comments on commit b82cf31

Please sign in to comment.