Move contact store configuration off GerritServer
Instead we get the configuration directly from the GerritServerConfig annotated Config object, which is available through injection. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -19,6 +19,8 @@ import com.google.gerrit.client.reviewdb.ContactInformation;
|
||||
import com.google.gerrit.client.rpc.ContactInformationStoreException;
|
||||
|
||||
public interface ContactStore {
|
||||
boolean isEnabled();
|
||||
|
||||
void store(Account account, ContactInformation info)
|
||||
throws ContactInformationStoreException;
|
||||
}
|
||||
|
@@ -19,9 +19,11 @@ import com.google.gerrit.client.reviewdb.AccountExternalId;
|
||||
import com.google.gerrit.client.reviewdb.ContactInformation;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.client.rpc.ContactInformationStoreException;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.apache.sshd.common.util.SecurityUtils;
|
||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
@@ -36,6 +38,7 @@ import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||||
import org.bouncycastle.openpgp.PGPUtil;
|
||||
import org.spearce.jgit.lib.Config;
|
||||
import org.spearce.jgit.util.NB;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -61,26 +64,28 @@ class EncryptedContactStore implements ContactStore {
|
||||
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
|
||||
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private PGPPublicKey dest;
|
||||
private SecureRandom prng;
|
||||
private URL storeUrl;
|
||||
private String storeAPPSEC;
|
||||
private final PGPPublicKey dest;
|
||||
private final SecureRandom prng;
|
||||
private final URL storeUrl;
|
||||
private final String storeAPPSEC;
|
||||
|
||||
EncryptedContactStore(final GerritServer server,
|
||||
@Inject
|
||||
EncryptedContactStore(@GerritServerConfig final Config cfg,
|
||||
@SitePath final File sitePath, final SchemaFactory<ReviewDb> sf)
|
||||
throws ContactInformationStoreException {
|
||||
schema = sf;
|
||||
|
||||
if (server.getContactStoreURL() == null) {
|
||||
final String url = cfg.getString("contactstore", null, "url");
|
||||
if (url == null) {
|
||||
throw new ContactInformationStoreException(new IllegalStateException(
|
||||
"No contactStoreURL configured"));
|
||||
"contactstore.url not set"));
|
||||
}
|
||||
try {
|
||||
storeUrl = new URL(server.getContactStoreURL());
|
||||
storeUrl = new URL(url);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new ContactInformationStoreException(e);
|
||||
}
|
||||
storeAPPSEC = server.getContactStoreAPPSEC();
|
||||
storeAPPSEC = cfg.getString("contactstore", null, "appsec");
|
||||
|
||||
if (!SecurityUtils.isBouncyCastleRegistered()) {
|
||||
throw new ContactInformationStoreException(new NoSuchProviderException(
|
||||
@@ -96,6 +101,11 @@ class EncryptedContactStore implements ContactStore {
|
||||
dest = selectKey(readPubRing(sitePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private PGPPublicKeyRingCollection readPubRing(final File sitePath)
|
||||
throws ContactInformationStoreException {
|
||||
final File pub = new File(sitePath, "contact_information.pub");
|
||||
|
@@ -18,16 +18,20 @@ import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.ContactInformation;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.client.rpc.ContactInformationStoreException;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.spearce.jgit.lib.Config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
class EncryptedContactStoreProvider implements Provider<ContactStore> {
|
||||
@Inject
|
||||
private GerritServer server;
|
||||
@GerritServerConfig
|
||||
private Config config;
|
||||
|
||||
@Inject
|
||||
private SchemaFactory<ReviewDb> schema;
|
||||
@@ -39,9 +43,14 @@ class EncryptedContactStoreProvider implements Provider<ContactStore> {
|
||||
@Override
|
||||
public ContactStore get() {
|
||||
try {
|
||||
return new EncryptedContactStore(server, sitePath, schema);
|
||||
return new EncryptedContactStore(config, sitePath, schema);
|
||||
} catch (final ContactInformationStoreException initError) {
|
||||
return new ContactStore() {
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(Account account, ContactInformation info)
|
||||
throws ContactInformationStoreException {
|
||||
|
@@ -42,8 +42,10 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
|
||||
private final GerritServer server;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
|
||||
private GerritSshDaemon sshd;
|
||||
private EmailSender emailSender;
|
||||
private ContactStore contactStore;
|
||||
|
||||
@Inject
|
||||
GerritConfigProvider(final GerritServer gs, final SchemaFactory<ReviewDb> sf) {
|
||||
@@ -61,6 +63,11 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
emailSender = d;
|
||||
}
|
||||
|
||||
@Inject(optional = true)
|
||||
void setContactStore(final ContactStore d) {
|
||||
contactStore = d;
|
||||
}
|
||||
|
||||
private GerritConfig create() throws OrmException {
|
||||
final Config cfg = server.getGerritConfig();
|
||||
final GerritConfig config = new GerritConfig();
|
||||
@@ -70,7 +77,7 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
|
||||
config.setUseRepoDownload(cfg.getBoolean("repo", null,
|
||||
"showdownloadcommand", false));
|
||||
config.setUseContactInfo(server.getContactStoreURL() != null);
|
||||
config.setUseContactInfo(contactStore != null && contactStore.isEnabled());
|
||||
config.setAllowRegisterNewEmail(emailSender != null
|
||||
&& emailSender.isEnabled());
|
||||
config.setLoginType(server.getLoginType());
|
||||
|
@@ -307,14 +307,6 @@ public class GerritServer {
|
||||
return getGerritConfig().getString("auth", null, "emailformat");
|
||||
}
|
||||
|
||||
public String getContactStoreURL() {
|
||||
return getGerritConfig().getString("contactstore", null, "url");
|
||||
}
|
||||
|
||||
public String getContactStoreAPPSEC() {
|
||||
return getGerritConfig().getString("contactstore", null, "appsec");
|
||||
}
|
||||
|
||||
/** Optional canonical URL for this application. */
|
||||
public String getCanonicalURL() {
|
||||
String u = getGerritConfig().getString("gerrit", null, "canonicalweburl");
|
||||
|
Reference in New Issue
Block a user