1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.utils; 17 18 import static software.amazon.awssdk.utils.internal.SystemSettingUtils.resolveEnvironmentVariable; 19 20 import java.util.Locale; 21 import java.util.Optional; 22 import software.amazon.awssdk.annotations.SdkProtectedApi; 23 24 /** 25 * An enumeration representing environment settings related to proxy configuration. Instances of this enum are used to 26 * define and access proxy configuration settings obtained from environment variables. 27 */ 28 @SdkProtectedApi 29 public enum ProxyEnvironmentSetting implements SystemSetting { 30 31 HTTP_PROXY("http_proxy"), 32 HTTPS_PROXY("https_proxy"), 33 NO_PROXY("no_proxy") 34 ; 35 36 private final String environmentVariable; 37 ProxyEnvironmentSetting(String environmentVariable)38 ProxyEnvironmentSetting(String environmentVariable) { 39 this.environmentVariable = environmentVariable; 40 } 41 42 @Override getStringValue()43 public Optional<String> getStringValue() { 44 Optional<String> envVarLowercase = resolveEnvironmentVariable(environmentVariable); 45 if (envVarLowercase.isPresent()) { 46 return getValueIfValid(envVarLowercase.get()); 47 } 48 49 Optional<String> envVarUppercase = resolveEnvironmentVariable(environmentVariable.toUpperCase(Locale.getDefault())); 50 if (envVarUppercase.isPresent()) { 51 return getValueIfValid(envVarUppercase.get()); 52 } 53 return Optional.empty(); 54 } 55 56 @Override property()57 public String property() { 58 return null; 59 } 60 61 @Override environmentVariable()62 public String environmentVariable() { 63 return environmentVariable; 64 } 65 66 @Override defaultValue()67 public String defaultValue() { 68 return null; 69 } 70 getValueIfValid(String value)71 private Optional<String> getValueIfValid(String value) { 72 String trimmedValue = value.trim(); 73 if (!trimmedValue.isEmpty()) { 74 return Optional.of(trimmedValue); 75 } 76 return Optional.empty(); 77 } 78 79 }