Skip to content

Commit c336bfb

Browse files
sabifranjoSabolc Franjo
andauthored
🎉 Make credentials optional in BigQuery connector (issue #3657) (#3947)
* Make credentials optional for BigQuery connector * Bump destination-bigquery version 0.3.5 -> 0.3.6 Co-authored-by: Sabolc Franjo <sabolc.franjo@ev-box.com>
1 parent f365c0c commit c336bfb

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

airbyte-config/init/src/main/resources/config/STANDARD_DESTINATION_DEFINITION/22f6c74f-5699-40ff-833c-4a879ea40133.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"destinationDefinitionId": "22f6c74f-5699-40ff-833c-4a879ea40133",
33
"name": "BigQuery",
44
"dockerRepository": "airbyte/destination-bigquery",
5-
"dockerImageTag": "0.3.5",
5+
"dockerImageTag": "0.3.6",
66
"documentationUrl": "https://docs.airbyte.io/integrations/destinations/bigquery"
77
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- destinationDefinitionId: 22f6c74f-5699-40ff-833c-4a879ea40133
1818
name: BigQuery
1919
dockerRepository: airbyte/destination-bigquery
20-
dockerImageTag: 0.3.5
20+
dockerImageTag: 0.3.6
2121
documentationUrl: https://docs.airbyte.io/integrations/destinations/bigquery
2222
- destinationDefinitionId: 424892c4-daac-4491-b35d-c6688ba547ba
2323
name: Snowflake

airbyte-integrations/connectors/destination-bigquery/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
## 0.3.4
44
Added option to choose dataset location
5+
6+
## 0.3.6
7+
Service account credentials are now optional. Default credentials will be used if the field is empty.

airbyte-integrations/connectors/destination-bigquery/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar
88

99
RUN tar xf ${APPLICATION}.tar --strip-components=1
1010

11-
LABEL io.airbyte.version=0.3.5
11+
LABEL io.airbyte.version=0.3.6
1212
LABEL io.airbyte.name=airbyte/destination-bigquery

airbyte-integrations/connectors/destination-bigquery/src/main/java/io/airbyte/integrations/destination/bigquery/BigQueryDestination.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
import org.slf4j.Logger;
7070
import org.slf4j.LoggerFactory;
7171

72+
import static java.util.Objects.isNull;
73+
7274
public class BigQueryDestination extends BaseConnector implements Destination {
7375

7476
private static final Logger LOGGER = LoggerFactory.getLogger(BigQueryDestination.class);
@@ -130,24 +132,32 @@ private void createSchemaTable(BigQuery bigquery, String datasetId, String datas
130132

131133
private BigQuery getBigQuery(JsonNode config) {
132134
final String projectId = config.get(CONFIG_PROJECT_ID).asText();
133-
// handle the credentials json being passed as a json object or a json object already serialized as
134-
// a string.
135-
final String credentialsString =
136-
config.get(CONFIG_CREDS).isObject() ? Jsons.serialize(config.get(CONFIG_CREDS)) : config.get(CONFIG_CREDS).asText();
137-
try {
138-
final ServiceAccountCredentials credentials = ServiceAccountCredentials
139-
.fromStream(new ByteArrayInputStream(credentialsString.getBytes(Charsets.UTF_8)));
140135

141-
return BigQueryOptions.newBuilder()
136+
try {
137+
BigQueryOptions.Builder bigQueryBuilder = BigQueryOptions.newBuilder();
138+
ServiceAccountCredentials credentials = null;
139+
if (isUsingJsonCredentials(config)) {
140+
// handle the credentials json being passed as a json object or a json object already serialized as
141+
// a string.
142+
final String credentialsString =
143+
config.get(CONFIG_CREDS).isObject() ? Jsons.serialize(config.get(CONFIG_CREDS)) : config.get(CONFIG_CREDS).asText();
144+
credentials = ServiceAccountCredentials
145+
.fromStream(new ByteArrayInputStream(credentialsString.getBytes(Charsets.UTF_8)));
146+
}
147+
return bigQueryBuilder
142148
.setProjectId(projectId)
143-
.setCredentials(credentials)
149+
.setCredentials(!isNull(credentials) ? credentials : ServiceAccountCredentials.getApplicationDefault())
144150
.build()
145151
.getService();
146152
} catch (IOException e) {
147153
throw new RuntimeException(e);
148154
}
149155
}
150156

157+
public static boolean isUsingJsonCredentials(JsonNode config) {
158+
return config.has(CONFIG_CREDS) && !config.get(CONFIG_CREDS).asText().isEmpty();
159+
}
160+
151161
/**
152162
* Strategy:
153163
* <p>

airbyte-integrations/connectors/destination-bigquery/src/main/resources/spec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"$schema": "http://json-schema.org/draft-07/schema#",
99
"title": "BigQuery Destination Spec",
1010
"type": "object",
11-
"required": ["project_id", "dataset_id", "credentials_json"],
11+
"required": ["project_id", "dataset_id"],
1212
"additionalProperties": false,
1313
"properties": {
1414
"project_id": {
@@ -58,7 +58,7 @@
5858
},
5959
"credentials_json": {
6060
"type": "string",
61-
"description": "The contents of the JSON service account key. Check out the <a href=\"https://docs.airbyte.io/integrations/destinations/bigquery\">docs</a> if you need help generating this key.",
61+
"description": "The contents of the JSON service account key. Check out the <a href=\"https://docs.airbyte.io/integrations/destinations/bigquery\">docs</a> if you need help generating this key. Default credentials will be used if this field is left empty.",
6262
"title": "Credentials JSON",
6363
"airbyte_secret": true
6464
}

0 commit comments

Comments
 (0)