Do not fail because of invalid SSH key
There's no reason to abort the import because of an invalid key.
Especially when a bug (issue 4643) generates invalid keys in 2.13.
Change-Id: Ifaeea7e256c024b6c7ccf9a0c6f305b30ab0973b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/AccountUtil.java b/src/main/java/com/googlesource/gerrit/plugins/importer/AccountUtil.java
index d99f77c..1b91675 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/AccountUtil.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/AccountUtil.java
@@ -77,7 +77,7 @@
Account.Id resolveUser(GerritApi api, AccountInfo acc)
throws NoSuchAccountException, IOException, OrmException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
if (acc.username == null) {
throw new NoSuchAccountException(String.format(
"User %s <%s> (%s) doesn't have a username and cannot be looked up.",
@@ -112,7 +112,7 @@
private Account.Id createAccountByLdapAndAddSshKeys(GerritApi api,
AccountInfo acc) throws NoSuchAccountException, IOException, OrmException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
if (!acc.username.matches(Account.USER_NAME_PATTERN)) {
throw new NoSuchAccountException(String.format("User %s not found",
acc.username));
@@ -131,11 +131,15 @@
private void addSshKeys(GerritApi api, AccountInfo acc)
throws BadRequestException, IOException, OrmException,
- ConfigInvalidException, InvalidSshKeyException {
+ ConfigInvalidException {
List<SshKeyInfo> sshKeys = api.getSshKeys(acc.username);
AccountState a = accountCache.getByUsername(acc.username);
for (SshKeyInfo sshKeyInfo : sshKeys) {
- authorizedKeys.addKey(a.getAccount().getId(), sshKeyInfo.sshPublicKey);
+ try {
+ authorizedKeys.addKey(a.getAccount().getId(), sshKeyInfo.sshPublicKey);
+ } catch (InvalidSshKeyException e) {
+ log.warn(String.format("Invalid SSH key for user %s", acc.username));
+ }
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java
index 05c869b..b541966 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java
@@ -17,7 +17,6 @@
import com.google.common.base.MoreObjects;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.common.data.LabelType;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ApprovalInfo;
@@ -84,7 +83,7 @@
void add(GerritApi api) throws OrmException, NoSuchChangeException,
IOException, NoSuchAccountException, RestApiException,
- ConfigInvalidException, InvalidSshKeyException {
+ ConfigInvalidException {
if (resume) {
db.patchSetApprovals().delete(
db.patchSetApprovals().byChange(change.getId()));
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java
index 87456a2..0992551 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java
@@ -15,7 +15,6 @@
package com.googlesource.gerrit.plugins.importer;
import com.google.common.base.Strings;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.annotations.RequiresCapability;
@@ -73,7 +72,7 @@
public ImportStatistic apply(ProjectResource rsrc, Input input)
throws RestApiException, OrmException, IOException, ValidationException,
GitAPIException, NoSuchChangeException, NoSuchAccountException,
- UpdateException, ConfigInvalidException, InvalidSshKeyException {
+ UpdateException, ConfigInvalidException {
if (Strings.isNullOrEmpty(input.name)) {
throw new BadRequestException("name is required");
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/GroupCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/GroupCommand.java
index ffe1d57..5b4c758 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/GroupCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/GroupCommand.java
@@ -17,7 +17,6 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Strings;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.restapi.RestApiException;
@@ -68,7 +67,7 @@
@Override
protected void run() throws UnloggedFailure, OrmException, IOException,
- NoSuchAccountException, ConfigInvalidException, InvalidSshKeyException {
+ NoSuchAccountException, ConfigInvalidException {
ImportGroup.Input input = new ImportGroup.Input();
input.from = url;
input.user = user;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroup.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroup.java
index 24ee5f9..e2eec41 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroup.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroup.java
@@ -16,7 +16,6 @@
import static com.google.gerrit.reviewdb.client.AccountGroup.isInternalGroup;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.common.AccountInfo;
@@ -117,7 +116,7 @@
@Override
public Response<String> apply(ConfigResource rsrc, Input input)
throws NoSuchAccountException, OrmException, IOException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
GroupInfo groupInfo;
this.api = apiFactory.create(input.from, input.user, input.pass);
groupInfo = api.getGroup(group.get());
@@ -129,7 +128,7 @@
private void validate(Input input, GroupInfo groupInfo)
throws IOException, OrmException, NoSuchAccountException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
if (!isInternalGroup(new AccountGroup.UUID(groupInfo.id))) {
throw new MethodNotAllowedException(String.format(
"Group with name %s is not an internal group and cannot be imported",
@@ -185,7 +184,7 @@
private CreateGroupArgs toCreateGroupArgs(GroupInfo groupInfo)
throws IOException, OrmException, NoSuchAccountException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
CreateGroupArgs args = new CreateGroupArgs();
args.setGroupName(groupInfo.name);
args.groupDescription = groupInfo.description;
@@ -203,7 +202,7 @@
private AccountGroup createGroup(Input input, GroupInfo info)
throws OrmException, NoSuchAccountException, IOException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
String uniqueName = getUniqueGroupName(info.name);
if (!info.name.equals(uniqueName)) {
log.warn(String.format("Group %s with UUID %s is imported with name %s",
@@ -282,7 +281,7 @@
private void addMembers(AccountGroup.Id groupId, List<AccountInfo> members)
throws OrmException, NoSuchAccountException, IOException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
List<AccountGroupMember> memberships = new ArrayList<>();
for (AccountInfo member : members) {
Account.Id userId = accountUtil.resolveUser(api, member);
@@ -300,7 +299,7 @@
private void addGroups(Input input, AccountGroup.Id groupId, String groupName,
List<GroupInfo> includedGroups)
throws NoSuchAccountException, OrmException, IOException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
List<AccountGroupById> includeList = new ArrayList<>();
for (GroupInfo includedGroup : includedGroups) {
if (isInternalGroup(new AccountGroup.UUID(includedGroup.id))) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroupsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroupsStep.java
index 0e9fece..e8b0288 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroupsStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroupsStep.java
@@ -16,7 +16,6 @@
import static com.google.gerrit.reviewdb.client.AccountGroup.isInternalGroup;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
@@ -78,7 +77,7 @@
}
void importGroups() throws NoSuchAccountException, OrmException, IOException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
ProjectConfig projectConfig = projectCache.get(project).getConfig();
Set<AccountGroup.UUID> groupUUIDs = projectConfig.getAllGroupUUIDs();
pm.beginTask("Import Groups", groupUUIDs.size());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java
index 5d8931d..5c946c4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java
@@ -18,7 +18,6 @@
import static java.lang.String.format;
import com.google.common.base.Strings;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.restapi.BadRequestException;
@@ -167,7 +166,7 @@
public ImportStatistic apply(ConfigResource rsrc, Input input)
throws RestApiException, OrmException, IOException, ValidationException,
GitAPIException, NoSuchChangeException, NoSuchAccountException,
- UpdateException, ConfigInvalidException, InvalidSshKeyException {
+ UpdateException, ConfigInvalidException {
if (input == null) {
input = new Input();
}
@@ -183,7 +182,7 @@
public ResumeImportStatistic resume(String user, String pass, boolean force,
File importStatus) throws RestApiException, OrmException, IOException,
GitAPIException, NoSuchChangeException, NoSuchAccountException,
- UpdateException, ConfigInvalidException, InvalidSshKeyException {
+ UpdateException, ConfigInvalidException {
LockFile lockFile = lockForImport();
try {
ImportProjectInfo info = ImportJson.parse(importStatus);
@@ -206,8 +205,7 @@
private ResumeImportStatistic apply(LockFile lockFile, Input input,
ImportProjectInfo info) throws RestApiException, OrmException,
IOException, GitAPIException, NoSuchChangeException,
- NoSuchAccountException, UpdateException, ConfigInvalidException,
- InvalidSshKeyException {
+ NoSuchAccountException, UpdateException, ConfigInvalidException {
boolean resume = info != null;
api = apiFactory.create(input.from, input.user, input.pass);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java
index 48e0212..e449d36 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java
@@ -15,7 +15,6 @@
package com.googlesource.gerrit.plugins.importer;
import com.google.common.base.Strings;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.restapi.RestApiException;
@@ -74,7 +73,7 @@
protected void run()
throws OrmException, IOException, UnloggedFailure, ValidationException,
GitAPIException, NoSuchChangeException, NoSuchAccountException,
- UpdateException, ConfigInvalidException, InvalidSshKeyException {
+ UpdateException, ConfigInvalidException {
ImportProject.Input input = new ImportProject.Input();
input.from = url;
input.name = name;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java
index dcb0a66..1e8daf1 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java
@@ -17,7 +17,6 @@
import com.google.common.collect.Iterators;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.GlobalCapability;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.common.ChangeInfo;
@@ -134,7 +133,7 @@
void replay() throws IOException, OrmException,
NoSuchAccountException, NoSuchChangeException, RestApiException,
- UpdateException, ConfigInvalidException, InvalidSshKeyException {
+ UpdateException, ConfigInvalidException {
int start = 0;
int limit = GlobalCapability.DEFAULT_MAX_QUERY_LIMIT;
pm.beginTask("Replay Changes", ProgressMonitor.UNKNOWN);
@@ -169,7 +168,7 @@
private void replayChange(RevWalk rw, ChangeInfo c)
throws IOException, OrmException, NoSuchAccountException,
NoSuchChangeException, RestApiException, IllegalArgumentException,
- UpdateException, ConfigInvalidException, InvalidSshKeyException {
+ UpdateException, ConfigInvalidException {
if (c.status == ChangeStatus.DRAFT) {
// no import of draft changes
return;
@@ -227,7 +226,7 @@
private Change createChange(ChangeInfo c)
throws OrmException, NoSuchAccountException, IOException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
Change.Id changeId = new Change.Id(sequences.nextChangeId());
Change change =
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
index 2584978..be71dd7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
@@ -21,7 +21,6 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.gerrit.common.TimeUtil;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.extensions.common.ChangeInfo;
@@ -111,7 +110,7 @@
void replay()
throws RestApiException, OrmException, IOException, NoSuchChangeException,
- NoSuchAccountException, ConfigInvalidException, InvalidSshKeyException {
+ NoSuchAccountException, ConfigInvalidException {
ChangeControl ctrl = control(change, change.getOwner());
for (PatchSet ps : ChangeUtil.PS_ID_ORDER
.sortedCopy(psUtil.byChange(db, ctrl.getNotes()))) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayMessagesStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayMessagesStep.java
index dfdf892..3fb9932 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayMessagesStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayMessagesStep.java
@@ -14,7 +14,6 @@
package com.googlesource.gerrit.plugins.importer;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ChangeMessageInfo;
@@ -79,7 +78,7 @@
void replay(GerritApi api) throws NoSuchAccountException,
NoSuchChangeException, OrmException, IOException, RestApiException,
- ConfigInvalidException, InvalidSshKeyException {
+ ConfigInvalidException {
for (ChangeMessageInfo msg : changeInfo.messages) {
ChangeMessage.Key msgKey = new ChangeMessage.Key(change.getId(), msg.id);
if (resume && db.changeMessages().get(msgKey) != null) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java
index e5cd3dc..50efc97 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java
@@ -14,7 +14,6 @@
package com.googlesource.gerrit.plugins.importer;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
@@ -82,7 +81,7 @@
void replay(GerritApi api)
throws IOException, OrmException, NoSuchAccountException,
- RestApiException, ConfigInvalidException, InvalidSshKeyException {
+ RestApiException, ConfigInvalidException {
List<RevisionInfo> revisions = new ArrayList<>(changeInfo.revisions.values());
sortRevisionInfoByNumber(revisions);
List<PatchSet> patchSets = new ArrayList<>();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java
index 748bf4c..731e077 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java
@@ -14,7 +14,6 @@
package com.googlesource.gerrit.plugins.importer;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.annotations.RequiresCapability;
@@ -82,7 +81,7 @@
public ResumeImportStatistic apply(ProjectResource rsrc, Input input)
throws RestApiException, IOException, OrmException, ValidationException,
GitAPIException, NoSuchChangeException, NoSuchAccountException,
- UpdateException, ConfigInvalidException, InvalidSshKeyException {
+ UpdateException, ConfigInvalidException {
ImportProjectResource projectResource =
projectsCollection.parse(new ConfigResource(),
IdString.fromDecoded(rsrc.getName()));
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
index 881b6ff..a27ef44 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
@@ -15,7 +15,6 @@
package com.googlesource.gerrit.plugins.importer;
import com.google.common.base.Strings;
-import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.annotations.RequiresCapability;
@@ -96,7 +95,7 @@
public ResumeImportStatistic apply(ImportProjectResource rsrc, Input input)
throws RestApiException, IOException, OrmException, ValidationException,
GitAPIException, NoSuchChangeException, NoSuchAccountException,
- UpdateException, ConfigInvalidException, InvalidSshKeyException {
+ UpdateException, ConfigInvalidException {
if (copy) {
input.validateResumeCopy();
} else {
@@ -133,7 +132,7 @@
public ResumeImportStatistic apply(ProjectResource rsrc, Input input)
throws RestApiException, IOException, OrmException, ValidationException,
GitAPIException, NoSuchChangeException, NoSuchAccountException,
- UpdateException, ConfigInvalidException, InvalidSshKeyException {
+ UpdateException, ConfigInvalidException {
ImportProjectResource projectResource =
projectsCollection.parse(new ConfigResource(),
IdString.fromDecoded(rsrc.getName()));