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

@@ -0,0 +1,24 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.extensions.common;
public class SshKeyInfo {
public Integer seq;
public String sshPublicKey;
public String encodedKey;
public String algorithm;
public String comment;
public Boolean valid;
}

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

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.api.accounts.EmailInput;
import com.google.gerrit.extensions.common.SshKeyInfo;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.RawInput;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
@@ -37,7 +38,6 @@ import com.google.gerrit.server.account.DeleteSshKey;
import com.google.gerrit.server.account.GetEmails;
import com.google.gerrit.server.account.GetEmails.EmailInfo;
import com.google.gerrit.server.account.GetSshKeys;
import com.google.gerrit.server.account.GetSshKeys.SshKeyInfo;
import com.google.gerrit.server.account.PutActive;
import com.google.gerrit.server.account.PutHttpPassword;
import com.google.gerrit.server.account.PutName;