Migrate external IDs to NoteDb (part 3)
This is the third part of migrating external IDs from ReviewDb to NoteDb. This change: * changes the code to always read external IDs from NoteDb (the user.readExternalIdsFromGit configuration parameter is removed) * bumps the database schema version * deletes the database table for external IDs Pushing to the refs/meta/external-ids branch is still prevented by a commit validator. Since all external IDs are now in NoteDb only we could allow pushing to refs/meta/external-ids. However we would still like to do validation of the branch content and reject invalid content (e.g. invalid Git config files, usage of non-existing account IDs etc.) and such a validator is not implemented yet (but can be implemented in a follow-up change). Change-Id: Id9e5574a1d8d82f4f48fbb0b6dadc0e27d138a28 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user