use of com.google.gerrit.extensions.api.accounts.SshKeyInput in project gerrit by GerritCodeReview.
the class AccountApiImpl method addSshKey.
@Override
public SshKeyInfo addSshKey(String key) throws RestApiException {
SshKeyInput in = new SshKeyInput();
in.raw = RawInputUtil.create(key);
try {
return addSshKey.apply(account, in).value();
} catch (Exception e) {
throw asRestApiException("Cannot add SSH key", e);
}
}
use of com.google.gerrit.extensions.api.accounts.SshKeyInput in project gerrit by GerritCodeReview.
the class SetAccountCommand method addSshKeys.
private void addSshKeys(List<String> sshKeys) throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException {
for (String sshKey : sshKeys) {
SshKeyInput in = new SshKeyInput();
in.raw = RawInputUtil.create(sshKey.getBytes(UTF_8), "text/plain");
addSshKey.apply(rsrc, in);
}
}
use of com.google.gerrit.extensions.api.accounts.SshKeyInput in project gerrit by GerritCodeReview.
the class AddSshKey method apply.
public Response<SshKeyInfo> apply(IdentifiedUser user, SshKeyInput input) throws BadRequestException, IOException, ConfigInvalidException {
if (input == null) {
input = new SshKeyInput();
}
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) {
logger.atSevere().withCause(e).log("Cannot send SSH key added message to %s", user.getAccount().preferredEmail());
}
user.getUserName().ifPresent(sshKeyCache::evict);
return Response.created(GetSshKeys.newSshKeyInfo(sshKey));
} catch (InvalidSshKeyException e) {
throw new BadRequestException(e.getMessage());
}
}
Aggregations