Merge "Extract SshKeyInfo from GetSshKeys to extension API"
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.gerrit.common.errors.EmailException;
|
||||
import com.google.gerrit.common.errors.InvalidSshKeyException;
|
||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.RawInput;
|
||||
@@ -30,7 +31,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AddSshKey.Input;
|
||||
import com.google.gerrit.server.account.GetSshKeys.SshKeyInfo;
|
||||
import com.google.gerrit.server.mail.AddKeySender;
|
||||
import com.google.gerrit.server.ssh.SshKeyCache;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -112,7 +112,7 @@ public class AddSshKey implements RestModifyView<AccountResource, Input> {
|
||||
+ user.getAccount().getPreferredEmail(), e);
|
||||
}
|
||||
sshKeyCache.evict(user.getUserName());
|
||||
return Response.<SshKeyInfo>created(new SshKeyInfo(sshKey));
|
||||
return Response.<SshKeyInfo>created(GetSshKeys.newSshKeyInfo(sshKey));
|
||||
} catch (InvalidSshKeyException e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.account.AccountResource.SshKey;
|
||||
import com.google.gerrit.server.account.GetSshKeys.SshKeyInfo;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
@@ -24,6 +24,6 @@ public class GetSshKey implements RestReadView<AccountResource.SshKey> {
|
||||
|
||||
@Override
|
||||
public SshKeyInfo apply(SshKey rsrc) {
|
||||
return new SshKeyInfo(rsrc.getSshKey());
|
||||
return GetSshKeys.newSshKeyInfo(rsrc.getSshKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.AccountSshKey;
|
||||
@@ -55,26 +56,19 @@ public class GetSshKeys implements RestReadView<AccountResource> {
|
||||
List<SshKeyInfo> sshKeys = Lists.newArrayList();
|
||||
for (AccountSshKey sshKey : dbProvider.get().accountSshKeys()
|
||||
.byAccount(user.getAccountId()).toList()) {
|
||||
sshKeys.add(new SshKeyInfo(sshKey));
|
||||
sshKeys.add(newSshKeyInfo(sshKey));
|
||||
}
|
||||
return sshKeys;
|
||||
}
|
||||
|
||||
public static class SshKeyInfo {
|
||||
public SshKeyInfo(AccountSshKey sshKey) {
|
||||
seq = sshKey.getKey().get();
|
||||
sshPublicKey = sshKey.getSshPublicKey();
|
||||
encodedKey = sshKey.getEncodedKey();
|
||||
algorithm = sshKey.getAlgorithm();
|
||||
comment = Strings.emptyToNull(sshKey.getComment());
|
||||
valid = sshKey.isValid();
|
||||
}
|
||||
|
||||
public int seq;
|
||||
public String sshPublicKey;
|
||||
public String encodedKey;
|
||||
public String algorithm;
|
||||
public String comment;
|
||||
public boolean valid;
|
||||
public static SshKeyInfo newSshKeyInfo(AccountSshKey sshKey) {
|
||||
SshKeyInfo info = new SshKeyInfo();
|
||||
info.seq = sshKey.getKey().get();
|
||||
info.sshPublicKey = sshKey.getSshPublicKey();
|
||||
info.encodedKey = sshKey.getEncodedKey();
|
||||
info.algorithm = sshKey.getAlgorithm();
|
||||
info.comment = Strings.emptyToNull(sshKey.getComment());
|
||||
info.valid = sshKey.isValid();
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user