use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.
the class VersionedAuthorizedKeys method setKeys.
/**
* Sets new SSH keys.
*
* <p>The existing SSH keys are overwritten.
*
* @param newKeys the new public SSH keys
*/
public void setKeys(Collection<AccountSshKey> newKeys) {
Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
keys = new ArrayList<>(Collections.nCopies(o.max(newKeys).getKey().get(), Optional.empty()));
for (AccountSshKey key : newKeys) {
keys.set(key.getKey().get() - 1, Optional.of(key));
}
}
use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.
the class AuthorizedKeysTest method addInvalidKey.
/**
* Adds the given public key as invalid SSH key to the given list.
*
* @return the expected line for this key in the authorized_keys file
*/
private static String addInvalidKey(List<Optional<AccountSshKey>> keys, String pub) {
AccountSshKey.Id keyId = new AccountSshKey.Id(new Account.Id(1), keys.size() + 1);
AccountSshKey key = new AccountSshKey(keyId, pub);
key.setInvalid();
keys.add(Optional.of(key));
return AuthorizedKeys.INVALID_KEY_COMMENT_PREFIX + key.getSshPublicKey() + "\n";
}
use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.
the class AuthorizedKeysTest method addKey.
/**
* Adds the given public key as new SSH key to the given list.
*
* @return the expected line for this key in the authorized_keys file
*/
private static String addKey(List<Optional<AccountSshKey>> keys, String pub) {
AccountSshKey.Id keyId = new AccountSshKey.Id(new Account.Id(1), keys.size() + 1);
AccountSshKey key = new AccountSshKey(keyId, pub);
keys.add(Optional.of(key));
return key.getSshPublicKey() + "\n";
}
use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.
the class SetAccountCommand method deleteSshKey.
private void deleteSshKey(SshKeyInfo i) throws AuthException, OrmException, RepositoryNotFoundException, IOException, ConfigInvalidException, PermissionBackendException {
AccountSshKey sshKey = new AccountSshKey(new AccountSshKey.Id(user.getAccountId(), i.seq), i.sshPublicKey);
deleteSshKey.apply(new AccountResource.SshKey(user, sshKey), null);
}
use of com.google.gerrit.reviewdb.client.AccountSshKey in project gerrit by GerritCodeReview.
the class VersionedAuthorizedKeysOnInit method addKey.
public AccountSshKey addKey(String pub) {
checkState(keys != null, "SSH keys not loaded yet");
int seq = keys.isEmpty() ? 1 : keys.size() + 1;
AccountSshKey.Id keyId = new AccountSshKey.Id(accountId, seq);
AccountSshKey key = new VersionedAuthorizedKeys.SimpleSshKeyCreator().create(keyId, pub);
keys.add(Optional.of(key));
return key;
}
Aggregations