Skip to content

Commit 568e9f5

Browse files
🎉 Source Oracle: Use Service Name to connect to database (#14953)
* add service_name as second connection option * fix test * merge with master * bump version * bump strict-encrypt * fixed test * auto-bump connector version [ci skip] Co-authored-by: Octavia Squidington III <[email protected]>
1 parent b57ec0f commit 568e9f5

File tree

13 files changed

+184
-37
lines changed

13 files changed

+184
-37
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@
651651
- name: Oracle DB
652652
sourceDefinitionId: b39a7370-74c3-45a6-ac3a-380d48520a83
653653
dockerRepository: airbyte/source-oracle
654-
dockerImageTag: 0.3.18
654+
dockerImageTag: 0.3.19
655655
documentationUrl: https://docs.airbyte.io/integrations/sources/oracle
656656
icon: oracle.svg
657657
sourceType: database

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6297,7 +6297,7 @@
62976297
supportsNormalization: false
62986298
supportsDBT: false
62996299
supported_destination_sync_modes: []
6300-
- dockerImage: "airbyte/source-oracle:0.3.18"
6300+
- dockerImage: "airbyte/source-oracle:0.3.19"
63016301
spec:
63026302
documentationUrl: "https://docs.airbyte.io/integrations/sources/oracle"
63036303
connectionSpecification:
@@ -6307,7 +6307,6 @@
63076307
required:
63086308
- "host"
63096309
- "port"
6310-
- "sid"
63116310
- "username"
63126311
properties:
63136312
host:
@@ -6326,10 +6325,40 @@
63266325
maximum: 65536
63276326
default: 1521
63286327
order: 2
6329-
sid:
6330-
title: "SID (Oracle System Identifier)"
6331-
type: "string"
6328+
connection_data:
6329+
title: "Connect by"
6330+
type: "object"
6331+
description: "Connect data that will be used for DB connection"
63326332
order: 3
6333+
oneOf:
6334+
- title: "Service name"
6335+
description: "Use service name"
6336+
required:
6337+
- "service_name"
6338+
properties:
6339+
connection_type:
6340+
type: "string"
6341+
const: "service_name"
6342+
default: "service_name"
6343+
order: 0
6344+
service_name:
6345+
title: "Service name"
6346+
type: "string"
6347+
order: 1
6348+
- title: "System ID (SID)"
6349+
description: "Use SID (Oracle System Identifier)"
6350+
required:
6351+
- "sid"
6352+
properties:
6353+
connection_type:
6354+
type: "string"
6355+
const: "sid"
6356+
default: "sid"
6357+
order: 0
6358+
sid:
6359+
title: "System ID (SID)"
6360+
type: "string"
6361+
order: 1
63336362
username:
63346363
title: "User"
63356364
description: "The username which is used to access the database."

airbyte-integrations/connectors/source-oracle-strict-encrypt/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ ENV TZ UTC
1717

1818
COPY --from=build /airbyte /airbyte
1919

20-
LABEL io.airbyte.version=0.3.16
20+
LABEL io.airbyte.version=0.3.17
2121
LABEL io.airbyte.name=airbyte/source-oracle-strict-encrypt

airbyte-integrations/connectors/source-oracle-strict-encrypt/src/test/resources/expected_spec.json

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"$schema": "http://json-schema.org/draft-07/schema#",
55
"title": "Oracle Source Spec",
66
"type": "object",
7-
"required": ["host", "port", "sid", "username", "encryption"],
7+
"required": ["host", "port", "username", "encryption"],
88
"properties": {
99
"host": {
1010
"title": "Host",
@@ -21,10 +21,53 @@
2121
"default": 1521,
2222
"order": 2
2323
},
24-
"sid": {
25-
"title": "SID (Oracle System Identifier)",
26-
"type": "string",
27-
"order": 3
24+
"connection_data": {
25+
"title": "Connect by",
26+
"type": "object",
27+
"description": "Connect data that will be used for DB connection",
28+
"order": 3,
29+
"oneOf": [
30+
{
31+
"title": "Service name",
32+
"description": "Use service name",
33+
"required": [
34+
"service_name"
35+
],
36+
"properties": {
37+
"connection_type": {
38+
"type": "string",
39+
"const": "service_name",
40+
"default": "service_name",
41+
"order": 0
42+
},
43+
"service_name": {
44+
"title": "Service name",
45+
"type": "string",
46+
"order": 1
47+
}
48+
}
49+
},
50+
{
51+
"title": "System ID (SID)",
52+
"description": "Use SID (Oracle System Identifier)",
53+
"required": [
54+
"sid"
55+
],
56+
"properties": {
57+
"connection_type": {
58+
"type": "string",
59+
"const": "sid",
60+
"default": "sid",
61+
"order": 0
62+
},
63+
"sid": {
64+
"title": "System ID (SID)",
65+
"type": "string",
66+
"order": 1
67+
}
68+
}
69+
}
70+
]
2871
},
2972
"username": {
3073
"title": "User",

airbyte-integrations/connectors/source-oracle/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ ENV TZ UTC
88
COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar
99
RUN tar xf ${APPLICATION}.tar --strip-components=1
1010

11-
LABEL io.airbyte.version=0.3.18
11+
LABEL io.airbyte.version=0.3.19
1212
LABEL io.airbyte.name=airbyte/source-oracle

airbyte-integrations/connectors/source-oracle/src/main/java/io/airbyte/integrations/source/oracle/OracleSource.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public class OracleSource extends AbstractJdbcSource<JDBCType> implements Source
4141
private static final String KEY_STORE_FILE_PATH = "clientkeystore.jks";
4242
private static final String KEY_STORE_PASS = RandomStringUtils.randomAlphanumeric(8);
4343

44+
private static final String SID = "sid";
45+
private static final String SERVICE_NAME = "service_name";
46+
private static final String UNRECOGNIZED = "Unrecognized";
47+
private static final String CONNECTION_DATA = "connection_data";
48+
4449
enum Protocol {
4550
TCP,
4651
TCPS
@@ -70,12 +75,21 @@ public JsonNode toDatabaseConfig(final JsonNode config) {
7075
final Protocol protocol = config.has(JdbcUtils.ENCRYPTION_KEY)
7176
? obtainConnectionProtocol(config.get(JdbcUtils.ENCRYPTION_KEY), additionalParameters)
7277
: Protocol.TCP;
73-
final String connectionString = String.format(
74-
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=%s)(HOST=%s)(PORT=%s))(CONNECT_DATA=(SID=%s)))",
75-
protocol,
76-
config.get(JdbcUtils.HOST_KEY).asText(),
77-
config.get(JdbcUtils.PORT_KEY).asText(),
78-
config.get("sid").asText());
78+
String connectionString;
79+
if (config.has(CONNECTION_DATA)) {
80+
JsonNode connectionData = config.get(CONNECTION_DATA);
81+
final String connectionType = connectionData.has("connection_type") ? connectionData.get("connection_type").asText()
82+
: UNRECOGNIZED;
83+
connectionString = switch (connectionType) {
84+
case SERVICE_NAME -> buildConnectionString(config, protocol.toString(), SERVICE_NAME.toUpperCase(), config.get(CONNECTION_DATA).get(SERVICE_NAME).asText());
85+
case SID -> buildConnectionString(config, protocol.toString(), SID.toUpperCase(), config.get(CONNECTION_DATA).get(SID).asText());
86+
default -> throw new IllegalArgumentException("Unrecognized connection type: " + connectionType);
87+
};
88+
} else {
89+
// To keep backward compatibility with existing connectors which doesn't have connection_data
90+
// and use only sid.
91+
connectionString = buildConnectionString(config, protocol.toString(), SID.toUpperCase(), config.get(SID).asText());
92+
}
7993

8094
final ImmutableMap.Builder<Object, Object> configBuilder = ImmutableMap.builder()
8195
.put(JdbcUtils.USERNAME_KEY, config.get(JdbcUtils.USERNAME_KEY).asText())
@@ -189,4 +203,13 @@ public static void main(final String[] args) throws Exception {
189203
LOGGER.info("completed source: {}", OracleSource.class);
190204
}
191205

206+
private String buildConnectionString(JsonNode config, String protocol, String connectionTypeName, String connectionTypeValue) {
207+
return String.format(
208+
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=%s)(HOST=%s)(PORT=%s))(CONNECT_DATA=(%s=%s)))",
209+
protocol,
210+
config.get(JdbcUtils.HOST_KEY).asText(),
211+
config.get(JdbcUtils.PORT_KEY).asText(),
212+
connectionTypeName,
213+
connectionTypeValue);
214+
}
192215
}

airbyte-integrations/connectors/source-oracle/src/main/resources/spec.json

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"$schema": "http://json-schema.org/draft-07/schema#",
55
"title": "Oracle Source Spec",
66
"type": "object",
7-
"required": ["host", "port", "sid", "username"],
7+
"required": ["host", "port", "username"],
88
"properties": {
99
"host": {
1010
"title": "Host",
@@ -21,10 +21,53 @@
2121
"default": 1521,
2222
"order": 2
2323
},
24-
"sid": {
25-
"title": "SID (Oracle System Identifier)",
26-
"type": "string",
27-
"order": 3
24+
"connection_data": {
25+
"title": "Connect by",
26+
"type": "object",
27+
"description": "Connect data that will be used for DB connection",
28+
"order": 3,
29+
"oneOf": [
30+
{
31+
"title": "Service name",
32+
"description": "Use service name",
33+
"required": [
34+
"service_name"
35+
],
36+
"properties": {
37+
"connection_type": {
38+
"type": "string",
39+
"const": "service_name",
40+
"default": "service_name",
41+
"order": 0
42+
},
43+
"service_name": {
44+
"title": "Service name",
45+
"type": "string",
46+
"order": 1
47+
}
48+
}
49+
},
50+
{
51+
"title": "System ID (SID)",
52+
"description": "Use SID (Oracle System Identifier)",
53+
"required": [
54+
"sid"
55+
],
56+
"properties": {
57+
"connection_type": {
58+
"type": "string",
59+
"const": "sid",
60+
"default": "sid",
61+
"order": 0
62+
},
63+
"sid": {
64+
"title": "System ID (SID)",
65+
"type": "string",
66+
"order": 1
67+
}
68+
}
69+
}
70+
]
2871
},
2972
"username": {
3073
"title": "User",

airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/AbstractSshOracleSourceAcceptanceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private void populateDatabaseTestData() throws Exception {
5757
String.format(DatabaseDriver.ORACLE.getUrlFormatString(),
5858
config.get("host").asText(),
5959
config.get("port").asInt(),
60-
config.get("sid").asText()));
60+
config.get("connection_data").get("service_name").asText()));
6161

6262
try {
6363
final JdbcDatabase database = new DefaultJdbcDatabase(dataSource);
@@ -117,7 +117,9 @@ public ImmutableMap.Builder<Object, Object> getBasicOracleDbConfigBuider(final O
117117
.put("username", db.getUsername())
118118
.put("password", db.getPassword())
119119
.put("port", db.getExposedPorts().get(0))
120-
.put("sid", db.getSid())
120+
.put("connection_data", ImmutableMap.builder()
121+
.put("service_name", db.getSid())
122+
.put("connection_type", "service_name").build())
121123
.put("schemas", List.of("JDBC_SPACE"))
122124
.put("encryption", Jsons.jsonNode(ImmutableMap.builder()
123125
.put("encryption_method", "unencrypted")

airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceAcceptanceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ protected void setupEnvironment(final TestDestinationEnv environment) throws Exc
4545
config = Jsons.jsonNode(ImmutableMap.builder()
4646
.put("host", container.getHost())
4747
.put("port", container.getFirstMappedPort())
48-
.put("sid", container.getSid())
48+
.put("connection_data", ImmutableMap.builder()
49+
.put("service_name", container.getSid())
50+
.put("connection_type", "service_name").build())
4951
.put("username", container.getUsername())
5052
.put("password", container.getPassword())
5153
.put("schemas", List.of("JDBC_SPACE"))
@@ -61,7 +63,7 @@ protected void setupEnvironment(final TestDestinationEnv environment) throws Exc
6163
String.format(DatabaseDriver.ORACLE.getUrlFormatString(),
6264
config.get("host").asText(),
6365
config.get("port").asInt(),
64-
config.get("sid").asText()));
66+
config.get("connection_data").get("service_name").asText()));
6567

6668
try {
6769
final JdbcDatabase database = new DefaultJdbcDatabase(dataSource);

airbyte-integrations/connectors/source-oracle/src/test-integration/java/io/airbyte/integrations/source/oracle/OracleSourceDatatypeTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ protected Database setupDatabase() throws Exception {
4444
config = Jsons.jsonNode(ImmutableMap.builder()
4545
.put("host", container.getHost())
4646
.put("port", container.getFirstMappedPort())
47-
.put("sid", container.getSid())
47+
.put("connection_data", ImmutableMap.builder()
48+
.put("service_name", container.getSid())
49+
.put("connection_type", "service_name").build())
4850
.put("username", container.getUsername())
4951
.put("password", container.getPassword())
5052
.put("schemas", List.of("TEST"))
@@ -57,7 +59,7 @@ protected Database setupDatabase() throws Exception {
5759
String.format(DatabaseDriver.ORACLE.getUrlFormatString(),
5860
config.get("host").asText(),
5961
config.get("port").asInt(),
60-
config.get("sid").asText()),
62+
config.get("connection_data").get("service_name").asText()),
6163
null);
6264
final Database database = new Database(dslContext);
6365
LOGGER.warn("config: " + config);

0 commit comments

Comments
 (0)