Add schema migration to populate gpg subkey to master key map
Change-Id: I342413df1730395745cda837c90e71a09003d24c
This commit is contained in:
@@ -3,6 +3,7 @@ java_library(
|
||||
srcs = glob(["**/*.java"]),
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//java/com/google/gerrit/common:annotations",
|
||||
"//java/com/google/gerrit/common:server",
|
||||
"//java/com/google/gerrit/exceptions",
|
||||
"//java/com/google/gerrit/extensions:api",
|
||||
|
||||
@@ -272,6 +272,25 @@ public class PublicKeyStore implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
public void rebuildSubkeyMasterKeyMap()
|
||||
throws MissingObjectException, IncorrectObjectTypeException, IOException, PGPException {
|
||||
if (reader == null) {
|
||||
load();
|
||||
}
|
||||
if (notes != null) {
|
||||
try (ObjectInserter ins = repo.newObjectInserter()) {
|
||||
for (Note note : notes) {
|
||||
for (PGPPublicKeyRing keyRing :
|
||||
new PGPPublicKeyRingCollection(readKeysFromNote(note, null))) {
|
||||
long masterKeyId = keyRing.getPublicKey().getKeyID();
|
||||
ObjectId masterKeyObjectId = keyObjectId(masterKeyId);
|
||||
saveSubkeyMaping(ins, keyRing, masterKeyId, masterKeyObjectId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a public key to the store.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,7 @@ java_library(
|
||||
"//java/com/google/gerrit/exceptions",
|
||||
"//java/com/google/gerrit/extensions:api",
|
||||
"//java/com/google/gerrit/git",
|
||||
"//java/com/google/gerrit/gpg",
|
||||
"//java/com/google/gerrit/lifecycle",
|
||||
"//java/com/google/gerrit/metrics",
|
||||
"//java/com/google/gerrit/reviewdb:server",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -30,11 +31,14 @@ interface NoteDbSchemaVersion {
|
||||
class Arguments {
|
||||
final GitRepositoryManager repoManager;
|
||||
final AllProjectsName allProjects;
|
||||
final AllUsersName allUsers;
|
||||
|
||||
@Inject
|
||||
Arguments(GitRepositoryManager repoManager, AllProjectsName allProjects) {
|
||||
Arguments(
|
||||
GitRepositoryManager repoManager, AllProjectsName allProjects, AllUsersName allUsers) {
|
||||
this.repoManager = repoManager;
|
||||
this.allProjects = allProjects;
|
||||
this.allUsers = allUsers;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.stream.Stream;
|
||||
public class NoteDbSchemaVersions {
|
||||
static final ImmutableSortedMap<Integer, Class<? extends NoteDbSchemaVersion>> ALL =
|
||||
// List all supported NoteDb schema versions here.
|
||||
Stream.of(Schema_180.class)
|
||||
Stream.of(Schema_180.class, Schema_181.class)
|
||||
.collect(toImmutableSortedMap(naturalOrder(), v -> guessVersion(v).get(), v -> v));
|
||||
|
||||
public static final int FIRST = ALL.firstKey();
|
||||
|
||||
29
java/com/google/gerrit/server/schema/Schema_181.java
Normal file
29
java/com/google/gerrit/server/schema/Schema_181.java
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import com.google.gerrit.gpg.PublicKeyStore;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
public class Schema_181 implements NoteDbSchemaVersion {
|
||||
@Override
|
||||
public void upgrade(Arguments args, UpdateUI ui) throws Exception {
|
||||
ui.message("Rebuild GPGP note map to build subkey to master key map");
|
||||
try (Repository repo = args.repoManager.openRepository(args.allUsers);
|
||||
PublicKeyStore store = new PublicKeyStore(repo)) {
|
||||
store.rebuildSubkeyMasterKeyMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class NoteDbSchemaUpdaterTest extends GerritBaseTests {
|
||||
allUsersName = new AllUsersName("The-Users");
|
||||
repoManager = new InMemoryRepositoryManager();
|
||||
|
||||
args = new NoteDbSchemaVersion.Arguments(repoManager, allProjectsName);
|
||||
args = new NoteDbSchemaVersion.Arguments(repoManager, allProjectsName, allUsersName);
|
||||
NoteDbSchemaVersionManager versionManager =
|
||||
new NoteDbSchemaVersionManager(allProjectsName, repoManager);
|
||||
updater =
|
||||
|
||||
Reference in New Issue
Block a user