|
| 1 | +package software.amazon.awssdk.services.json.internal; |
| 2 | + |
| 3 | +import java.net.URI; |
| 4 | +import java.util.Collections; |
| 5 | +import java.util.HashMap; |
| 6 | +import java.util.Map; |
| 7 | +import software.amazon.awssdk.annotations.Generated; |
| 8 | +import software.amazon.awssdk.annotations.SdkInternalApi; |
| 9 | +import software.amazon.awssdk.awscore.client.config.AwsClientOption; |
| 10 | +import software.amazon.awssdk.core.ClientEndpointProvider; |
| 11 | +import software.amazon.awssdk.core.checksums.RequestChecksumCalculation; |
| 12 | +import software.amazon.awssdk.core.checksums.ResponseChecksumValidation; |
| 13 | +import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; |
| 14 | +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; |
| 15 | +import software.amazon.awssdk.core.client.config.SdkClientOption; |
| 16 | +import software.amazon.awssdk.endpoints.EndpointProvider; |
| 17 | +import software.amazon.awssdk.http.auth.spi.scheme.AuthScheme; |
| 18 | +import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeProvider; |
| 19 | +import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; |
| 20 | +import software.amazon.awssdk.identity.spi.IdentityProvider; |
| 21 | +import software.amazon.awssdk.regions.Region; |
| 22 | +import software.amazon.awssdk.services.json.JsonServiceClientConfiguration; |
| 23 | +import software.amazon.awssdk.services.json.auth.scheme.JsonAuthSchemeProvider; |
| 24 | +import software.amazon.awssdk.utils.Validate; |
| 25 | + |
| 26 | +@Generated("software.amazon.awssdk:codegen") |
| 27 | +@SdkInternalApi |
| 28 | +public class JsonServiceClientConfigurationBuilder implements JsonServiceClientConfiguration.Builder { |
| 29 | + private final SdkClientConfiguration.Builder config; |
| 30 | + |
| 31 | + public JsonServiceClientConfigurationBuilder() { |
| 32 | + this(SdkClientConfiguration.builder()); |
| 33 | + } |
| 34 | + |
| 35 | + public JsonServiceClientConfigurationBuilder(SdkClientConfiguration.Builder config) { |
| 36 | + this.config = config; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Sets the value for client override configuration |
| 41 | + */ |
| 42 | + @Override |
| 43 | + public JsonServiceClientConfiguration.Builder overrideConfiguration(ClientOverrideConfiguration overrideConfiguration) { |
| 44 | + config.putAll(overrideConfiguration); |
| 45 | + return this; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Gets the value for client override configuration |
| 50 | + */ |
| 51 | + @Override |
| 52 | + public ClientOverrideConfiguration overrideConfiguration() { |
| 53 | + return config.asOverrideConfigurationBuilder().build(); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Sets the value for endpoint override |
| 58 | + */ |
| 59 | + @Override |
| 60 | + public JsonServiceClientConfiguration.Builder endpointOverride(URI endpointOverride) { |
| 61 | + if (endpointOverride != null) { |
| 62 | + config.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER, ClientEndpointProvider.forEndpointOverride(endpointOverride)); |
| 63 | + } else { |
| 64 | + config.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER, null); |
| 65 | + } |
| 66 | + return this; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Gets the value for endpoint override |
| 71 | + */ |
| 72 | + @Override |
| 73 | + public URI endpointOverride() { |
| 74 | + ClientEndpointProvider clientEndpoint = config.option(SdkClientOption.CLIENT_ENDPOINT_PROVIDER); |
| 75 | + if (clientEndpoint != null && clientEndpoint.isEndpointOverridden()) { |
| 76 | + return clientEndpoint.clientEndpoint(); |
| 77 | + } |
| 78 | + return null; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Sets the value for endpoint provider |
| 83 | + */ |
| 84 | + @Override |
| 85 | + public JsonServiceClientConfiguration.Builder endpointProvider(EndpointProvider endpointProvider) { |
| 86 | + config.option(SdkClientOption.ENDPOINT_PROVIDER, endpointProvider); |
| 87 | + return this; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Gets the value for endpoint provider |
| 92 | + */ |
| 93 | + @Override |
| 94 | + public EndpointProvider endpointProvider() { |
| 95 | + return config.option(SdkClientOption.ENDPOINT_PROVIDER); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Sets the value for AWS region |
| 100 | + */ |
| 101 | + @Override |
| 102 | + public JsonServiceClientConfiguration.Builder region(Region region) { |
| 103 | + config.option(AwsClientOption.AWS_REGION, region); |
| 104 | + return this; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Gets the value for AWS region |
| 109 | + */ |
| 110 | + @Override |
| 111 | + public Region region() { |
| 112 | + return config.option(AwsClientOption.AWS_REGION); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Sets the value for credentials provider |
| 117 | + */ |
| 118 | + @Override |
| 119 | + public JsonServiceClientConfiguration.Builder credentialsProvider( |
| 120 | + IdentityProvider<? extends AwsCredentialsIdentity> credentialsProvider) { |
| 121 | + config.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER, credentialsProvider); |
| 122 | + return this; |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Gets the value for credentials provider |
| 127 | + */ |
| 128 | + @Override |
| 129 | + public IdentityProvider<? extends AwsCredentialsIdentity> credentialsProvider() { |
| 130 | + return config.option(AwsClientOption.CREDENTIALS_IDENTITY_PROVIDER); |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public JsonServiceClientConfiguration.Builder putAuthScheme(AuthScheme<?> authScheme) { |
| 135 | + config.computeOptionIfAbsent(SdkClientOption.AUTH_SCHEMES, HashMap::new).put(authScheme.schemeId(), authScheme); |
| 136 | + return this; |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * Gets the value for auth schemes |
| 141 | + */ |
| 142 | + @Override |
| 143 | + public Map<String, AuthScheme<?>> authSchemes() { |
| 144 | + Map<String, AuthScheme<?>> authSchemes = config.option(SdkClientOption.AUTH_SCHEMES); |
| 145 | + return Collections.unmodifiableMap(authSchemes == null ? Collections.emptyMap() : authSchemes); |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Sets the value for auth scheme provider |
| 150 | + */ |
| 151 | + @Override |
| 152 | + public JsonServiceClientConfiguration.Builder authSchemeProvider(JsonAuthSchemeProvider authSchemeProvider) { |
| 153 | + config.option(SdkClientOption.AUTH_SCHEME_PROVIDER, authSchemeProvider); |
| 154 | + return this; |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Gets the value for auth scheme provider |
| 159 | + */ |
| 160 | + @Override |
| 161 | + public JsonAuthSchemeProvider authSchemeProvider() { |
| 162 | + AuthSchemeProvider result = config.option(SdkClientOption.AUTH_SCHEME_PROVIDER); |
| 163 | + if (result == null) { |
| 164 | + return null; |
| 165 | + } |
| 166 | + return Validate.isInstanceOf(JsonAuthSchemeProvider.class, result, "Expected an instance of " |
| 167 | + + JsonAuthSchemeProvider.class.getSimpleName()); |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Sets the value for client behavior for response checksum validation |
| 172 | + */ |
| 173 | + @Override |
| 174 | + public JsonServiceClientConfiguration.Builder responseChecksumValidation(ResponseChecksumValidation responseChecksumValidation) { |
| 175 | + config.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION, responseChecksumValidation); |
| 176 | + return this; |
| 177 | + } |
| 178 | + |
| 179 | + /** |
| 180 | + * Gets the value for client behavior for response checksum validation |
| 181 | + */ |
| 182 | + @Override |
| 183 | + public ResponseChecksumValidation responseChecksumValidation() { |
| 184 | + return config.option(SdkClientOption.RESPONSE_CHECKSUM_VALIDATION); |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * Sets the value for client behavior for request checksum calculation |
| 189 | + */ |
| 190 | + @Override |
| 191 | + public JsonServiceClientConfiguration.Builder requestChecksumCalculation(RequestChecksumCalculation requestChecksumCalculation) { |
| 192 | + config.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION, requestChecksumCalculation); |
| 193 | + return this; |
| 194 | + } |
| 195 | + |
| 196 | + /** |
| 197 | + * Gets the value for client behavior for request checksum calculation |
| 198 | + */ |
| 199 | + @Override |
| 200 | + public RequestChecksumCalculation requestChecksumCalculation() { |
| 201 | + return config.option(SdkClientOption.REQUEST_CHECKSUM_CALCULATION); |
| 202 | + } |
| 203 | + |
| 204 | + @Override |
| 205 | + public JsonServiceClientConfiguration build() { |
| 206 | + return new JsonServiceClientConfiguration(this); |
| 207 | + } |
| 208 | +} |
0 commit comments