Skip to content

Commit d520bdd

Browse files
committed
feat: set JDBC credentials from environmental variables
Using the CONNECT_JDBC_CONNECTION_USER and CONNECT_JDBC_CONNECTION_PASSWORD env vars.
1 parent 220f734 commit d520bdd

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2018 Confluent Inc.
3+
*
4+
* Licensed under the Confluent Community License (the "License"); you may not use
5+
* this file except in compliance with the License. You may obtain a copy of the
6+
* License at
7+
*
8+
* http://www.confluent.io/confluent-community-license
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*/
15+
16+
package io.confluent.connect.jdbc.util;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
21+
public class EnvVarsJdbcCredentialsProvider implements JdbcCredentialsProvider {
22+
23+
private static final Logger log = LoggerFactory.getLogger(Version.class);
24+
25+
private static final String ENV_VAR_DB_USERNAME = "CONNECT_JDBC_CONNECTION_USER";
26+
private static final String ENV_VAR_DB_PASSWORD = "CONNECT_JDBC_CONNECTION_PASSWORD";
27+
28+
@Override
29+
public JdbcCredentials getJdbcCredentials() {
30+
String username = System.getenv(ENV_VAR_DB_USERNAME);
31+
String password = System.getenv(ENV_VAR_DB_PASSWORD);
32+
if (username == null || password == null) {
33+
throw new RuntimeException("Environment variables " + ENV_VAR_DB_USERNAME + " and "
34+
+ ENV_VAR_DB_PASSWORD + " must be set when using EnvVarsJdbcCredentialsProvider");
35+
}
36+
log.info("Using JDBC credentials from environment variables " + ENV_VAR_DB_USERNAME + " and "
37+
+ ENV_VAR_DB_PASSWORD);
38+
return new BasicJdbcCredentials(username, password);
39+
}
40+
41+
}

0 commit comments

Comments
 (0)