diff --git a/ballerina/client.bal b/ballerina/client.bal index f521cc3..c84ef47 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -115,9 +115,18 @@ public isolated client class Client { # # + datasourceName - The driver class name to be used to get the connection # + properties - The database properties, which should be applied when getting the connection +# + ssl - SSL configurations to be used public type Options record {| string? datasourceName = (); map? properties = (); + SecureSocket ssl?; +|}; + +# The SSL configurations to be used when connecting to the Redshift server. +# +# + rootcert - File path of the SSL root certificate +public type SecureSocket record {| + string rootcert?; |}; # An additional set of configurations for the JDBC Client to be passed internally within the module. diff --git a/native/src/main/java/io/ballerina/lib/aws/redshift/Constants.java b/native/src/main/java/io/ballerina/lib/aws/redshift/Constants.java index 84c8cfa..4e69cad 100644 --- a/native/src/main/java/io/ballerina/lib/aws/redshift/Constants.java +++ b/native/src/main/java/io/ballerina/lib/aws/redshift/Constants.java @@ -39,8 +39,17 @@ public static final class ClientConfiguration { public static final BString CONNECTION_POOL_OPTIONS = StringUtils.fromString("connectionPool"); public static final BString OPTIONS = StringUtils.fromString("options"); public static final BString PROPERTIES = StringUtils.fromString("properties"); + public static final BString SECURE_SOCKET = StringUtils.fromString("ssl"); } + public static final class SSL { + public static final BString SSL_MODE = StringUtils.fromString("ssl"); + public static final BString ROOT_CERT = StringUtils.fromString("rootcert"); + public static final BString SSL_FACTORY_ARG = StringUtils.fromString("sslfactory"); + public static final BString SSL_FACTORY_VALUE = StringUtils.fromString("com.amazon.redshift.ssl.NonValidatingFactory"); + public static final BString SSL_ROOT_CERT_ARG = StringUtils.fromString("sslfactoryarg"); + + } public static final String CONNECT_TIMEOUT = ".*(connect).*(timeout).*"; public static final String POOL_CONNECTION_TIMEOUT = "ConnectionTimeout"; diff --git a/native/src/main/java/io/ballerina/lib/aws/redshift/Utils.java b/native/src/main/java/io/ballerina/lib/aws/redshift/Utils.java new file mode 100644 index 0000000..ddcb54b --- /dev/null +++ b/native/src/main/java/io/ballerina/lib/aws/redshift/Utils.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 WSO2 LLC. (https://www.wso2.com) All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.lib.aws.redshift; + +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BString; + +/** + * This class includes utility functions. + */ +public class Utils { + + public static void addSSLOptions(BMap secureSocket, BMap options) { + if (secureSocket == null) { + options.put(Constants.SSL.SSL_MODE, false); + } else { + options.put(Constants.SSL.SSL_MODE, true); + BString sslrootcert = secureSocket.getStringValue(Constants.SSL.ROOT_CERT); + options.put(Constants.SSL.SSL_FACTORY_ARG, Constants.SSL.SSL_FACTORY_VALUE.getValue()); + if (sslrootcert != null) { + options.put(Constants.SSL.SSL_ROOT_CERT_ARG, sslrootcert); + } + } + } +} diff --git a/native/src/main/java/io/ballerina/lib/aws/redshift/nativeimpl/ClientProcessor.java b/native/src/main/java/io/ballerina/lib/aws/redshift/nativeimpl/ClientProcessor.java index 507e4ab..12d8eab 100644 --- a/native/src/main/java/io/ballerina/lib/aws/redshift/nativeimpl/ClientProcessor.java +++ b/native/src/main/java/io/ballerina/lib/aws/redshift/nativeimpl/ClientProcessor.java @@ -19,6 +19,7 @@ package io.ballerina.lib.aws.redshift.nativeimpl; import io.ballerina.lib.aws.redshift.Constants; +import io.ballerina.lib.aws.redshift.Utils; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; @@ -57,11 +58,8 @@ public static Object createClient(BObject client, BMap clientCo properties = options.getMapValue(Constants.ClientConfiguration.PROPERTIES); BString dataSourceNamVal = options.getStringValue(Constants.ClientConfiguration.DATASOURCE_NAME); datasourceName = dataSourceNamVal == null ? null : dataSourceNamVal.getValue(); - BString requestGeneratedKeysVal = options.getStringValue( - Constants.ClientConfiguration.REQUEST_GENERATED_KEYS); - requestGeneratedKeys = requestGeneratedKeysVal == null ? - Constants.RequestGeneratedKeysValues.ALL : requestGeneratedKeysVal.getValue(); if (properties != null) { + Utils.addSSLOptions(options.getMapValue(Constants.ClientConfiguration.SECURE_SOCKET), properties); for (Object propKey : properties.getKeys()) { if (propKey.toString().toLowerCase(Locale.ENGLISH).matches(Constants.CONNECT_TIMEOUT)) { poolProperties = new Properties();