Add API to make SecureStore switching possible

In order to be able to implement switching the SecureStore
implementation we need to obtain a list of the currently stored values in the
SecureStore. For this purpose a list() method was added to SecureStore
interface.

Then we can decode them using the old implementation and encrypt with new
one and also replace the secure store jar file in the lib folder and
change the configuration in the gerrit.config in a separate site
program.

Change-Id: Ia270d0ee4a708b5724601902f3382bea3ae45356
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
This commit is contained in:
Dariusz Luksza
2014-09-09 18:37:45 +02:00
parent dab88b1ab1
commit d984b9c6ce
3 changed files with 35 additions and 0 deletions

View File

@@ -144,5 +144,10 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
public void unset(String section, String subsection, String name) {
cfg.unset(section, subsection, name);
}
@Override
public Iterable<EntryKey> list() {
throw new UnsupportedOperationException("not used by tests");
}
}
}

View File

@@ -26,6 +26,7 @@ import org.eclipse.jgit.util.FS;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Singleton
@@ -80,6 +81,22 @@ public class DefaultSecureStore implements SecureStore {
save();
}
@Override
public Iterable<EntryKey> list() {
List<EntryKey> result = new ArrayList<>();
for (String section : sec.getSections()) {
for (String subsection : sec.getSubsections(section)) {
for (String name : sec.getNames(section, subsection)) {
result.add(new EntryKey(section, subsection, name));
}
}
for (String name : sec.getNames(section)) {
result.add(new EntryKey(section, null, name));
}
}
return result;
}
private void save() {
try {
saveSecure(sec);

View File

@@ -17,6 +17,17 @@ package com.google.gerrit.server.securestore;
import java.util.List;
public interface SecureStore {
public static class EntryKey {
public final String name;
public final String section;
public final String subsection;
public EntryKey(String section, String subsection, String name) {
this.name = name;
this.section = section;
this.subsection = subsection;
}
}
String get(String section, String subsection, String name);
@@ -27,4 +38,6 @@ public interface SecureStore {
void setList(String section, String subsection, String name, List<String> values);
void unset(String section, String subsection, String name);
Iterable<EntryKey> list();
}