|
| 1 | +/* |
| 2 | + ** Copyright (c) 2025 Oracle and/or its affiliates. |
| 3 | + ** |
| 4 | + ** The Universal Permissive License (UPL), Version 1.0 |
| 5 | + ** |
| 6 | + ** Subject to the condition set forth below, permission is hereby granted to any |
| 7 | + ** person obtaining a copy of this software, associated documentation and/or data |
| 8 | + ** (collectively the "Software"), free of charge and under any and all copyright |
| 9 | + ** rights in the Software, and any and all patent rights owned or freely |
| 10 | + ** licensable by each licensor hereunder covering either (i) the unmodified |
| 11 | + ** Software as contributed to or provided by such licensor, or (ii) the Larger |
| 12 | + ** Works (as defined below), to deal in both |
| 13 | + ** |
| 14 | + ** (a) the Software, and |
| 15 | + ** (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if |
| 16 | + ** one is included with the Software (each a "Larger Work" to which the Software |
| 17 | + ** is contributed by such licensors), |
| 18 | + ** |
| 19 | + ** without restriction, including without limitation the rights to copy, create |
| 20 | + ** derivative works of, display, perform, and distribute the Software and make, |
| 21 | + ** use, sell, offer for sale, import, export, have made, and have sold the |
| 22 | + ** Software and the Larger Work(s), and to sublicense the foregoing rights on |
| 23 | + ** either these or other terms. |
| 24 | + ** |
| 25 | + ** This license is subject to the following condition: |
| 26 | + ** The above copyright notice and either this complete permission notice or at |
| 27 | + ** a minimum a reference to the UPL must be included in all copies or |
| 28 | + ** substantial portions of the Software. |
| 29 | + ** |
| 30 | + ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 31 | + ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 32 | + ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 33 | + ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 34 | + ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 35 | + ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 36 | + ** SOFTWARE. |
| 37 | + */ |
| 38 | + |
| 39 | +package oracle.jdbc.provider.aws.resource; |
| 40 | + |
| 41 | +import oracle.jdbc.provider.aws.authentication.AwsAuthenticationMethod; |
| 42 | +import oracle.jdbc.provider.aws.authentication.AwsCredentialsFactory; |
| 43 | +import oracle.jdbc.provider.resource.AbstractResourceProvider; |
| 44 | +import oracle.jdbc.provider.resource.ResourceParameter; |
| 45 | + |
| 46 | +import java.util.stream.Stream; |
| 47 | + |
| 48 | +import static oracle.jdbc.provider.aws.authentication.AwsAuthenticationMethod.DEFAULT; |
| 49 | +import static oracle.jdbc.provider.aws.authentication.AwsCredentialsFactory.AUTHENTICATION_METHOD; |
| 50 | +import static oracle.jdbc.provider.aws.configuration.AwsConfigurationParameters.REGION; |
| 51 | +import static oracle.jdbc.provider.aws.resource.AwsSecretsManagerResourceParameterNames.AWS_REGION; |
| 52 | + |
| 53 | +/** |
| 54 | + * Super class of all {@code OracleResourceProvider} implementations |
| 55 | + * that request a resource from AWS. This super class defines parameters for |
| 56 | + * authentication with AWS. |
| 57 | + */ |
| 58 | +public abstract class AwsResourceProvider extends AbstractResourceProvider { |
| 59 | + |
| 60 | + private static final ResourceParameter[] PARAMETERS = { |
| 61 | + new ResourceParameter("authenticationMethod", AUTHENTICATION_METHOD, |
| 62 | + "aws-default", |
| 63 | + AwsResourceProvider::parseAuthenticationMethod), |
| 64 | + new ResourceParameter(AWS_REGION, REGION) |
| 65 | + }; |
| 66 | + |
| 67 | + /** |
| 68 | + * Constructs a provider identified by the name: |
| 69 | + * <pre>{@code |
| 70 | + * ojdbc-provider-aws-{resourceType} |
| 71 | + * }</pre> |
| 72 | + * @param resourceType The resource type identifier used in the provider name. |
| 73 | + * @param parameters Additional parameters specific to the subclass provider. |
| 74 | + */ |
| 75 | + protected AwsResourceProvider(String resourceType, ResourceParameter... parameters) { |
| 76 | + super("aws", resourceType, |
| 77 | + Stream.concat(Stream.of(PARAMETERS), Stream.of(parameters)) |
| 78 | + .toArray(ResourceParameter[]::new)); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Parses the "authenticationMethod" parameter as an |
| 83 | + * {@link AwsAuthenticationMethod} recognized by {@link AwsCredentialsFactory}. |
| 84 | + * |
| 85 | + * @param authenticationMethod The value to parse. |
| 86 | + * @return An {@link AwsAuthenticationMethod} enum. |
| 87 | + * @throws IllegalArgumentException if the value is unrecognized. |
| 88 | + */ |
| 89 | + private static AwsAuthenticationMethod parseAuthenticationMethod(String authenticationMethod) { |
| 90 | + switch (authenticationMethod) { |
| 91 | + case "aws-default": return DEFAULT; |
| 92 | + default: |
| 93 | + throw new IllegalArgumentException("Unrecognized authentication method: " + authenticationMethod); |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments