@Override protected Optional<String> loadSetting(SystemSetting setting) { // CHECKSTYLE:OFF - Customers should be able to specify a credentials provider that only looks at the environment // variables, but not the system properties. For that reason, we're only checking the environment variable here. return Optional.ofNullable(System.getenv(setting.environmentVariable())); // CHECKSTYLE:ON }
@Override protected Optional<String> loadSetting(SystemSetting setting) { // CHECKSTYLE:OFF - Customers should be able to specify a credentials provider that only looks at the environment // variables, but not the system properties. For that reason, we're only checking the environment variable here. return Optional.ofNullable(System.getenv(setting.environmentVariable())); // CHECKSTYLE:ON }
/** * Attempt to load this setting from the environment variables. */ private static Optional<String> resolveEnvironmentVariable(SystemSetting setting) { try { // CHECKSTYLE:OFF - This is the only place we're allowed to use System.getenv return Optional.ofNullable(setting.environmentVariable()).map(System::getenv); // CHECKSTYLE:ON } catch (SecurityException e) { LOG.debug("Unable to load the environment variable '{}' because the security manager did not allow the SDK" + " to read this system property. This setting will be assumed to be null", setting.environmentVariable(), e); return Optional.empty(); } }
/** * Attempt to load this setting from the environment variables. */ private static Optional<String> resolveEnvironmentVariable(SystemSetting setting) { try { // CHECKSTYLE:OFF - This is the only place we're allowed to use System.getenv return Optional.ofNullable(setting.environmentVariable()).map(System::getenv); // CHECKSTYLE:ON } catch (SecurityException e) { LOG.debug("Unable to load the environment variable '{}' because the security manager did not allow the SDK" + " to read this system property. This setting will be assumed to be null", setting.environmentVariable(), e); return Optional.empty(); } }
public void set(SystemSetting setting, String value) { set(setting.environmentVariable(), value); }
/** * Convert a string to boolean safely (as opposed to the less strict {@link Boolean#parseBoolean(String)}). If a customer * specifies a boolean value it should be "true" or "false" (case insensitive) or an exception will be thrown. */ public static Boolean safeStringToBoolean(SystemSetting setting, String value) { if (value.equalsIgnoreCase("true")) { return true; } else if (value.equalsIgnoreCase("false")) { return false; } throw new IllegalStateException("Environment variable '" + setting.environmentVariable() + "' or system property '" + setting.property() + "' was defined as '" + value + "', but should be 'false' or 'true'"); } }
public void remove(SystemSetting setting) { remove(setting.environmentVariable()); }
public void set(SystemSetting setting, String value) { set(setting.environmentVariable(), value); }
public void remove(SystemSetting setting) { remove(setting.environmentVariable()); }
/** * Convert a string to boolean safely (as opposed to the less strict {@link Boolean#parseBoolean(String)}). If a customer * specifies a boolean value it should be "true" or "false" (case insensitive) or an exception will be thrown. */ public static Boolean safeStringToBoolean(SystemSetting setting, String value) { if (value.equalsIgnoreCase("true")) { return true; } else if (value.equalsIgnoreCase("false")) { return false; } throw new IllegalStateException("Environment variable '" + setting.environmentVariable() + "' or system property '" + setting.property() + "' was defined as '" + value + "', but should be 'false' or 'true'"); } }
/** * Load the requested system setting as per the documentation in {@link #getStringValue()}, throwing an exception if the value * was not set and had no default. * * @return The requested setting. */ default String getStringValueOrThrow() { return getStringValue().orElseThrow(() -> new IllegalStateException("Either the environment variable " + environmentVariable() + " or the java" + "property " + property() + " must be set.")); }
/** * Load the requested system setting as per the documentation in {@link #getBooleanValue()}, throwing an * exception if the value was not set and had no default. * * @return The requested setting. */ default Boolean getBooleanValueOrThrow() { return getBooleanValue().orElseThrow(() -> new IllegalStateException("Either the environment variable " + environmentVariable() + " or the java" + "property " + property() + " must be set.")); } }
/** * Load the requested system setting as per the documentation in {@link #getBooleanValue()}, throwing an * exception if the value was not set and had no default. * * @return The requested setting. */ default Boolean getBooleanValueOrThrow() { return getBooleanValue().orElseThrow(() -> new IllegalStateException("Either the environment variable " + environmentVariable() + " or the java" + "property " + property() + " must be set.")); } }
/** * Load the requested system setting as per the documentation in {@link #getStringValue()}, throwing an exception if the value * was not set and had no default. * * @return The requested setting. */ default String getStringValueOrThrow() { return getStringValue().orElseThrow(() -> new IllegalStateException("Either the environment variable " + environmentVariable() + " or the java" + "property " + property() + " must be set.")); }