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.common.io.ByteSource;
import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.common.errors.InvalidSshKeyException; 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.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.RawInput; 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.CurrentUser;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AddSshKey.Input; 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.mail.AddKeySender;
import com.google.gerrit.server.ssh.SshKeyCache; import com.google.gerrit.server.ssh.SshKeyCache;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -112,7 +112,7 @@ public class AddSshKey implements RestModifyView<AccountResource, Input> {
+ user.getAccount().getPreferredEmail(), e); + user.getAccount().getPreferredEmail(), e);
} }
sshKeyCache.evict(user.getUserName()); sshKeyCache.evict(user.getUserName());
return Response.<SshKeyInfo>created(new SshKeyInfo(sshKey)); return Response.<SshKeyInfo>created(GetSshKeys.newSshKeyInfo(sshKey));
} catch (InvalidSshKeyException e) { } catch (InvalidSshKeyException e) {
throw new BadRequestException(e.getMessage()); throw new BadRequestException(e.getMessage());
} }

View File

@@ -14,9 +14,9 @@
package com.google.gerrit.server.account; package com.google.gerrit.server.account;
import com.google.gerrit.extensions.common.SshKeyInfo;
import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.account.AccountResource.SshKey; import com.google.gerrit.server.account.AccountResource.SshKey;
import com.google.gerrit.server.account.GetSshKeys.SshKeyInfo;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@Singleton @Singleton
@@ -24,6 +24,6 @@ public class GetSshKey implements RestReadView<AccountResource.SshKey> {
@Override @Override
public SshKeyInfo apply(SshKey rsrc) { 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.base.Strings;
import com.google.common.collect.Lists; 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.AuthException;
import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.AccountSshKey; import com.google.gerrit.reviewdb.client.AccountSshKey;
@@ -60,21 +61,14 @@ public class GetSshKeys implements RestReadView<AccountResource> {
return sshKeys; return sshKeys;
} }
public static class SshKeyInfo { public static SshKeyInfo newSshKeyInfo(AccountSshKey sshKey) {
public SshKeyInfo(AccountSshKey sshKey) { SshKeyInfo info = new SshKeyInfo();
seq = sshKey.getKey().get(); info.seq = sshKey.getKey().get();
sshPublicKey = sshKey.getSshPublicKey(); info.sshPublicKey = sshKey.getSshPublicKey();
encodedKey = sshKey.getEncodedKey(); info.encodedKey = sshKey.getEncodedKey();
algorithm = sshKey.getAlgorithm(); info.algorithm = sshKey.getAlgorithm();
comment = Strings.emptyToNull(sshKey.getComment()); info.comment = Strings.emptyToNull(sshKey.getComment());
valid = sshKey.isValid(); info.valid = sshKey.isValid();
} return info;
public int seq;
public String sshPublicKey;
public String encodedKey;
public String algorithm;
public String comment;
public boolean valid;
} }
} }

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.annotations.RequiresCapability; import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.api.accounts.EmailInput; 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.AuthException;
import com.google.gerrit.extensions.restapi.RawInput; import com.google.gerrit.extensions.restapi.RawInput;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException; 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;
import com.google.gerrit.server.account.GetEmails.EmailInfo; import com.google.gerrit.server.account.GetEmails.EmailInfo;
import com.google.gerrit.server.account.GetSshKeys; 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.PutActive;
import com.google.gerrit.server.account.PutHttpPassword; import com.google.gerrit.server.account.PutHttpPassword;
import com.google.gerrit.server.account.PutName; import com.google.gerrit.server.account.PutName;