Skip to content

Commit

Permalink
Allow federated auth
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed May 6, 2024
1 parent a6d6a7e commit 99352ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions env-example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ATHENA_DB=
ATHENA_TABLE=
BQ_CLIENT_CONFIG=
BQ_DATASET=
DT_LOG_EXPIRATION_DAYS=
MAX_DAYS_TO_ROLLUP=
14 changes: 13 additions & 1 deletion lib/bigquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@ const { BigQuery } = require("@google-cloud/bigquery");

const gzip = promisify(zlib.gzip);

// optional: google workload identity federation
exports.opts = () => {
if (process.env.BQ_CLIENT_CONFIG) {
const config = JSON.parse(process.env.BQ_CLIENT_CONFIG);
return {
projectId: config.audience.match(/projects\/([0-9]+)\/locations/)[1],
credentials: config,
};
}
return {};
};

// mockable dataset
exports.dataset = () => {
const bq = new BigQuery();
const bq = new BigQuery(exports.opts());
return bq.dataset(process.env.BQ_DATASET);
};

Expand Down

0 comments on commit 99352ed

Please sign in to comment.