PutHttpPassword: Move static Input to separate class in extension API

Change-Id: I85f6d452015c04e1678712441c93a0856c1637e6
This commit is contained in:
David Pursehouse
2017-10-04 16:30:56 +01:00
parent 6de1314e4d
commit 112063210a
3 changed files with 26 additions and 10 deletions

View File

@@ -0,0 +1,20 @@
// Copyright (C) 2017 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 HttpPasswordInput {
public String httpPassword;
public boolean generate;
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.account;
import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME;
import com.google.common.base.Strings;
import com.google.gerrit.extensions.common.HttpPasswordInput;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
@@ -24,7 +25,6 @@ import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.PutHttpPassword.Input;
import com.google.gerrit.server.account.externalids.ExternalId;
import com.google.gerrit.server.account.externalids.ExternalIds;
import com.google.gerrit.server.account.externalids.ExternalIdsUpdate;
@@ -40,12 +40,7 @@ import java.security.SecureRandom;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.jgit.errors.ConfigInvalidException;
public class PutHttpPassword implements RestModifyView<AccountResource, Input> {
public static class Input {
public String httpPassword;
public boolean generate;
}
public class PutHttpPassword implements RestModifyView<AccountResource, HttpPasswordInput> {
private static final int LEN = 31;
private static final SecureRandom rng;
@@ -75,7 +70,7 @@ public class PutHttpPassword implements RestModifyView<AccountResource, Input> {
}
@Override
public Response<String> apply(AccountResource rsrc, Input input)
public Response<String> apply(AccountResource rsrc, HttpPasswordInput input)
throws AuthException, ResourceNotFoundException, ResourceConflictException, OrmException,
IOException, ConfigInvalidException, PermissionBackendException {
if (self.get() != rsrc.getUser()) {
@@ -83,7 +78,7 @@ public class PutHttpPassword implements RestModifyView<AccountResource, Input> {
}
if (input == null) {
input = new Input();
input = new HttpPasswordInput();
}
input.httpPassword = Strings.emptyToNull(input.httpPassword);

View File

@@ -23,6 +23,7 @@ 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.EmailInfo;
import com.google.gerrit.extensions.common.HttpPasswordInput;
import com.google.gerrit.extensions.common.Input;
import com.google.gerrit.extensions.common.SshKeyInfo;
import com.google.gerrit.extensions.common.SshKeyInput;
@@ -201,7 +202,7 @@ final class SetAccountCommand extends SshCommand {
}
if (httpPassword != null || clearHttpPassword) {
PutHttpPassword.Input in = new PutHttpPassword.Input();
HttpPasswordInput in = new HttpPasswordInput();
in.httpPassword = httpPassword;
putHttpPassword.apply(rsrc, in);
}