Java Code Examples for com.typesafe.config.ConfigException#Missing

The following examples show how to use com.typesafe.config.ConfigException#Missing . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyUserValidation.java    From gcp-token-broker with Apache License 2.0 6 votes vote down vote up
private static boolean isWhitelistedByUsername(Config proxyConfig, String impersonated) {
    // Check if user is whitelisted directly by name
    List<String> proxyableUsers;
    try {
        proxyableUsers = proxyConfig.getStringList(CONFIG_USERS);
    } catch (ConfigException.Missing e) {
        // No users setting specified
        return false;
    }

    if (proxyableUsers.contains("*")) {
        // Any users can be impersonated
        return true;
    }

    return proxyableUsers.contains(impersonated);
}
 
Example 2
Source File: SecretManager.java    From gcp-token-broker with Apache License 2.0 6 votes vote down vote up
/**
 * Download all secrets specified in the settings.
 */
public static void downloadSecrets() {
    List<? extends Config> downloads = AppSettings.getInstance().getConfigList(AppSettings.SECRET_MANAGER_DOWNLOADS);
    if (downloads.size() > 0) {
        // Download all secrets specified in the settings
        for (Config download : downloads) {
            boolean required;
            try {
                required = download.getBoolean("required");
            }
            catch (ConfigException.Missing e) {
                required = true;
            }
            downloadSecret(download.getString("secret"), download.getString("file"), required);
        }
    }
}
 
Example 3
Source File: PersistentStoreRegistry.java    From Bats with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public PersistentStoreProvider newPStoreProvider() throws ExecutionSetupException {
  try {
    String storeProviderClassName = config.getString(ExecConstants.SYS_STORE_PROVIDER_CLASS);
    logger.info("Using the configured PStoreProvider class: '{}'.", storeProviderClassName);
    Class<? extends PersistentStoreProvider> storeProviderClass = (Class<? extends PersistentStoreProvider>) Class.forName(storeProviderClassName);
    Constructor<? extends PersistentStoreProvider> c = storeProviderClass.getConstructor(PersistentStoreRegistry.class);
    return new CachingPersistentStoreProvider(c.newInstance(this));
  } catch (ConfigException.Missing | ClassNotFoundException | NoSuchMethodException | SecurityException
      | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
    logger.error(e.getMessage(), e);
    throw new ExecutionSetupException("A System Table provider was either not specified or could not be found or instantiated", e);
  }
}
 
Example 4
Source File: R2ClientFactory.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private Client createD2Client(Config config) {
  String zkhosts = config.getString(ZOOKEEPER_HOSTS);
  if (zkhosts == null || zkhosts.length() == 0) {
    throw new ConfigException.Missing(ZOOKEEPER_HOSTS);
  }

  D2ClientBuilder d2Builder = new D2ClientBuilder().setZkHosts(zkhosts);

  boolean isSSLEnabled = config.getBoolean(SSL_ENABLED);
  if (isSSLEnabled) {
    d2Builder.setIsSSLEnabled(true);
    SSLContext sslContext = SSLContextFactory.createInstance(config);
    d2Builder.setSSLContext(sslContext);
    d2Builder.setSSLParameters(sslContext.getDefaultSSLParameters());
  }

  if (config.hasPath(CLIENT_SERVICES_CONFIG)) {
    Config clientServiceConfig = config.getConfig(CLIENT_SERVICES_CONFIG);
    Map<String, Map<String, Object>> result = new HashMap<>();
    for (String key: clientServiceConfig.root().keySet()) {
      Config value = clientServiceConfig.getConfig(key);
      result.put(key, toMap(value));
    }
    d2Builder.setClientServicesConfig(result);
  }

  return new D2ClientProxy(d2Builder, isSSLEnabled);
}
 
Example 5
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<? extends Config> getConfigList(final String path) {
    try {
        return config.getConfigList(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get List of Configs for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 6
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object getAnyRef(final String path) {
    try {
        return config.getAnyRef(path);
    } catch (final ConfigException.Missing e) {
        final String msgPattern = "Failed to get the unwrapped Java object for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 7
Source File: WaveServerModule.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Inject
WaveServerModule(Config config,
    @WaveletLoadExecutor Executor waveletLoadExecutor,
    @StorageContinuationExecutor Executor storageContinuationExecutor) {
  this.enableFederation = config.getBoolean("federation.enable_federation");
  int deltaCountForPersistSnapshots = 250;
  try {
    deltaCountForPersistSnapshots = config.getInt("core.persist_snapshots_on_deltas_count");
  } catch (ConfigException.Missing e) {
    e.printStackTrace();
  }
  this.persistSnapshotOnDeltasCount = deltaCountForPersistSnapshots;
  this.waveletLoadExecutor = waveletLoadExecutor;
  this.storageContinuationExecutor = storageContinuationExecutor;
}
 
Example 8
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<Number> getNumberList(final String path) {
    try {
        return config.getNumberList(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get List of Numbers for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 9
Source File: BuildMojo.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private String get(final String override, final Config config, final String path)
    throws MojoExecutionException {
  if (override != null) {
    return override;
  }
  try {
    return expand(config.getString(path));
  } catch (ConfigException.Missing e) {
    return null;
  }
}
 
Example 10
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ConfigList getList(final String path) {
    try {
        return config.getList(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get ConfigList for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 11
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Duration getDuration(final String path) {
    try {
        return config.getDuration(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get Duration value for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 12
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public long getLong(final String path) {
    try {
        return tryToGetLongValue(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType | NumberFormatException e) {
        final String msgPattern = "Failed to get long value for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 13
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public int getInt(final String path) {
    try {
        return tryToGetIntValue(path);
    } catch(final ConfigException.Missing | ConfigException.WrongType | NumberFormatException e) {
        final String msgPattern = "Failed to get int value for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 14
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Number getNumber(final String path) {
    try {
        return config.getNumber(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get Number for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 15
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean getBoolean(final String path) {
    try {
        return config.getBoolean(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get boolean value for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 16
Source File: ConsoleOutputProvider.java    From plog with Apache License 2.0 5 votes vote down vote up
@Override
public Handler getHandler(Config config) throws Exception {
    PrintStream target = System.out;
    try {
        final String targetDescription = config.getString("target");
        if (targetDescription.toLowerCase().equals("stderr")) {
            target = System.err;
        }
    } catch (ConfigException.Missing ignored) {
    }

    return new ConsoleOutputHandler(target);
}
 
Example 17
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private static Config tryToGetAsConfig(final Config originalConfig, final String configPath) {
    try {
        return originalConfig.getConfig(configPath);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get nested Config at <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, configPath), e);
    }
}
 
Example 18
Source File: DefaultScopedConfig.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<Long> getBytesList(final String path) {
    try {
        return config.getBytesList(path);
    } catch (final ConfigException.Missing | ConfigException.WrongType e) {
        final String msgPattern = "Failed to get List of byte sizes for path <{0}>!";
        throw new DittoConfigError(MessageFormat.format(msgPattern, appendToConfigPath(path)), e);
    }
}
 
Example 19
Source File: R2ClientFactory.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
/**
 * Given a {@link Config}, create an instance of {@link Client}
 *
 * <p>
 *   A sample configuration for https based client is:
 *   <br> ssl=true
 *   <br> keyStoreFilePath=/path/to/key/store
 *   <br> keyStorePassword=password
 *   <br> keyStoreType=PKCS12
 *   <br> trustStoreFilePath=/path/to/trust/store
 *   <br> trustStorePassword=password
 *
 *   <p>
 *     Http configurations(see {@link HttpClientFactory}) like http.responseMaxSize, http.idleTimeout, etc, can
 *     be set as:
 *     <br> properties.http.responseMaxSize=10000
 *     <br> properties.http.idleTimeout=3000
 *   </p>
 * </p>
 *
 * <p>
 *   A sample configuration for a secured d2 client is:
 *   <br> d2.zkHosts=zk1.host.com:12000
 *   <br> d2.ssl=true
 *   <br> d2.keyStoreFilePath=/path/to/key/store
 *   <br> d2.keyStorePassword=password
 *   <br> d2.keyStoreType=PKCS12
 *   <br> d2.trustStoreFilePath=/path/to/trust/store
 *   <br> d2.trustStorePassword=password
 *
 *   <p>
 *     Http configurations(see {@link HttpClientFactory}) like http.responseMaxSize, http.idleTimeout, etc, can
 *     be set as:
 *     <br> d2.clientServicesConfig.[client_name].http.responseMaxSize=10000
 *     <br> d2.clientServicesConfig.[client_name].http.idleTimeout=3000
 *   </p>
 * </p>
 *
 * @param srcConfig configuration
 * @return an instance of {@link Client}
 */
public Client createInstance(Config srcConfig) {
  Config config = srcConfig.withFallback(FALLBACK);
  switch (schema) {
    case HTTP:
      return createHttpClient(config);
    case D2:
      String confPrefix = schema.name().toLowerCase();
      if (config.hasPath(confPrefix)) {
        Config d2Config = config.getConfig(confPrefix);
        return createD2Client(d2Config);
      } else {
        throw new ConfigException.Missing(confPrefix);
      }
    default:
      throw new RuntimeException("Schema not supported: " + schema.name());
  }
}
 
Example 20
Source File: SimpleHoconConfigTest.java    From kite with Apache License 2.0 4 votes vote down vote up
@Test
	@Ignore
	public void testBasic() {
		Config conf = ConfigFactory.load("test-application").getConfig(getClass().getPackage().getName() + ".test");
		
    assertEquals(conf.getString("foo.bar"), "1234");
    assertEquals(conf.getInt("foo.bar"), 1234);
		//assertEquals(conf.getInt("moo.bar"), 56789); // read from reference.config
		
		Config subConfig = conf.getConfig("foo");
    assertNotNull(subConfig);
    assertEquals(subConfig.getString("bar"), "1234");
    
    assertFalse(conf.hasPath("missing.foox.barx"));
    try {
      conf.getString("missing.foox.barx");
      fail("Failed to detect missing param");
    } catch (ConfigException.Missing e) {} 

    Iterator userNames = Arrays.asList("nadja", "basti").iterator();
		Iterator passwords = Arrays.asList("nchangeit", "bchangeit").iterator();
		for (Config user : conf.getConfigList("users")) {
			assertEquals(user.getString("userName"), userNames.next());
			assertEquals(user.getString("password"), passwords.next());
		}
		assertFalse(userNames.hasNext());
		assertFalse(passwords.hasNext());
		
		assertEquals(conf.getStringList("files.paths"), Arrays.asList("dir/file1.log", "dir/file2.txt"));
		Iterator schemas = Arrays.asList("schema1.json", "schema2.json").iterator();
		Iterator globs = Arrays.asList("*.log*", "*.txt*").iterator();
		for (Config fileMapping : conf.getConfigList("files.fileMappings")) {
			assertEquals(fileMapping.getString("schema"), schemas.next());
			assertEquals(fileMapping.getString("glob"), globs.next());
		}
		assertFalse(schemas.hasNext());
		assertFalse(globs.hasNext());    
				
//		Object list2 = conf.entrySet();
//		Object list2 = conf.getAnyRef("users.userName");
//		assertEquals(conf.getString("users.user.userName"), "nadja");
	}