Merge "Extract SshKeyInfo from GetSshKeys to extension API"
This commit is contained in:
		| @@ -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; | ||||||
|  | } | ||||||
| @@ -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()); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -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()); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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; | ||||||
| @@ -55,26 +56,19 @@ public class GetSshKeys implements RestReadView<AccountResource> { | |||||||
|     List<SshKeyInfo> sshKeys = Lists.newArrayList(); |     List<SshKeyInfo> sshKeys = Lists.newArrayList(); | ||||||
|     for (AccountSshKey sshKey : dbProvider.get().accountSshKeys() |     for (AccountSshKey sshKey : dbProvider.get().accountSshKeys() | ||||||
|         .byAccount(user.getAccountId()).toList()) { |         .byAccount(user.getAccountId()).toList()) { | ||||||
|       sshKeys.add(new SshKeyInfo(sshKey)); |       sshKeys.add(newSshKeyInfo(sshKey)); | ||||||
|     } |     } | ||||||
|     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; |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 David Pursehouse
					David Pursehouse