Extract SshKeyInfo from GetSshKeys to extension API

Change-Id: I900a527a5b0d1d2635f54e200fdb5a2f32c0596d
This commit is contained in:
David Pursehouse
2016-03-16 18:01:08 +09:00
parent 3c3f01e80e
commit f5118d8338
5 changed files with 40 additions and 22 deletions

View File

@@ -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());
}

View File

@@ -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());
}
}

View File

@@ -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;
}
}