Merge changes from topic 'migrate-external-ids-3'

* changes:
  Allow to update external IDs by push
  Migrate external IDs to NoteDb (part 3)
This commit is contained in:
ekempin
2017-05-11 13:51:20 +00:00
committed by Gerrit Code Review
40 changed files with 467 additions and 670 deletions

View File

@@ -19,14 +19,12 @@ import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USE
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.gerrit.reviewdb.client.AccountSshKey;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.VersionedAuthorizedKeys;
import com.google.gerrit.server.account.externalids.ExternalId;
import com.google.gerrit.server.account.externalids.ExternalIds;
import com.google.gerrit.server.cache.CacheModule;
import com.google.gerrit.server.ssh.SshKeyCache;
import com.google.gerrit.server.ssh.SshKeyCreator;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Module;
import com.google.inject.Singleton;
@@ -92,40 +90,33 @@ public class SshKeyCacheImpl implements SshKeyCache {
}
static class Loader extends CacheLoader<String, Iterable<SshKeyCacheEntry>> {
private final SchemaFactory<ReviewDb> schema;
private final ExternalIds externalIds;
private final VersionedAuthorizedKeys.Accessor authorizedKeys;
@Inject
Loader(
SchemaFactory<ReviewDb> schema,
ExternalIds externalIds,
VersionedAuthorizedKeys.Accessor authorizedKeys) {
this.schema = schema;
Loader(ExternalIds externalIds, VersionedAuthorizedKeys.Accessor authorizedKeys) {
this.externalIds = externalIds;
this.authorizedKeys = authorizedKeys;
}
@Override
public Iterable<SshKeyCacheEntry> load(String username) throws Exception {
try (ReviewDb db = schema.open()) {
ExternalId user = externalIds.get(db, ExternalId.Key.create(SCHEME_USERNAME, username));
if (user == null) {
return NO_SUCH_USER;
}
List<SshKeyCacheEntry> kl = new ArrayList<>(4);
for (AccountSshKey k : authorizedKeys.getKeys(user.accountId())) {
if (k.isValid()) {
add(kl, k);
}
}
if (kl.isEmpty()) {
return NO_KEYS;
}
return Collections.unmodifiableList(kl);
ExternalId user = externalIds.get(ExternalId.Key.create(SCHEME_USERNAME, username));
if (user == null) {
return NO_SUCH_USER;
}
List<SshKeyCacheEntry> kl = new ArrayList<>(4);
for (AccountSshKey k : authorizedKeys.getKeys(user.accountId())) {
if (k.isValid()) {
add(kl, k);
}
}
if (kl.isEmpty()) {
return NO_KEYS;
}
return Collections.unmodifiableList(kl);
}
private void add(List<SshKeyCacheEntry> kl, AccountSshKey k) {