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