diff --git a/Documentation/cmd-set-account.txt b/Documentation/cmd-set-account.txt index 884c8ccda4..adbb6b13cf 100644 --- a/Documentation/cmd-set-account.txt +++ b/Documentation/cmd-set-account.txt @@ -12,6 +12,7 @@ _ssh_ -p _gerrit set-account_ [--preferred-email ] [--add-ssh-key - | ] [--delete-ssh-key - | | ALL] + [--generate-http-password] [--http-password ] [--clear-http-password] -- @@ -93,6 +94,11 @@ This most likely requires double quoting the value, for example May be supplied more than once to delete multiple SSH keys in a single command execution. +--generate-http-password:: + Generate a new random HTTP password for the user account + similar to the web ui. The password will be output to the + user on success with a line: `New password: `. + --http-password:: Set the HTTP password for the user account. diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/SetAccountCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/SetAccountCommand.java index f413461688..6e1a3b8bdc 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/SetAccountCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/SetAccountCommand.java @@ -26,6 +26,7 @@ import com.google.gerrit.extensions.common.EmailInfo; import com.google.gerrit.extensions.common.SshKeyInfo; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException; +import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.AccountSshKey; @@ -113,6 +114,9 @@ final class SetAccountCommand extends SshCommand { @Option(name = "--clear-http-password", usage = "clear HTTP password for the account") private boolean clearHttpPassword; + @Option(name = "--generate-http-password", usage = "generate a new HTTP password for the account") + private boolean generateHttpPassword; + @Inject private IdentifiedUser.GenericFactory genericUserFactory; @Inject private CreateEmail.Factory createEmailFactory; @@ -150,8 +154,16 @@ final class SetAccountCommand extends SshCommand { if (active && inactive) { throw die("--active and --inactive options are mutually exclusive."); } - if (clearHttpPassword && !Strings.isNullOrEmpty(httpPassword)) { - throw die("--http-password and --clear-http-password options are mutually exclusive."); + if (generateHttpPassword && clearHttpPassword) { + throw die("--generate-http-password and --clear-http-password are mutually exclusive."); + } + if (!Strings.isNullOrEmpty(httpPassword)) { // gave --http-password + if (generateHttpPassword) { + throw die("--http-password and --generate-http-password options are mutually exclusive."); + } + if (clearHttpPassword) { + throw die("--http-password and --clear-http-password options are mutually exclusive."); + } } if (addSshKeys.contains("-") && deleteSshKeys.contains("-")) { throw die("Only one option may use the stdin"); @@ -193,10 +205,16 @@ final class SetAccountCommand extends SshCommand { putName.apply(rsrc, in); } - if (httpPassword != null || clearHttpPassword) { + if (httpPassword != null || clearHttpPassword || generateHttpPassword) { PutHttpPassword.Input in = new PutHttpPassword.Input(); in.httpPassword = httpPassword; - putHttpPassword.apply(rsrc, in); + if (generateHttpPassword) { + in.generate = true; + } + Response resp = putHttpPassword.apply(rsrc, in); + if (generateHttpPassword) { + stdout.print("New password: " + resp.value() + "\n"); + } } if (active) {