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());
}
}
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");
}
Aggregations