public void setMachineName(String machineName) throws ConfigException { if (machineName == null || !VectorClock.MACHINE_PATTERN.matcher(machineName).matches()) { throw new ConfigException("Machine name cannot be empty and must be only characters (A-Z)."); } this.machineName = machineName; }
/** * Loads the config transfer object from the local directory * or throws an exception if the file does not exist. */ public static ConfigTO loadConfigTO(File localDir) throws ConfigException { File appDir = new File(localDir, Config.DIR_APPLICATION); File configFile = new File(appDir, Config.FILE_CONFIG); if (!configFile.exists()) { throw new ConfigException("Cannot find config file at "+configFile+". Try connecting to a repository using 'connect', or 'init' to create a new one."); } return ConfigTO.load(configFile); }
public void save(File file, List<CipherSpec> cipherSpecs, SaltedSecretKey masterKey) throws ConfigException { try { ByteArrayOutputStream plaintextRepoOutputStream = new ByteArrayOutputStream(); Serializer serializer = new Persister(); serializer.write(this, plaintextRepoOutputStream); CipherUtil.encrypt(new ByteArrayInputStream(plaintextRepoOutputStream.toByteArray()), new FileOutputStream(file), cipherSpecs, masterKey); } catch (Exception e) { throw new ConfigException("Cannot write repoTO (encrypted) to file " + file, e); } }
private static RepoTO loadEncryptedRepoTO(File repoFile, ConfigTO configTO) throws Exception { logger.log(Level.INFO, "Loading encrypted repo file from {0} ...", repoFile); SaltedSecretKey masterKey = configTO.getMasterKey(); if (masterKey == null) { throw new ConfigException("Repo file is encrypted, but master key not set in config file."); } String repoFileStr = new String(CipherUtil.decrypt(new FileInputStream(repoFile), masterKey)); return new Persister().read(RepoTO.class, repoFileStr); } }
public static DaemonConfigTO load(File file) throws ConfigException { try { return new Persister().read(DaemonConfigTO.class, file); } catch (Exception e) { throw new ConfigException("Config file does not exist or is invalid: " + file, e); } }
public void save(File file) throws ConfigException { try { new Persister().write(this, file); } catch (Exception e) { throw new ConfigException("Cannot write masterTO to file " + file, e); } }
/** * Loads the repository transfer object from the local directory. */ public static RepoTO loadRepoTO(File localDir, ConfigTO configTO) throws ConfigException { File appDir = new File(localDir, Config.DIR_APPLICATION); File repoFile = new File(appDir, Config.FILE_REPO); if (!repoFile.exists()) { throw new ConfigException("Cannot find repository file at "+repoFile+". Try connecting to a repository using 'connect', or 'init' to create a new one."); } try { if (CipherUtil.isEncrypted(repoFile)) { return loadEncryptedRepoTO(repoFile, configTO); } else { return loadPlaintextRepoTO(repoFile, configTO); } } catch (Exception e) { throw new ConfigException("Cannot load repo file: "+e.getMessage(), e); } }
public void save(File file) throws ConfigException { try { new Persister().write(this, file); } catch (Exception e) { throw new ConfigException("Config could not be written: " + file, e); } }
public void save(File file) throws ConfigException { try { new Persister().write(this, file); } catch (Exception e) { throw new ConfigException("Cannot write repoTO to file " + file, e); } }
public static ConfigTO load(File file) throws ConfigException { try { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter()); registry.bind(String.class, new EncryptedTransferSettingsConverter()); return new Persister(strategy).read(ConfigTO.class, file); } catch (ClassNotFoundException ex) { // Ugly hack to catch common case of non-existing plugin String message = ex.getMessage(); if (!message.startsWith("org.syncany.plugins.")) { // Apparently there are other ClassNotFoundExceptions possible. throw new ConfigException("Config file does not exist or is invalid: " + file, ex); } message = message.replaceFirst("org.syncany.plugins.", ""); message = message.replaceAll("\\..*", ""); throw new ConfigException("Is the " + message + " plugin installed?"); } catch (Exception ex) { throw new ConfigException("Config file does not exist or is invalid: " + file, ex); } }
private void initMultiChunker(RepoTO repoTO) throws ConfigException { MultiChunkerTO multiChunkerTO = repoTO.getMultiChunker(); if (multiChunkerTO == null) { throw new ConfigException("No multichunker in repository config."); } multiChunker = MultiChunker.getInstance(multiChunkerTO.getType()); if (multiChunker == null) { throw new ConfigException("Invalid multichunk type or settings: " + multiChunkerTO.getType()); } multiChunker.init(multiChunkerTO.getSettings()); }
private void initConnection(ConfigTO configTO) throws ConfigException { if (configTO.getTransferSettings() != null) { plugin = Plugins.get(configTO.getTransferSettings().getType(), TransferPlugin.class); if (plugin == null) { throw new ConfigException("Plugin not supported: " + configTO.getTransferSettings().getType()); } try { transferSettings = configTO.getTransferSettings(); } catch (Exception e) { throw new ConfigException("Cannot initialize storage: " + e.getMessage(), e); } } }
throw new ConfigException("Argument localDir cannot be null."); throw new ConfigException("Plugin with id '" + pluginId + "' does not exist. Try 'sy plugin install " + pluginId + "'.");
private void initRepo(RepoTO repoTO) throws ConfigException { try { initRepoId(repoTO); initChunker(repoTO); initMultiChunker(repoTO); initTransformers(repoTO); } catch (Exception e) { throw new ConfigException("Unable to initialize repository information from config.", e); } }
public static UserConfigTO load(File file) throws ConfigException { try { return new Persister(new AnnotationStrategy()).read(UserConfigTO.class, file); } catch (Exception e) { throw new ConfigException("User config file cannot be read or is invalid: " + file, e); } }
public void save(File file) throws ConfigException { try { new Persister(new AnnotationStrategy()).write(this, file); } catch (Exception e) { throw new ConfigException("Cannot write user config to file " + file, e); } } }
public void save(File file) throws ConfigException { try { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter()); registry.bind(String.class, new EncryptedTransferSettingsConverter(transferSettings.getClass())); new Persister(strategy).write(this, file); } catch (Exception e) { throw new ConfigException("Cannot write config to file " + file, e); } }
public Config(File aLocalDir, ConfigTO configTO, RepoTO repoTO) throws ConfigException { if (aLocalDir == null || configTO == null || repoTO == null) { throw new ConfigException("Arguments aLocalDir, configTO and repoTO cannot be null."); } initNames(configTO); initMasterKey(configTO); initDirectories(aLocalDir); initCache(configTO); initIgnoredFile(); initRepo(repoTO); initConnection(configTO); }
private void initTransformers(RepoTO repoTO) throws Exception { if (repoTO.getTransformers() == null || repoTO.getTransformers().size() == 0) { transformer = new NoTransformer(); } else { List<TransformerTO> transformerTOs = new ArrayList<TransformerTO>(repoTO.getTransformers()); Transformer lastTransformer = null; for (int i = transformerTOs.size() - 1; i >= 0; i--) { TransformerTO transformerTO = transformerTOs.get(i); Transformer transformer = Transformer.getInstance(transformerTO.getType()); if (transformer == null) { throw new ConfigException("Cannot find transformer '" + transformerTO.getType() + "'"); } if (transformer instanceof CipherTransformer) { // Dirty workaround transformerTO.getSettings().put(CipherTransformer.PROPERTY_MASTER_KEY, StringUtil.toHex(getMasterKey().getEncoded())); transformerTO.getSettings().put(CipherTransformer.PROPERTY_MASTER_KEY_SALT, StringUtil.toHex(getMasterKey().getSalt())); } transformer.init(transformerTO.getSettings()); if (lastTransformer != null) { transformer.setNextTransformer(lastTransformer); } lastTransformer = transformer; } transformer = lastTransformer; } }