fix: unify access_token/accessToken and refresh_token/refreshToken credential keys#2383
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. |
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR unifies credential key handling across OCI credential consumers by introducing legacy snake_case token key support with camelCase precedence. Changes standardize token access in the resource repository to match docker config behavior while maintaining backward compatibility through fallback mechanisms. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
bindings/go/oci/repository/resource/resource_repository_test.go (1)
84-89: Nit: use credential key constants for consistency.The surrounding test cases reference credential keys via
ocicredentials.CredentialKey*constants, but this case hardcodes"username"and"password"as string literals. Aligning them avoids silent breakage if any constant value ever changes.♻️ Proposed refactor
credentials: map[string]string{ - "username": "user", - "password": "pass", - ocicredentials.LegacyCredentialKeyAccessToken: "atoken", - ocicredentials.LegacyCredentialKeyRefreshToken: "rtoken", + ocicredentials.CredentialKeyUsername: "user", + ocicredentials.CredentialKeyPassword: "pass", + ocicredentials.LegacyCredentialKeyAccessToken: "atoken", + ocicredentials.LegacyCredentialKeyRefreshToken: "rtoken", },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bindings/go/oci/repository/resource/resource_repository_test.go` around lines 84 - 89, Replace the hardcoded "username" and "password" keys in the test credentials map with the corresponding constants from ocicredentials (e.g., ocicredentials.CredentialKeyUsername and ocicredentials.CredentialKeyPassword) so the test uses the same canonical keys as other cases (leave the existing uses of ocicredentials.LegacyCredentialKeyAccessToken and LegacyCredentialKeyRefreshToken unchanged).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@bindings/go/oci/credentials/docker_config.go`:
- Around line 32-37: The deprecated notices for LegacyCredentialKeyAccessToken
and LegacyCredentialKeyRefreshToken must be in their own paragraph for
godoc/gocritic; update the comments above LegacyCredentialKeyAccessToken and
LegacyCredentialKeyRefreshToken by inserting a blank comment line before each
"Deprecated:" line so the "Deprecated:" sentence is separated into its own
paragraph (leave the existing explanatory sentence above intact and only add the
blank comment line immediately before the Deprecated: clause).
---
Nitpick comments:
In `@bindings/go/oci/repository/resource/resource_repository_test.go`:
- Around line 84-89: Replace the hardcoded "username" and "password" keys in the
test credentials map with the corresponding constants from ocicredentials (e.g.,
ocicredentials.CredentialKeyUsername and ocicredentials.CredentialKeyPassword)
so the test uses the same canonical keys as other cases (leave the existing uses
of ocicredentials.LegacyCredentialKeyAccessToken and
LegacyCredentialKeyRefreshToken unchanged).
🪄 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: 089faf03-3153-4523-9da2-c518323210a8
📒 Files selected for processing (4)
bindings/go/oci/credentials/docker_config.gobindings/go/oci/credentials/docker_config_test.gobindings/go/oci/repository/resource/resource_repository.gobindings/go/oci/repository/resource/resource_repository_test.go
On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
2c1e628 to
ebeb965
Compare
…n the tests On-behalf-of: SAP <matthias.bruns@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
ebeb965 to
22173a0
Compare
Co-authored-by: Matthias Bruns <github@matthiasbruns.com> Signed-off-by: Matthias Bruns <github@matthiasbruns.com>
…edential keys (open-component-model#2383) #### What this PR does / why we need it The OCI resource repository (`resource_repository.go`) used snake_case credential keys (`access_token`, `refresh_token`) while the rest of the codebase—including `docker_config.go` and the component version repository path—uses camelCase (`accessToken`, `refreshToken`). This mismatch caused silent authentication failures when tokens from Docker config (which produces camelCase keys) were used for OCI resource downloads. This PR: - Updates `clientCredentials()` in `resource_repository.go` to use the canonical `CredentialKey*` constants (camelCase) as the primary keys - Updates `CredentialFunc()` in `docker_config.go` to also accept legacy snake_case keys - Adds `LegacyCredentialKeyAccessToken` and `LegacyCredentialKeyRefreshToken` constants (marked deprecated) so legacy keys are not scattered as string literals - Falls back to the legacy snake_case keys for backward compatibility, with camelCase taking precedence when both are present #### Which issue(s) this PR fixes Fixes open-component-model/ocm-project#985 #### Testing ##### How to test the changes 1. Run unit tests: `go test ./bindings/go/oci/credentials/... ./bindings/go/oci/repository/resource/...` 2. Verify that credentials with camelCase keys (`accessToken`, `refreshToken`) are correctly resolved in both the component version and resource repository paths 3. Verify that credentials with legacy snake_case keys (`access_token`, `refresh_token`) still work for backward compatibility ##### Verification - [x] I have added/updated tests for my changes (see [Test Requirements](../CONTRIBUTING.md#test-requirements)) - [x] Tests pass locally (`task test` and `task test/integration` if applicable) - [ ] If touching multiple modules, `go work` is enabled (see `go.work`) - [x] My changes do not decrease test coverage - [ ] I have tested the changes locally by running `ocm` --------- Signed-off-by: Matthias Bruns <git@matthiasbruns.com> Signed-off-by: Matthias Bruns <github@matthiasbruns.com> Signed-off-by: Gerald Morrison (SAP) <gerald.morrison@sap.com>
What this PR does / why we need it
The OCI resource repository (
resource_repository.go) used snake_case credential keys (access_token,refresh_token) while the rest of the codebase—includingdocker_config.goand the component version repository path—uses camelCase (accessToken,refreshToken). This mismatch caused silent authentication failures when tokens from Docker config (which produces camelCase keys) were used for OCI resource downloads.This PR:
clientCredentials()inresource_repository.goto use the canonicalCredentialKey*constants (camelCase) as the primary keysCredentialFunc()indocker_config.goto also accept legacy snake_case keysLegacyCredentialKeyAccessTokenandLegacyCredentialKeyRefreshTokenconstants (marked deprecated) so legacy keys are not scattered as string literalsWhich issue(s) this PR fixes
Fixes open-component-model/ocm-project#985
Testing
How to test the changes
go test ./bindings/go/oci/credentials/... ./bindings/go/oci/repository/resource/...accessToken,refreshToken) are correctly resolved in both the component version and resource repository pathsaccess_token,refresh_token) still work for backward compatibilityVerification
task testandtask test/integrationif applicable)go workis enabled (seego.work)ocm