feat!: credentials phase 3 - credential bindings#2518
Conversation
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
✅ Deploy Preview for ocm-website ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughThis PR removes map-based Resolve APIs and migrates the credentials stack to runtime.Typed: interfaces (Resolver, RepositoryPlugin, CredentialPlugin), Graph, direct/indirect/static resolvers, merging/caching, tests, and benchmarks now use ResolveTyped end-to-end. ChangesCredential Resolution API Standardization
Sequence Diagram(s)sequenceDiagram
participant Client
participant Graph
participant CredentialPlugin
participant RepositoryPlugin
participant Cache
Client->>Graph: ResolveTyped(ctx, identity)
alt cached
Graph->>Cache: getCredentials(node)
Cache-->>Graph: runtime.Typed
else not cached
Graph->>CredentialPlugin: ResolveTyped(ctx, identity, nil)
Graph->>RepositoryPlugin: ResolveTyped(ctx, cfg, identity, nil)
CredentialPlugin-->>Graph: runtime.Typed
RepositoryPlugin-->>Graph: runtime.Typed
Graph->>Graph: mergeTyped(runtime.Typed...)
Graph->>Cache: setCredentials(node, merged)
end
Graph-->>Client: runtime.Typed (often *v1.DirectCredentials)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
bindings/go/credentials/graph_test.go (1)
612-642: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick winTest case does not validate credential resolution result.
The test case "recursive resolution through multiple edges leads to successful merged resolution" (lines 612-642) validates that the graph can be constructed without errors, but it does not actually call
ResolveTypedto verify the resolved credentials. Given the new "last writer wins" behavior inresolve_direct.go, this test should validate the actual resolution result.🧪 Add resolution validation to the test
After line 651, add resolution and validation:
} else { r.NoError(err, "Failed to get graph") + // Validate resolution behavior with multiple edges + typed, err := graph.ResolveTyped(t.Context(), runtime.Identity{ + "type": "RecursionTest", + "path": "recursive/path/abc", + }) + r.NoError(err) + dc, ok := typed.(*v1.DirectCredentials) + r.True(ok, "expected *v1.DirectCredentials") + // Verify last-writer-wins: only credentials from path/b edge should be present + r.Equal("def", dc.Properties["password"]) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bindings/go/credentials/graph_test.go` around lines 612 - 642, The test "recursive resolution through multiple edges leads to successful merged resolution" currently only builds the graph; update it to actually call ResolveTyped (the resolver used in resolve_direct.go) for the consumer with identity type RecursionTest/path "recursive/path/abc" and assert the merged credential fields match the new "last writer wins" semantics (expect username "abc" and password "def"). Locate the test case in graph_test.go, invoke ResolveTyped or the package's ResolveTyped helper for that identity, and add assertions that the resolved credential map or struct contains username == "abc" and password == "def" (or equivalent keys/types used by ResolveTyped) to validate the resolution result.
🧹 Nitpick comments (1)
bindings/go/credentials/resolve_direct.go (1)
51-53: 🏗️ Heavy liftAdd test coverage validating "last writer wins" behavior with multiple credential edges.
The comment correctly identifies that typed credentials cannot be merged generically—only the last resolved credential is retained, unlike the previous map-based implementation. However, the existing test "recursive resolution through multiple edges leads to successful merged resolution" (graph_test.go) only validates that the graph construction succeeds; it does not assert what credentials are actually returned when a consumer has multiple edges. This test should be expanded or a new test added to explicitly verify that only the last edge's credentials are present in the final resolution result, not a merge of all edges.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bindings/go/credentials/resolve_direct.go` around lines 51 - 53, Expand or add a unit test in graph_test.go to assert "last writer wins" when resolving typed credentials: create a consumer node with multiple incoming credential edges each supplying distinct credential values, invoke the same resolution path used in the existing test (the code path that sets resolved = credentials in resolve_direct.go), and assert that the returned resolved value equals the credential from the last edge only (not a merge). Reference the resolution code by the resolved variable assignment in resolve_direct.go and the existing test "recursive resolution through multiple edges leads to successful merged resolution" to locate where to augment or add the new assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@bindings/go/credentials/graph_test.go`:
- Around line 612-642: The test "recursive resolution through multiple edges
leads to successful merged resolution" currently only builds the graph; update
it to actually call ResolveTyped (the resolver used in resolve_direct.go) for
the consumer with identity type RecursionTest/path "recursive/path/abc" and
assert the merged credential fields match the new "last writer wins" semantics
(expect username "abc" and password "def"). Locate the test case in
graph_test.go, invoke ResolveTyped or the package's ResolveTyped helper for that
identity, and add assertions that the resolved credential map or struct contains
username == "abc" and password == "def" (or equivalent keys/types used by
ResolveTyped) to validate the resolution result.
---
Nitpick comments:
In `@bindings/go/credentials/resolve_direct.go`:
- Around line 51-53: Expand or add a unit test in graph_test.go to assert "last
writer wins" when resolving typed credentials: create a consumer node with
multiple incoming credential edges each supplying distinct credential values,
invoke the same resolution path used in the existing test (the code path that
sets resolved = credentials in resolve_direct.go), and assert that the returned
resolved value equals the credential from the last edge only (not a merge).
Reference the resolution code by the resolved variable assignment in
resolve_direct.go and the existing test "recursive resolution through multiple
edges leads to successful merged resolution" to locate where to augment or add
the new assertion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3659d237-1a0b-4b50-8f77-a1df4ed728ff
📒 Files selected for processing (11)
bindings/go/credentials/doc.gobindings/go/credentials/graph.gobindings/go/credentials/graph_bench_test.gobindings/go/credentials/graph_test.gobindings/go/credentials/interface.gobindings/go/credentials/plugins.gobindings/go/credentials/resolve_direct.gobindings/go/credentials/resolve_direct_test.gobindings/go/credentials/resolve_indirect.gobindings/go/credentials/resolve_static.gobindings/go/credentials/resolve_static_test.go
💤 Files with no reviewable changes (4)
- bindings/go/credentials/graph.go
- bindings/go/credentials/resolve_direct_test.go
- bindings/go/credentials/interface.go
- bindings/go/credentials/resolve_static.go
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
7ea6255 to
9837f0e
Compare
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
2e651f3 to
4e10530
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bindings/go/credentials/resolve_direct.go`:
- Around line 86-110: mergeTyped treats DirectCredentials and other typed
credentials differently: DirectCredentials copies dc.Properties verbatim (so
empty strings override), while the non-DC branch only copies non-empty strings
and drops non-string fields. In mergeTyped, change the non-DC branch (the block
that converts to runtime.Raw, unmarshals into fields, and iterates for k,v) to
stop requiring v be a non-empty string; instead convert any non-nil v to a
string (e.g. via fmt.Sprint or equivalent) and assign merged[k] = that string
(skip the "type" key as before), allowing empty strings to override earlier
values and preserving override semantics consistent with DirectCredentials; keep
scheme.Convert, json.Unmarshal, raw, and fields logic intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5725313f-b47c-45d4-8601-e5b8e47f2eaf
📒 Files selected for processing (2)
bindings/go/credentials/resolve_direct.gobindings/go/credentials/resolve_direct_test.go
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
…hub.com:matthiasbruns/open-component-model into feat/1047_typed_credentials_phase_3_credentials
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bindings/go/credentials/resolve_direct.go`:
- Around line 27-32: The cache key is inconsistent: g.getCredentials(vertex.ID)
is used for lookup but the result is stored under node := identity.String(); fix
by using the same key for both operations—either change the lookup to
g.getCredentials(identity.String()) or change the stored key to vertex.ID—so
that the cache reads and writes use the identical key (update the code paths
around g.getCredentials, vertex.ID, identity.String(), and the assignment to
node in resolve_direct.go to match resolve_indirect.go's approach).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 60c1caf9-0854-48b5-b787-f9e689164e4f
📒 Files selected for processing (1)
bindings/go/credentials/resolve_direct.go
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
2b2c0c9 to
6c87f61
Compare
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
What this PR does / why we need it
Phase 3 of the credential migration
This PR updated the
credentialbindings.This PR adds typed support to both CredentialPlugin and RepositoryPlugin as defined in the ADR
Additionally, we also replace the deprecated
Resolvemethods from the interfaces, as well as from the credentials.You can see the full impact in #2517
Which issue(s) this PR fixes
Contributes: open-component-model/ocm-project#1047