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.services.rds; 17 18 import java.util.function.Consumer; 19 import software.amazon.awssdk.annotations.SdkPublicApi; 20 import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; 21 import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity; 22 import software.amazon.awssdk.identity.spi.IdentityProvider; 23 import software.amazon.awssdk.regions.Region; 24 import software.amazon.awssdk.services.rds.model.GenerateAuthenticationTokenRequest; 25 26 /** 27 * Utilities for working with RDS. An instance of this class can be created by: 28 * <p> 29 * 1) Using the low-level client {@link RdsClient#utilities()} (or {@link RdsAsyncClient#utilities()}} method. This is 30 * recommended as SDK will use the same configuration from the {@link RdsClient} object to create the {@link RdsUtilities} object. 31 * 32 * <pre> 33 * RdsClient rdsClient = RdsClient.create(); 34 * RdsUtilities utilities = rdsClient.utilities(); 35 * </pre> 36 * </p> 37 * 38 * <p> 39 * 2) Directly using the {@link #builder()} method. 40 * 41 * <pre> 42 * RdsUtilities utilities = RdsUtilities.builder() 43 * .credentialsProvider(DefaultCredentialsProvider.create()) 44 * .region(Region.US_WEST_2) 45 * .build() 46 * </pre> 47 * </p> 48 * 49 * Note: This class does not make network calls. 50 */ 51 @SdkPublicApi 52 public interface RdsUtilities { 53 /** 54 * Create a builder that can be used to configure and create a {@link RdsUtilities}. 55 */ builder()56 static Builder builder() { 57 return new DefaultRdsUtilities.DefaultBuilder(); 58 } 59 60 /** 61 * Generates an authorization tokens for IAM authentication to an RDS database. 62 * 63 * @param request The request used to generate the auth token 64 * @return String to use as the RDS auth token 65 * @throws IllegalArgumentException if the required parameters are not valid 66 */ generateAuthenticationToken(Consumer<GenerateAuthenticationTokenRequest.Builder> request)67 default String generateAuthenticationToken(Consumer<GenerateAuthenticationTokenRequest.Builder> request) { 68 return generateAuthenticationToken(GenerateAuthenticationTokenRequest.builder().applyMutation(request).build()); 69 } 70 71 /** 72 * Generates an authorization tokens for IAM authentication to an RDS database. 73 * 74 * @param request The request used to generate the auth token 75 * @return String to use as the RDS auth token 76 * @throws IllegalArgumentException if the required parameters are not valid 77 */ generateAuthenticationToken(GenerateAuthenticationTokenRequest request)78 default String generateAuthenticationToken(GenerateAuthenticationTokenRequest request) { 79 throw new UnsupportedOperationException(); 80 } 81 82 /** 83 * Builder for creating an instance of {@link RdsUtilities}. It can be configured using {@link RdsUtilities#builder()}. 84 * Once configured, the {@link RdsUtilities} can created using {@link #build()}. 85 */ 86 @SdkPublicApi 87 interface Builder { 88 /** 89 * The default region to use when working with the methods in {@link RdsUtilities} class. 90 * 91 * @return This object for method chaining 92 */ region(Region region)93 Builder region(Region region); 94 95 /** 96 * The default credentials provider to use when working with the methods in {@link RdsUtilities} class. 97 * 98 * @return This object for method chaining 99 */ credentialsProvider(AwsCredentialsProvider credentialsProvider)100 default Builder credentialsProvider(AwsCredentialsProvider credentialsProvider) { 101 return credentialsProvider((IdentityProvider<? extends AwsCredentialsIdentity>) credentialsProvider); 102 } 103 104 /** 105 * The default credentials provider to use when working with the methods in {@link RdsUtilities} class. 106 * 107 * @return This object for method chaining 108 */ credentialsProvider(IdentityProvider<? extends AwsCredentialsIdentity> credentialsProvider)109 default Builder credentialsProvider(IdentityProvider<? extends AwsCredentialsIdentity> credentialsProvider) { 110 throw new UnsupportedOperationException(); 111 } 112 113 114 /** 115 * Create a {@link RdsUtilities} 116 */ build()117 RdsUtilities build(); 118 } 119 } 120