|
30 | 30 | import com.ing.data.cassandra.jdbc.optionset.Liquibase;
|
31 | 31 | import com.ing.data.cassandra.jdbc.utils.ContactPoint;
|
32 | 32 | import org.apache.commons.lang3.StringUtils;
|
| 33 | +import software.amazon.awssdk.regions.Region; |
33 | 34 |
|
34 | 35 | import javax.sql.ConnectionPoolDataSource;
|
35 | 36 | import javax.sql.DataSource;
|
|
48 | 49 | import static com.ing.data.cassandra.jdbc.utils.ErrorConstants.NO_INTERFACE;
|
49 | 50 | import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.PROTOCOL;
|
50 | 51 | import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_ACTIVE_PROFILE;
|
| 52 | +import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_AWS_REGION; |
| 53 | +import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_AWS_SECRET_NAME; |
| 54 | +import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_AWS_SECRET_REGION; |
51 | 55 | import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_CLOUD_SECURE_CONNECT_BUNDLE;
|
52 | 56 | import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_COMPLIANCE_MODE;
|
53 | 57 | import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_CONFIG_FILE;
|
|
70 | 74 | import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_TCP_NO_DELAY;
|
71 | 75 | import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_USER;
|
72 | 76 | import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_USE_KERBEROS;
|
| 77 | +import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_USE_SIG_V4; |
73 | 78 | import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.createSubName;
|
74 | 79 |
|
75 | 80 | /**
|
@@ -827,6 +832,125 @@ public void setConfigurationFile(final Path configurationFilePath) {
|
827 | 832 | this.setConfigurationFile(configurationFilePath.toString());
|
828 | 833 | }
|
829 | 834 |
|
| 835 | + /** |
| 836 | + * Gets the AWS region of the contact point of the Amazon Keyspaces instance. |
| 837 | + * |
| 838 | + * @return The AWS region. |
| 839 | + */ |
| 840 | + public String getAwsRegion() { |
| 841 | + return this.properties.getProperty(TAG_AWS_REGION); |
| 842 | + } |
| 843 | + |
| 844 | + /** |
| 845 | + * Sets the AWS region of the contact point of the Amazon Keyspaces instance. |
| 846 | + * |
| 847 | + * @param region The string representation of the region. |
| 848 | + */ |
| 849 | + public void setAwsRegion(final String region) { |
| 850 | + this.setDataSourceProperty(TAG_AWS_REGION, region); |
| 851 | + } |
| 852 | + |
| 853 | + /** |
| 854 | + * Sets the AWS region of the contact point of the Amazon Keyspaces instance. |
| 855 | + * |
| 856 | + * @param region The AWS region. |
| 857 | + */ |
| 858 | + public void setAwsRegion(final Region region) { |
| 859 | + if (region == null) { |
| 860 | + this.setAwsRegion((String) null); |
| 861 | + } else { |
| 862 | + this.setDataSourceProperty(TAG_AWS_REGION, region.id()); |
| 863 | + } |
| 864 | + } |
| 865 | + |
| 866 | + /** |
| 867 | + * Gets the AWS region of the Amazon Secret Manager in which the credentials of the user used for the connection |
| 868 | + * are stored. If not defined, the value is the one returned by {@link #getAwsRegion()}. |
| 869 | + * |
| 870 | + * @return . |
| 871 | + */ |
| 872 | + public String getAwsSecretRegion() { |
| 873 | + return (String) this.properties.getOrDefault(TAG_AWS_SECRET_REGION, |
| 874 | + this.properties.getProperty(TAG_AWS_REGION)); |
| 875 | + } |
| 876 | + |
| 877 | + /** |
| 878 | + * Sets the AWS region of the Amazon Secret Manager in which the credentials of the user used for the connection |
| 879 | + * are stored. |
| 880 | + * |
| 881 | + * @param region The string representation of the region. |
| 882 | + */ |
| 883 | + public void setAwsSecretRegion(final String region) { |
| 884 | + this.setDataSourceProperty(TAG_AWS_SECRET_REGION, region); |
| 885 | + } |
| 886 | + |
| 887 | + /** |
| 888 | + * Sets the AWS region of the Amazon Secret Manager in which the credentials of the user used for the connection |
| 889 | + * are stored. |
| 890 | + * |
| 891 | + * @param region The AWS region. |
| 892 | + */ |
| 893 | + public void setAwsSecretRegion(final Region region) { |
| 894 | + if (region == null) { |
| 895 | + this.setAwsSecretRegion((String) null); |
| 896 | + } else { |
| 897 | + this.setDataSourceProperty(TAG_AWS_SECRET_REGION, region.id()); |
| 898 | + } |
| 899 | + } |
| 900 | + |
| 901 | + /** |
| 902 | + * Gets the name of the secret, stored in Amazon Secret Manager, containing the credentials of the user used for |
| 903 | + * the connection. |
| 904 | + * |
| 905 | + * @return The name of the secret. |
| 906 | + */ |
| 907 | + public String getAwsSecretName() { |
| 908 | + return this.properties.getProperty(TAG_AWS_SECRET_NAME); |
| 909 | + } |
| 910 | + |
| 911 | + /** |
| 912 | + * Sets the name of the secret, stored in Amazon Secret Manager, containing the credentials of the user used for |
| 913 | + * the connection. |
| 914 | + * |
| 915 | + * @param secretName The name of the secret. |
| 916 | + */ |
| 917 | + public void setAwsSecretName(final String secretName) { |
| 918 | + this.setDataSourceProperty(TAG_AWS_SECRET_NAME, secretName); |
| 919 | + } |
| 920 | + |
| 921 | + /** |
| 922 | + * Gets whether the Amazon Signature V4 auth provider is enabled. |
| 923 | + * <p> |
| 924 | + * The default value is {@code false}. |
| 925 | + * See <a href="https://docs.datastax.com/en/developer/java-driver/latest/manual/core/authentication/"> |
| 926 | + * Authentication reference</a> and |
| 927 | + * <a href="https://github.com/aws/aws-sigv4-auth-cassandra-java-driver-plugin"> |
| 928 | + * Amazon Signature V4 authenticator plugin for Java driver</a> for further information. |
| 929 | + * </p> |
| 930 | + * |
| 931 | + * @return {@code true} if the Amazon Signature V4 auth provider is enabled, {@code false} otherwise. |
| 932 | + */ |
| 933 | + public boolean isSigV4AuthProviderEnabled() { |
| 934 | + return (boolean) this.properties.getOrDefault(TAG_USE_SIG_V4, false); |
| 935 | + } |
| 936 | + |
| 937 | + /** |
| 938 | + * Sets whether the Amazon Signature V4 auth provider is enabled. |
| 939 | + * <p> |
| 940 | + * This will enable the Amazon Signature V4 {@link AuthProvider} implementation for the connection using the |
| 941 | + * AWS region defined in the property {@link #setAwsRegion(String)} (or {@link #setAwsRegion(Region)}). |
| 942 | + * See <a href="https://docs.datastax.com/en/developer/java-driver/latest/manual/core/authentication/"> |
| 943 | + * Authentication reference</a> and |
| 944 | + * <a href="https://github.com/aws/aws-sigv4-auth-cassandra-java-driver-plugin"> |
| 945 | + * Amazon Signature V4 authenticator plugin for Java driver</a> for further information. |
| 946 | + * </p> |
| 947 | + * |
| 948 | + * @param enabled Whether the Amazon Signature V4 auth provider is enabled. |
| 949 | + */ |
| 950 | + public void setSigV4AuthProviderEnabled(final boolean enabled) { |
| 951 | + this.setDataSourceProperty(TAG_USE_SIG_V4, enabled); |
| 952 | + } |
| 953 | + |
830 | 954 | private void setDataSourceProperty(final String propertyName, final Object value) {
|
831 | 955 | if (value == null) {
|
832 | 956 | this.properties.remove(propertyName);
|
|
0 commit comments