Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Make credentials optional in BigQuery connector (issue #3657) #3947

Merged
merged 2 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"destinationDefinitionId": "22f6c74f-5699-40ff-833c-4a879ea40133",
"name": "BigQuery",
"dockerRepository": "airbyte/destination-bigquery",
"dockerImageTag": "0.3.5",
"dockerImageTag": "0.3.6",
"documentationUrl": "https://docs.airbyte.io/integrations/destinations/bigquery"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- destinationDefinitionId: 22f6c74f-5699-40ff-833c-4a879ea40133
name: BigQuery
dockerRepository: airbyte/destination-bigquery
dockerImageTag: 0.3.5
dockerImageTag: 0.3.6
documentationUrl: https://docs.airbyte.io/integrations/destinations/bigquery
- destinationDefinitionId: 424892c4-daac-4491-b35d-c6688ba547ba
name: Snowflake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

## 0.3.4
Added option to choose dataset location

## 0.3.6
Service account credentials are now optional. Default credentials will be used if the field is empty.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar

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

LABEL io.airbyte.version=0.3.5
LABEL io.airbyte.version=0.3.6
LABEL io.airbyte.name=airbyte/destination-bigquery
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.isNull;

public class BigQueryDestination extends BaseConnector implements Destination {

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

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

return BigQueryOptions.newBuilder()
try {
BigQueryOptions.Builder bigQueryBuilder = BigQueryOptions.newBuilder();
ServiceAccountCredentials credentials = null;
if (isUsingJsonCredentials(config)) {
// handle the credentials json being passed as a json object or a json object already serialized as
// a string.
final String credentialsString =
config.get(CONFIG_CREDS).isObject() ? Jsons.serialize(config.get(CONFIG_CREDS)) : config.get(CONFIG_CREDS).asText();
credentials = ServiceAccountCredentials
.fromStream(new ByteArrayInputStream(credentialsString.getBytes(Charsets.UTF_8)));
}
return bigQueryBuilder
.setProjectId(projectId)
.setCredentials(credentials)
.setCredentials(!isNull(credentials) ? credentials : ServiceAccountCredentials.getApplicationDefault())
.build()
.getService();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static boolean isUsingJsonCredentials(JsonNode config) {
return config.has(CONFIG_CREDS) && !config.get(CONFIG_CREDS).asText().isEmpty();
}

/**
* Strategy:
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "BigQuery Destination Spec",
"type": "object",
"required": ["project_id", "dataset_id", "credentials_json"],
"required": ["project_id", "dataset_id"],
"additionalProperties": false,
"properties": {
"project_id": {
Expand Down Expand Up @@ -58,7 +58,7 @@
},
"credentials_json": {
"type": "string",
"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.",
"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.",
"title": "Credentials JSON",
"airbyte_secret": true
}
Expand Down