fix(credentials): return empty config instead of nil#607
Conversation
Signed-off-by: Fabian Burth <fabian.burth@sap.com>
Signed-off-by: Fabian Burth <fabian.burth@sap.com>
| func Merge(configs ...*Config) *Config { | ||
| if len(configs) == 0 { | ||
| return nil | ||
| return &Config{} |
There was a problem hiding this comment.
Just saying that this means that we will have to check in a different way that things aren't set.
There was a problem hiding this comment.
what are you referring to?
There was a problem hiding this comment.
Yeah, I'm not completely satisfied either, I'll go ahead and check again where the nil pointer was.
There was a problem hiding this comment.
what are you referring to?
That now you can't do == nil you have to figure out what the zero value is for the struct.
There was a problem hiding this comment.
It's the ToGraph logic in `setupCredentialGraph that is not able to deal with the nil pointer.
var credCfg *credentialsRuntime.Config
var err error
if cfg := ocmctx.FromContext(cmd.Context()).Configuration(); cfg == nil {
slog.WarnContext(cmd.Context(), "could not get configuration to initialize credential graph")
// PR-COMMENT: we could move this to after the if
credCfg = &credentialsRuntime.Config{}
} else if credCfg, err = credentialsConfig.LookupCredentialConfiguration(cfg); err != nil {
return fmt.Errorf("could not get credential configuration: %w", err)
}
// PR-COMMENT: this would fix it
// if credCfg == nil {
// credCfg = &credentialsRuntime.Config{}
// }
graph, err := credentials.ToGraph(cmd.Context(), credCfg, opts)
if err != nil {
return fmt.Errorf("could not create credential graph: %w", err)
}
Included some comments with the prefix PR-COMMENT.
I'd say this is a valid fix too. Since @Skarlso comment is valid, I'd vote for closing this PR using this to fix it.
favoring an alternative suggestion
|
closing as discussed |
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it Align the merge logic with the change proposed in: #607 #### Which issue(s) this PR fixes <!-- Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> Signed-off-by: Fabian Burth <fabian.burth@sap.com> Co-authored-by: Jakob Möller <jakob.moeller@sap.com>
… merge logic (#608)" (#705) This reverts commit eb5a51d. <!-- markdownlint-disable MD041 --> #### What this PR does / why we need it We decided against doing the change in the credential merge logic (#607 (comment)) and only accidentally merged this PR. #### Which issue(s) this PR fixes <!-- Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> Signed-off-by: Fabian Burth <fabian.burth@sap.com>
What this PR does / why we need it
Can't really remember where, but pretty sure we ran into a nil pointer somewhere during implementation efforts of
get cv --recursiveand agreed that this would be the best way to fix it. (:Which issue(s) this PR fixes
Contributes to: open-component-model/ocm-project#563