SitePaths: Convert configuration paths to Path
Change-Id: Ie25659964fa2546e2b73370edaa87a86da1d6b70
This commit is contained in:
@@ -125,6 +125,7 @@ java_test(
|
|||||||
':init-api',
|
':init-api',
|
||||||
':pgm',
|
':pgm',
|
||||||
'//gerrit-server:server',
|
'//gerrit-server:server',
|
||||||
|
'//lib:guava',
|
||||||
'//lib:junit',
|
'//lib:junit',
|
||||||
'//lib/easymock:easymock',
|
'//lib/easymock:easymock',
|
||||||
'//lib/guice:guice',
|
'//lib/guice:guice',
|
||||||
|
@@ -47,7 +47,7 @@ import java.util.zip.ZipEntry;
|
|||||||
public class SwitchSecureStore extends SiteProgram {
|
public class SwitchSecureStore extends SiteProgram {
|
||||||
private static String getSecureStoreClassFromGerritConfig(SitePaths sitePaths) {
|
private static String getSecureStoreClassFromGerritConfig(SitePaths sitePaths) {
|
||||||
FileBasedConfig cfg =
|
FileBasedConfig cfg =
|
||||||
new FileBasedConfig(sitePaths.gerrit_config, FS.DETECTED);
|
new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
|
||||||
try {
|
try {
|
||||||
cfg.load();
|
cfg.load();
|
||||||
} catch (IOException | ConfigInvalidException e) {
|
} catch (IOException | ConfigInvalidException e) {
|
||||||
@@ -151,7 +151,7 @@ public class SwitchSecureStore extends SiteProgram {
|
|||||||
log.info("Set gerrit.secureStoreClass property of gerrit.config to {}",
|
log.info("Set gerrit.secureStoreClass property of gerrit.config to {}",
|
||||||
newSecureStore);
|
newSecureStore);
|
||||||
FileBasedConfig config =
|
FileBasedConfig config =
|
||||||
new FileBasedConfig(sitePaths.gerrit_config, FS.DETECTED);
|
new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
|
||||||
config.load();
|
config.load();
|
||||||
config.setString("gerrit", null, "secureStoreClass", newSecureStore);
|
config.setString("gerrit", null, "secureStoreClass", newSecureStore);
|
||||||
config.save();
|
config.save();
|
||||||
|
@@ -169,7 +169,7 @@ class InitHttpd implements InitStep {
|
|||||||
final String dname =
|
final String dname =
|
||||||
"CN=" + hostname + ",OU=Gerrit Code Review,O=" + domainOf(hostname);
|
"CN=" + hostname + ",OU=Gerrit Code Review,O=" + domainOf(hostname);
|
||||||
|
|
||||||
Path tmpdir = site.etc_dir.toPath().resolve("tmp.sslcertgen");
|
Path tmpdir = site.etc_dir.resolve("tmp.sslcertgen");
|
||||||
try {
|
try {
|
||||||
Files.createDirectory(tmpdir);
|
Files.createDirectory(tmpdir);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@@ -25,6 +25,8 @@ import com.google.gerrit.server.mail.SmtpEmailSender.Encryption;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
/** Initialize the {@code sendemail} configuration section. */
|
/** Initialize the {@code sendemail} configuration section. */
|
||||||
@Singleton
|
@Singleton
|
||||||
class InitSendEmail implements InitStep {
|
class InitSendEmail implements InitStep {
|
||||||
@@ -54,7 +56,7 @@ class InitSendEmail implements InitStep {
|
|||||||
true);
|
true);
|
||||||
|
|
||||||
String username = null;
|
String username = null;
|
||||||
if (site.gerrit_config.exists()) {
|
if (Files.exists(site.gerrit_config)) {
|
||||||
username = sendemail.get("smtpUser");
|
username = sendemail.get("smtpUser");
|
||||||
} else if ((enc != null && enc != Encryption.NONE) || !isLocal(hostname)) {
|
} else if ((enc != null && enc != Encryption.NONE) || !isLocal(hostname)) {
|
||||||
username = username();
|
username = username();
|
||||||
|
@@ -131,7 +131,7 @@ class InitSshd implements InitStep {
|
|||||||
// short period of time. We try to reduce that risk by creating
|
// short period of time. We try to reduce that risk by creating
|
||||||
// the key within a temporary directory.
|
// the key within a temporary directory.
|
||||||
//
|
//
|
||||||
Path tmpdir = site.etc_dir.toPath().resolve("tmp.sshkeygen");
|
Path tmpdir = site.etc_dir.resolve("tmp.sshkeygen");
|
||||||
try {
|
try {
|
||||||
Files.createDirectory(tmpdir);
|
Files.createDirectory(tmpdir);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@@ -37,6 +37,8 @@ import java.io.InputStream;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@@ -65,7 +67,7 @@ class UpgradeFrom2_0_x implements InitStep {
|
|||||||
private final FileBasedConfig cfg;
|
private final FileBasedConfig cfg;
|
||||||
private final SecureStore sec;
|
private final SecureStore sec;
|
||||||
private final File site_path;
|
private final File site_path;
|
||||||
private final File etc_dir;
|
private final Path etc_dir;
|
||||||
private final Section.Factory sections;
|
private final Section.Factory sections;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -100,14 +102,16 @@ class UpgradeFrom2_0_x implements InitStep {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (String name : etcFiles) {
|
for (String name : etcFiles) {
|
||||||
final File src = new File(site_path, name);
|
Path src = site_path.toPath().resolve(name);
|
||||||
final File dst = new File(etc_dir, name);
|
Path dst = etc_dir.resolve(name);
|
||||||
if (src.exists()) {
|
if (Files.exists(src)) {
|
||||||
if (dst.exists()) {
|
if (Files.exists(dst)) {
|
||||||
throw die("File " + src + " would overwrite " + dst);
|
throw die("File " + src + " would overwrite " + dst);
|
||||||
}
|
}
|
||||||
if (!src.renameTo(dst)) {
|
try {
|
||||||
throw die("Cannot rename " + src + " to " + dst);
|
Files.move(src, dst);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw die("Cannot rename " + src + " to " + dst, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ public class InitFlags {
|
|||||||
ConfigInvalidException {
|
ConfigInvalidException {
|
||||||
sec = secureStore;
|
sec = secureStore;
|
||||||
this.installPlugins = installPlugins;
|
this.installPlugins = installPlugins;
|
||||||
cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
|
cfg = new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED);
|
||||||
|
|
||||||
cfg.load();
|
cfg.load();
|
||||||
}
|
}
|
||||||
|
@@ -199,7 +199,8 @@ public abstract class SiteProgram extends AbstractProgram {
|
|||||||
};
|
};
|
||||||
Injector i = Guice.createInjector(m);
|
Injector i = Guice.createInjector(m);
|
||||||
SitePaths site = i.getInstance(SitePaths.class);
|
SitePaths site = i.getInstance(SitePaths.class);
|
||||||
FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
|
FileBasedConfig cfg =
|
||||||
|
new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED);
|
||||||
if (!cfg.getFile().exists()) {
|
if (!cfg.getFile().exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.gerrit.pgm.init.api.ConsoleUI;
|
import com.google.gerrit.pgm.init.api.ConsoleUI;
|
||||||
import com.google.gerrit.pgm.init.api.InitFlags;
|
import com.google.gerrit.pgm.init.api.InitFlags;
|
||||||
import com.google.gerrit.pgm.init.api.Section;
|
import com.google.gerrit.pgm.init.api.Section;
|
||||||
@@ -36,11 +37,10 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
|||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
import org.eclipse.jgit.storage.file.FileBasedConfig;
|
import org.eclipse.jgit.storage.file.FileBasedConfig;
|
||||||
import org.eclipse.jgit.util.FS;
|
import org.eclipse.jgit.util.FS;
|
||||||
import org.eclipse.jgit.util.IO;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -55,7 +55,7 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
|
|||||||
final SitePaths site = new SitePaths(p);
|
final SitePaths site = new SitePaths(p);
|
||||||
assertTrue(site.isNew);
|
assertTrue(site.isNew);
|
||||||
assertTrue(site.site_path.mkdir());
|
assertTrue(site.site_path.mkdir());
|
||||||
assertTrue(site.etc_dir.mkdir());
|
Files.createDirectory(site.etc_dir);
|
||||||
|
|
||||||
for (String n : UpgradeFrom2_0_x.etcFiles) {
|
for (String n : UpgradeFrom2_0_x.etcFiles) {
|
||||||
Files.write(p.resolve(n), ("# " + n + "\n").getBytes(UTF_8));
|
Files.write(p.resolve(n), ("# " + n + "\n").getBytes(UTF_8));
|
||||||
@@ -98,11 +98,14 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
|
|||||||
for (String n : UpgradeFrom2_0_x.etcFiles) {
|
for (String n : UpgradeFrom2_0_x.etcFiles) {
|
||||||
if ("gerrit.config".equals(n)) continue;
|
if ("gerrit.config".equals(n)) continue;
|
||||||
if ("secure.config".equals(n)) continue;
|
if ("secure.config".equals(n)) continue;
|
||||||
assertEquals("# " + n + "\n",//
|
try (InputStream in = Files.newInputStream(site.etc_dir.resolve(n))) {
|
||||||
new String(IO.readFully(new File(site.etc_dir, n)), "UTF-8"));
|
assertEquals("# " + n + "\n",
|
||||||
|
new String(ByteStreams.toByteArray(in), UTF_8));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
|
FileBasedConfig cfg =
|
||||||
|
new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED);
|
||||||
cfg.load();
|
cfg.load();
|
||||||
|
|
||||||
assertEquals("email.user", cfg.getString("sendemail", null, "smtpUser"));
|
assertEquals("email.user", cfg.getString("sendemail", null, "smtpUser"));
|
||||||
|
@@ -44,10 +44,11 @@ class GerritServerConfigProvider implements Provider<Config> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Config get() {
|
public Config get() {
|
||||||
FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
|
FileBasedConfig cfg =
|
||||||
|
new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED);
|
||||||
|
|
||||||
if (!cfg.getFile().exists()) {
|
if (!cfg.getFile().exists()) {
|
||||||
log.info("No " + site.gerrit_config.getAbsolutePath()
|
log.info("No " + site.gerrit_config.toAbsolutePath()
|
||||||
+ "; assuming defaults");
|
+ "; assuming defaults");
|
||||||
return new GerritConfig(cfg, secureStore);
|
return new GerritConfig(cfg, secureStore);
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -61,7 +62,7 @@ public class PluginConfigFactory implements ReloadPluginListener {
|
|||||||
this.projectStateFactory = projectStateFactory;
|
this.projectStateFactory = projectStateFactory;
|
||||||
this.pluginConfigs = Maps.newHashMap();
|
this.pluginConfigs = Maps.newHashMap();
|
||||||
|
|
||||||
this.cfgSnapshot = FileSnapshot.save(site.gerrit_config);
|
this.cfgSnapshot = FileSnapshot.save(site.gerrit_config.toFile());
|
||||||
this.cfg = cfgProvider.get();
|
this.cfg = cfgProvider.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +104,9 @@ public class PluginConfigFactory implements ReloadPluginListener {
|
|||||||
* @return the plugin configuration from the 'gerrit.config' file
|
* @return the plugin configuration from the 'gerrit.config' file
|
||||||
*/
|
*/
|
||||||
public PluginConfig getFromGerritConfig(String pluginName, boolean refresh) {
|
public PluginConfig getFromGerritConfig(String pluginName, boolean refresh) {
|
||||||
if (refresh && cfgSnapshot.isModified(site.gerrit_config)) {
|
File configFile = site.gerrit_config.toFile();
|
||||||
cfgSnapshot = FileSnapshot.save(site.gerrit_config);
|
if (refresh && cfgSnapshot.isModified(configFile)) {
|
||||||
|
cfgSnapshot = FileSnapshot.save(configFile);
|
||||||
cfg = cfgProvider.get();
|
cfg = cfgProvider.get();
|
||||||
}
|
}
|
||||||
return new PluginConfig(pluginName, cfg);
|
return new PluginConfig(pluginName, cfg);
|
||||||
@@ -250,20 +252,21 @@ public class PluginConfigFactory implements ReloadPluginListener {
|
|||||||
return pluginConfigs.get(pluginName);
|
return pluginConfigs.get(pluginName);
|
||||||
}
|
}
|
||||||
|
|
||||||
File pluginConfigFile = new File(site.etc_dir, pluginName + ".config");
|
Path pluginConfigFile = site.etc_dir.resolve(pluginName + ".config");
|
||||||
FileBasedConfig cfg = new FileBasedConfig(pluginConfigFile, FS.DETECTED);
|
FileBasedConfig cfg =
|
||||||
|
new FileBasedConfig(pluginConfigFile.toFile(), FS.DETECTED);
|
||||||
pluginConfigs.put(pluginName, cfg);
|
pluginConfigs.put(pluginName, cfg);
|
||||||
if (!cfg.getFile().exists()) {
|
if (!cfg.getFile().exists()) {
|
||||||
log.info("No " + pluginConfigFile.getAbsolutePath() + "; assuming defaults");
|
log.info("No " + pluginConfigFile.toAbsolutePath() + "; assuming defaults");
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cfg.load();
|
cfg.load();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warn("Failed to load " + pluginConfigFile.getAbsolutePath(), e);
|
log.warn("Failed to load " + pluginConfigFile.toAbsolutePath(), e);
|
||||||
} catch (ConfigInvalidException e) {
|
} catch (ConfigInvalidException e) {
|
||||||
log.warn("Failed to load " + pluginConfigFile.getAbsolutePath(), e);
|
log.warn("Failed to load " + pluginConfigFile.toAbsolutePath(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
|
@@ -31,7 +31,7 @@ public final class SitePaths {
|
|||||||
|
|
||||||
public final File site_path;
|
public final File site_path;
|
||||||
public final Path bin_dir;
|
public final Path bin_dir;
|
||||||
public final File etc_dir;
|
public final Path etc_dir;
|
||||||
public final File lib_dir;
|
public final File lib_dir;
|
||||||
public final Path tmp_dir;
|
public final Path tmp_dir;
|
||||||
public final File logs_dir;
|
public final File logs_dir;
|
||||||
@@ -46,9 +46,9 @@ public final class SitePaths {
|
|||||||
public final Path gerrit_sh;
|
public final Path gerrit_sh;
|
||||||
public final Path gerrit_war;
|
public final Path gerrit_war;
|
||||||
|
|
||||||
public final File gerrit_config;
|
public final Path gerrit_config;
|
||||||
public final File secure_config;
|
public final Path secure_config;
|
||||||
public final File contact_information_pub;
|
public final Path contact_information_pub;
|
||||||
|
|
||||||
public final Path ssl_keystore;
|
public final Path ssl_keystore;
|
||||||
public final Path ssh_key;
|
public final Path ssh_key;
|
||||||
@@ -71,13 +71,13 @@ public final class SitePaths {
|
|||||||
Path p = sitePath;
|
Path p = sitePath;
|
||||||
|
|
||||||
bin_dir = p.resolve("bin");
|
bin_dir = p.resolve("bin");
|
||||||
etc_dir = new File(site_path, "etc");
|
etc_dir = p.resolve("etc");
|
||||||
lib_dir = new File(site_path, "lib");
|
lib_dir = new File(site_path, "lib");
|
||||||
tmp_dir = p.resolve("tmp");
|
tmp_dir = p.resolve("tmp");
|
||||||
plugins_dir = new File(site_path, "plugins");
|
plugins_dir = new File(site_path, "plugins");
|
||||||
data_dir = new File(site_path, "data");
|
data_dir = new File(site_path, "data");
|
||||||
logs_dir = new File(site_path, "logs");
|
logs_dir = new File(site_path, "logs");
|
||||||
mail_dir = new File(etc_dir, "mail");
|
mail_dir = etc_dir.resolve("mail").toFile();
|
||||||
hooks_dir = new File(site_path, "hooks");
|
hooks_dir = new File(site_path, "hooks");
|
||||||
static_dir = new File(site_path, "static");
|
static_dir = new File(site_path, "static");
|
||||||
themes_dir = new File(site_path, "themes");
|
themes_dir = new File(site_path, "themes");
|
||||||
@@ -86,21 +86,20 @@ public final class SitePaths {
|
|||||||
gerrit_sh = bin_dir.resolve("gerrit.sh");
|
gerrit_sh = bin_dir.resolve("gerrit.sh");
|
||||||
gerrit_war = bin_dir.resolve("gerrit.war");
|
gerrit_war = bin_dir.resolve("gerrit.war");
|
||||||
|
|
||||||
gerrit_config = new File(etc_dir, "gerrit.config");
|
gerrit_config = etc_dir.resolve("gerrit.config");
|
||||||
secure_config = new File(etc_dir, "secure.config");
|
secure_config = etc_dir.resolve("secure.config");
|
||||||
contact_information_pub = new File(etc_dir, "contact_information.pub");
|
contact_information_pub = etc_dir.resolve("contact_information.pub");
|
||||||
|
|
||||||
Path etcDirPath = etc_dir.toPath();
|
ssl_keystore = etc_dir.resolve("keystore");
|
||||||
ssl_keystore = etcDirPath.resolve("keystore");
|
ssh_key = etc_dir.resolve("ssh_host_key");
|
||||||
ssh_key = etcDirPath.resolve("ssh_host_key");
|
ssh_rsa = etc_dir.resolve("ssh_host_rsa_key");
|
||||||
ssh_rsa = etcDirPath.resolve("ssh_host_rsa_key");
|
ssh_dsa = etc_dir.resolve("ssh_host_dsa_key");
|
||||||
ssh_dsa = etcDirPath.resolve("ssh_host_dsa_key");
|
peer_keys = etc_dir.resolve("peer_keys");
|
||||||
peer_keys = etcDirPath.resolve("peer_keys");
|
|
||||||
|
|
||||||
site_css = etcDirPath.resolve(CSS_FILENAME);
|
site_css = etc_dir.resolve(CSS_FILENAME);
|
||||||
site_header = etcDirPath.resolve(HEADER_FILENAME);
|
site_header = etc_dir.resolve(HEADER_FILENAME);
|
||||||
site_footer = etcDirPath.resolve(FOOTER_FILENAME);
|
site_footer = etc_dir.resolve(FOOTER_FILENAME);
|
||||||
site_gitweb = etcDirPath.resolve("gitweb_config.perl");
|
site_gitweb = etc_dir.resolve("gitweb_config.perl");
|
||||||
|
|
||||||
if (site_path.exists()) {
|
if (site_path.exists()) {
|
||||||
final String[] contents = site_path.list();
|
final String[] contents = site_path.list();
|
||||||
|
@@ -28,11 +28,12 @@ import org.bouncycastle.openpgp.PGPPublicKey;
|
|||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
import org.eclipse.jgit.util.StringUtils;
|
import org.eclipse.jgit.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
|
|
||||||
/** Creates the {@link ContactStore} based on the configuration. */
|
/** Creates the {@link ContactStore} based on the configuration. */
|
||||||
@@ -46,7 +47,7 @@ public class ContactStoreModule extends AbstractModule {
|
|||||||
public ContactStore provideContactStore(@GerritServerConfig final Config config,
|
public ContactStore provideContactStore(@GerritServerConfig final Config config,
|
||||||
final SitePaths site, final SchemaFactory<ReviewDb> schema,
|
final SitePaths site, final SchemaFactory<ReviewDb> schema,
|
||||||
final ContactStoreConnection.Factory connFactory) {
|
final ContactStoreConnection.Factory connFactory) {
|
||||||
final String url = config.getString("contactstore", null, "url");
|
String url = config.getString("contactstore", null, "url");
|
||||||
if (StringUtils.isEmptyOrNull(url)) {
|
if (StringUtils.isEmptyOrNull(url)) {
|
||||||
return new NoContactStore();
|
return new NoContactStore();
|
||||||
}
|
}
|
||||||
@@ -56,18 +57,18 @@ public class ContactStoreModule extends AbstractModule {
|
|||||||
+ " needed to encrypt contact information");
|
+ " needed to encrypt contact information");
|
||||||
}
|
}
|
||||||
|
|
||||||
final URL storeUrl;
|
URL storeUrl;
|
||||||
try {
|
try {
|
||||||
storeUrl = new URL(url);
|
storeUrl = new URL(url);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
throw new ProvisionException("Invalid contactstore.url: " + url, e);
|
throw new ProvisionException("Invalid contactstore.url: " + url, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String storeAPPSEC = config.getString("contactstore", null, "appsec");
|
String storeAPPSEC = config.getString("contactstore", null, "appsec");
|
||||||
final File pubkey = site.contact_information_pub;
|
Path pubkey = site.contact_information_pub;
|
||||||
if (!pubkey.exists()) {
|
if (!Files.exists(pubkey)) {
|
||||||
throw new ProvisionException("PGP public key file \""
|
throw new ProvisionException("PGP public key file \""
|
||||||
+ pubkey.getAbsolutePath() + "\" not found");
|
+ pubkey.toAbsolutePath() + "\" not found");
|
||||||
}
|
}
|
||||||
return new EncryptedContactStore(storeUrl, storeAPPSEC, pubkey, schema,
|
return new EncryptedContactStore(storeUrl, storeAPPSEC, pubkey, schema,
|
||||||
connFactory);
|
connFactory);
|
||||||
|
@@ -42,12 +42,12 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.NoSuchProviderException;
|
import java.security.NoSuchProviderException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
@@ -72,7 +72,7 @@ class EncryptedContactStore implements ContactStore {
|
|||||||
private final ContactStoreConnection.Factory connFactory;
|
private final ContactStoreConnection.Factory connFactory;
|
||||||
|
|
||||||
EncryptedContactStore(final URL storeUrl, final String storeAPPSEC,
|
EncryptedContactStore(final URL storeUrl, final String storeAPPSEC,
|
||||||
final File pubKey, final SchemaFactory<ReviewDb> schema,
|
final Path pubKey, final SchemaFactory<ReviewDb> schema,
|
||||||
final ContactStoreConnection.Factory connFactory) {
|
final ContactStoreConnection.Factory connFactory) {
|
||||||
this.storeUrl = storeUrl;
|
this.storeUrl = storeUrl;
|
||||||
this.storeAPPSEC = storeAPPSEC;
|
this.storeAPPSEC = storeAPPSEC;
|
||||||
@@ -104,8 +104,8 @@ class EncryptedContactStore implements ContactStore {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PGPPublicKeyRingCollection readPubRing(final File pub) {
|
private static PGPPublicKeyRingCollection readPubRing(Path pub) {
|
||||||
try (InputStream fin = new FileInputStream(pub);
|
try (InputStream fin = Files.newInputStream(pub);
|
||||||
InputStream in = PGPUtil.getDecoderStream(fin)) {
|
InputStream in = PGPUtil.getDecoderStream(fin)) {
|
||||||
return new PGPPublicKeyRingCollection(in);
|
return new PGPPublicKeyRingCollection(in);
|
||||||
} catch (IOException | PGPException e) {
|
} catch (IOException | PGPException e) {
|
||||||
|
@@ -27,6 +27,7 @@ import org.eclipse.jgit.util.FS;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -35,8 +36,8 @@ public class DefaultSecureStore extends SecureStore {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DefaultSecureStore(SitePaths site) {
|
DefaultSecureStore(SitePaths site) {
|
||||||
File secureConfig = new File(site.etc_dir, "secure.config");
|
Path secureConfig = site.etc_dir.resolve("secure.config");
|
||||||
sec = new FileBasedConfig(secureConfig, FS.DETECTED);
|
sec = new FileBasedConfig(secureConfig.toFile(), FS.DETECTED);
|
||||||
try {
|
try {
|
||||||
sec.load();
|
sec.load();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@@ -38,7 +38,7 @@ public class SitePathsTest {
|
|||||||
final SitePaths site = new SitePaths(root);
|
final SitePaths site = new SitePaths(root);
|
||||||
assertTrue(site.isNew);
|
assertTrue(site.isNew);
|
||||||
assertEquals(root.toFile(), site.site_path);
|
assertEquals(root.toFile(), site.site_path);
|
||||||
assertEquals(root.resolve("etc").toFile(), site.etc_dir);
|
assertEquals(root.resolve("etc"), site.etc_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Submodule plugins/replication updated: 3973b31f3c...2266d4e2ec
Reference in New Issue
Block a user