Search in sources :

Example 1 with RawInput

use of com.google.gerrit.extensions.restapi.RawInput in project gerrit by GerritCodeReview.

the class AddSshKey method apply.

public Response<SshKeyInfo> apply(IdentifiedUser user, Input input) throws BadRequestException, IOException, ConfigInvalidException {
    if (input == null) {
        input = new Input();
    }
    if (input.raw == null) {
        throw new BadRequestException("SSH public key missing");
    }
    final RawInput rawKey = input.raw;
    String sshPublicKey = new ByteSource() {

        @Override
        public InputStream openStream() throws IOException {
            return rawKey.getInputStream();
        }
    }.asCharSource(UTF_8).read();
    try {
        AccountSshKey sshKey = authorizedKeys.addKey(user.getAccountId(), sshPublicKey);
        try {
            addKeyFactory.create(user, sshKey).send();
        } catch (EmailException e) {
            log.error("Cannot send SSH key added message to " + user.getAccount().getPreferredEmail(), e);
        }
        sshKeyCache.evict(user.getUserName());
        return Response.<SshKeyInfo>created(GetSshKeys.newSshKeyInfo(sshKey));
    } catch (InvalidSshKeyException e) {
        throw new BadRequestException(e.getMessage());
    }
}
Also used : RawInput(com.google.gerrit.extensions.restapi.RawInput) Input(com.google.gerrit.server.account.AddSshKey.Input) InvalidSshKeyException(com.google.gerrit.common.errors.InvalidSshKeyException) SshKeyInfo(com.google.gerrit.extensions.common.SshKeyInfo) AccountSshKey(com.google.gerrit.reviewdb.client.AccountSshKey) RawInput(com.google.gerrit.extensions.restapi.RawInput) EmailException(com.google.gerrit.common.errors.EmailException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ByteSource(com.google.common.io.ByteSource)

Example 2 with RawInput

use of com.google.gerrit.extensions.restapi.RawInput in project gerrit by GerritCodeReview.

the class ChangeFileContentModificationSubject method newContent.

public StringSubject newContent() throws IOException {
    isNotNull();
    RawInput newContent = actual().getNewContent();
    Truth.assertThat(newContent).named("newContent").isNotNull();
    String contentString = CharStreams.toString(new InputStreamReader(newContent.getInputStream(), StandardCharsets.UTF_8));
    return Truth.assertThat(contentString).named("newContent");
}
Also used : InputStreamReader(java.io.InputStreamReader) RawInput(com.google.gerrit.extensions.restapi.RawInput)

Aggregations

RawInput (com.google.gerrit.extensions.restapi.RawInput)2 ByteSource (com.google.common.io.ByteSource)1 EmailException (com.google.gerrit.common.errors.EmailException)1 InvalidSshKeyException (com.google.gerrit.common.errors.InvalidSshKeyException)1 SshKeyInfo (com.google.gerrit.extensions.common.SshKeyInfo)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 AccountSshKey (com.google.gerrit.reviewdb.client.AccountSshKey)1 Input (com.google.gerrit.server.account.AddSshKey.Input)1 InputStreamReader (java.io.InputStreamReader)1