@Override protected Optional<String> loadSetting(SystemSetting setting) { // CHECKSTYLE:OFF - Customers should be able to specify a credentials provider that only looks at the system properties, // but not the environment variables. For that reason, we're only checking the system properties here. return Optional.ofNullable(System.getProperty(setting.property())); // CHECKSTYLE:ON }
/** * Attempt to load this setting from the system properties. */ private static Optional<String> resolveProperty(SystemSetting setting) { // CHECKSTYLE:OFF - This is the only place we're allowed to use System.getProperty return Optional.ofNullable(setting.property()).map(System::getProperty); // CHECKSTYLE:ON }
/** * Attempt to load this setting from the system properties. */ private static Optional<String> resolveProperty(SystemSetting setting) { // CHECKSTYLE:OFF - This is the only place we're allowed to use System.getProperty return Optional.ofNullable(setting.property()).map(System::getProperty); // 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 system properties, // but not the environment variables. For that reason, we're only checking the system properties here. return Optional.ofNullable(System.getProperty(setting.property())); // CHECKSTYLE:ON }
/** * 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'"); } }
/** * 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'"); } }
@Override public Optional<T> loadService() { Iterator<T> httpServices = serviceLoader.loadServices(serviceClass); if (!httpServices.hasNext()) { return Optional.empty(); } T httpService = httpServices.next(); if (httpServices.hasNext()) { throw SdkClientException.builder().message( String.format( "Multiple HTTP implementations were found on the classpath. To avoid non-deterministic loading " + "implementations, please explicitly provide an HTTP client via the client builders, set the %s " + "system property with the FQCN of the HTTP service to use as the default, or remove all but one " + "HTTP implementation from the classpath", implSystemProperty.property())) .build(); } return Optional.of(httpService); }
/** * 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.")); }