Skip to content

Commit 31898f0

Browse files
authored
Fix an exception thrown when an SSH mirror has an invalid credential type (#1336)
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.
1 parent 5bc736b commit 31898f0

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/GitMirrorProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@
2525

2626
import java.net.URI;
2727

28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
31+
import com.linecorp.centraldogma.server.internal.credential.SshKeyCredential;
2832
import com.linecorp.centraldogma.server.mirror.Mirror;
2933
import com.linecorp.centraldogma.server.mirror.MirrorContext;
3034
import com.linecorp.centraldogma.server.mirror.MirrorProvider;
3135
import com.linecorp.centraldogma.server.mirror.RepositoryUri;
3236

3337
public final class GitMirrorProvider implements MirrorProvider {
3438

39+
private static final Logger logger = LoggerFactory.getLogger(GitMirrorProvider.class);
40+
3541
@Override
3642
public Mirror newMirror(MirrorContext context) {
3743
requireNonNull(context, "context");
@@ -44,6 +50,10 @@ public Mirror newMirror(MirrorContext context) {
4450

4551
switch (scheme) {
4652
case SCHEME_GIT_SSH: {
53+
if (!(context.credential() instanceof SshKeyCredential)) {
54+
logger.debug("'{}': SSH mirror requires an SSH_KEY credential, " +
55+
"but got: {}", context.id(), context.credential().type());
56+
}
4757
final RepositoryUri repositoryUri = RepositoryUri.parse(remoteUri, "git");
4858
return new SshGitMirror(context.id(), context.enabled(), context.schedule(),
4959
context.direction(), context.credential(),

server-mirror-git/src/main/java/com/linecorp/centraldogma/server/internal/mirror/SshGitMirror.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ final class SshGitMirror extends AbstractGitMirror {
101101
super(id, enabled, schedule, direction, credential, localRepo, localPath,
102102
remoteUri, gitignore, zone);
103103
this.trustedHostKeys = requireNonNull(trustedHostKeys, "trustedHostKeys");
104-
if (!(credential instanceof SshKeyCredential)) {
105-
throw new MirrorException(
106-
"SSH mirror requires an SSH_KEY credential, but got: " + credential.type());
107-
}
108104
}
109105

110106
@Override

server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/DefaultMetaRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ private CompletableFuture<List<Mirror>> handleAllMirrors(Map<String, Entry<?>> e
189189
} catch (Exception e) {
190190
// Skip a malformed mirror so that a single bad mirror does not
191191
// prevent the rest of the mirrors from being loaded.
192-
logger.debug("Failed to convert a mirror configuration to a mirror. " +
193-
"project: {}, mirror: {}", parent().name(), mirrorConfig,
194-
e);
192+
logger.warn("Failed to convert a mirror configuration to a mirror. " +
193+
"project: {}, mirror: {}", parent().name(), mirrorConfig,
194+
e);
195195
return null;
196196
}
197197
})

0 commit comments

Comments
 (0)