Fix an exception thrown when an SSH mirror has an invalid credential type - #1336
Conversation
…type Motivation: When an SSH mirror was configured with a non-SSH_KEY credential (e.g. ACCESS_TOKEN), `SshGitMirror` threw a `MirrorException` during mirror conversion. Although the exception was caught by `handleAllMirrors()` and the bad mirror was skipped, the mirror was invisible in the UI as a result, making it impossible to update or delete the mirror. Modifications: - Move the credential type validation from `SshGitMirror` constructor to `GitMirrorProvider.newMirror()`. When the credential type is wrong, log a warning and return `null` instead of throwing `MirrorException`. Result: - A mirror with an invalid credential type is loaded correctly and shown in the UI, allowing users to update or delete it.
📝 WalkthroughWalkthroughSSH mirror creation now logs unexpected credential types and removes duplicate constructor validation. Mirror conversion failures in ChangesMirror validation and observability
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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
🤖 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
`@server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitMirrorProvider.java`:
- Around line 53-57: Update GitMirrorProvider.newMirror() so an SSH mirror with
a missing credential, represented by Credential.NONE, remains loadable instead
of being rejected and dropped by handleAllMirrors(). Preserve the existing
validation for non-SSH credential types, or alternatively enforce rejection when
the mirror is written through the relevant write path rather than during
loading.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 53bc289c-1703-47f9-a287-072c7c0db335
📒 Files selected for processing (3)
server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitMirrorProvider.javaserver-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/SshGitMirror.javaserver/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/DefaultMetaRepository.java
💤 Files with no reviewable changes (1)
- server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/SshGitMirror.java
There was a problem hiding this comment.
♻️ Duplicate comments (1)
server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitMirrorProvider.java (1)
53-56: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winReturn
nulland log at WARN for invalid SSH credentials.This branch currently logs at DEBUG and continues creating
SshGitMirror. Since constructor validation was removed, credentials such asACCESS_TOKENare now accepted instead of being rejected as required by this PR.🐛 Proposed fix
if (!(context.credential() instanceof SshKeyCredential)) { - logger.debug("'{}': SSH mirror requires an SSH_KEY credential, " + - "but got: {}", context.id(), context.credential().type()); + logger.warn("'{}': SSH mirror requires an SSH_KEY credential, " + + "but got: {}", context.id(), context.credential().type()); + return null; }🤖 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 `@server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitMirrorProvider.java` around lines 53 - 56, Update the invalid-credential branch in the mirror creation flow to log the SSH credential mismatch at WARN level and return null immediately, preventing SshGitMirror creation when context.credential() is not an SshKeyCredential.
🤖 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.
Duplicate comments:
In
`@server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitMirrorProvider.java`:
- Around line 53-56: Update the invalid-credential branch in the mirror creation
flow to log the SSH credential mismatch at WARN level and return null
immediately, preventing SshGitMirror creation when context.credential() is not
an SshKeyCredential.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4cbca470-b269-45f0-ae56-cf91b856778c
📒 Files selected for processing (1)
server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitMirrorProvider.java
|
|
||
| switch (scheme) { | ||
| case SCHEME_GIT_SSH: { | ||
| if (!(context.credential() instanceof SshKeyCredential)) { |
There was a problem hiding this comment.
Question) Could we validate the configuration correctness also when a mirror is created.?
There was a problem hiding this comment.
…type
Motivation:
When an SSH mirror was configured with a non-SSH_KEY credential (e.g. ACCESS_TOKEN),
SshGitMirrorthrew aMirrorExceptionduring mirror conversion. Although the exception was caught byhandleAllMirrors()and the bad mirror was skipped, the mirror was invisible in the UI as a result, making it impossible to update or delete the mirror.Modifications:
SshGitMirrorconstructor toGitMirrorProvider.newMirror(). When the credential type is wrong, log a warning and returnnullinstead of throwingMirrorException.Result: