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; }
private static void loadAndInitUserConfigFile(File userConfigFile) { try { UserConfigTO userConfigTO = UserConfigTO.load(userConfigFile); // System properties for (Map.Entry<String, String> systemProperty : userConfigTO.getSystemProperties().entrySet()) { String propertyValue = (systemProperty.getValue() != null) ? systemProperty.getValue() : ""; System.setProperty(systemProperty.getKey(), propertyValue); } // Other options preventStandby = userConfigTO.isPreventStandby(); configEncryptionKey = userConfigTO.getConfigEncryptionKey(); } catch (ConfigException e) { System.err.println("ERROR: " + e.getMessage()); System.err.println(" Ignoring user config file!"); System.err.println(); } }
/** * 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); }
private static void writeExampleUserConfigFile(File userConfigFile) { UserConfigTO userConfigTO = new UserConfigTO(); try { System.out.println("First launch, creating a secret key (could take a sec)..."); SaltedSecretKey configEncryptionKey = CipherUtil.createMasterKey(CipherUtil.createRandomAlphabeticString(USER_CONFIG_ENCRYPTION_KEY_LENGTH)); userConfigTO.setConfigEncryptionKey(configEncryptionKey); userConfigTO.save(userConfigFile); } catch (CipherException e) { System.err.println("ERROR: " + e.getMessage()); System.err.println(" Failed to create masterkey."); System.err.println(); } catch (ConfigException e) { System.err.println("ERROR: " + e.getMessage()); System.err.println(" Failed to save to file."); System.err.println(); } }
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); } }
@Subscribe public void onAddWatchRequestReceived(AddWatchManagementRequest request) { File rootFolder = request.getWatch(); if (watchOperations.containsKey(rootFolder)) { eventBus.post(new AddWatchManagementResponse(AddWatchManagementResponse.ERR_ALREADY_EXISTS, request.getId(), "Watch already exists.")); } else { try { boolean folderAdded = DaemonConfigHelper.addFolder(rootFolder); if (folderAdded) { eventBus.post(new AddWatchManagementResponse(AddWatchManagementResponse.OKAY, request.getId(), "Successfully added.")); } else { eventBus.post(new AddWatchManagementResponse(AddWatchManagementResponse.ERR_ALREADY_EXISTS, request.getId(), "Watch already exists (inactive/disabled).")); } } catch (ConfigException e) { logger.log(Level.WARNING, "Error adding watch to daemon config.", e); eventBus.post(new AddWatchManagementResponse(AddWatchManagementResponse.ERR_OTHER, request.getId(), "Error adding to config: " + e.getMessage())); } } }
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); } }
@Subscribe public void onRemoveWatchRequestReceived(RemoveWatchManagementRequest request) { File rootFolder = request.getWatch(); if (!watchOperations.containsKey(rootFolder)) { eventBus.post(new RemoveWatchManagementResponse(RemoveWatchManagementResponse.ERR_DOES_NOT_EXIST, request.getId(), "Watch does not exist.")); } else { try { boolean folderRemoved = DaemonConfigHelper.removeFolder(rootFolder); if (folderRemoved) { eventBus.post(new RemoveWatchManagementResponse(RemoveWatchManagementResponse.OKAY, request.getId(), "Successfully removed.")); } else { eventBus.post(new RemoveWatchManagementResponse(RemoveWatchManagementResponse.ERR_DOES_NOT_EXIST, request.getId(), "Watch does not exist (inactive/disabled).")); } } catch (ConfigException e) { logger.log(Level.WARNING, "Error removing watch from daemon config.", e); eventBus.post(new RemoveWatchManagementResponse(RemoveWatchManagementResponse.ERR_OTHER, request.getId(), "Error removing to config: " + e.getMessage())); } } } }
/** * 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 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); } }
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); } } }