Skip to content

fix(credentials): return empty config instead of nil#607

Closed
fabianburth wants to merge 2 commits into
open-component-model:mainfrom
fabianburth:fix/credential-config-merge
Closed

fix(credentials): return empty config instead of nil#607
fabianburth wants to merge 2 commits into
open-component-model:mainfrom
fabianburth:fix/credential-config-merge

Conversation

@fabianburth

@fabianburth fabianburth commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

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 --recursive and 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

Signed-off-by: Fabian Burth <fabian.burth@sap.com>
@fabianburth fabianburth requested a review from a team as a code owner August 21, 2025 21:13
@github-actions github-actions Bot added kind/bugfix Bug size/xs Extra small labels Aug 21, 2025
Signed-off-by: Fabian Burth <fabian.burth@sap.com>
Skarlso
Skarlso previously approved these changes Aug 22, 2025
func Merge(configs ...*Config) *Config {
if len(configs) == 0 {
return nil
return &Config{}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saying that this means that we will have to check in a different way that things aren't set.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are you referring to?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not completely satisfied either, I'll go ahead and check again where the nil pointer was.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fabianburth fabianburth dismissed Skarlso’s stale review August 22, 2025 09:10

favoring an alternative suggestion

@jakobmoellerdev

Copy link
Copy Markdown
Member

closing as discussed

jakobmoellerdev added a commit that referenced this pull request Aug 22, 2025
<!-- 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>
jakobmoellerdev pushed a commit that referenced this pull request Aug 27, 2025
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bugfix Bug size/xs Extra small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants