Skip to content

Commit

Permalink
try to fix authentication issue from updating google-spreadsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
powellkerry committed Mar 18, 2024
1 parent becb331 commit 7380c28
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@pagerduty/pdjs": "^2.2.2",
"@slack/bolt": "^3.3.0",
"dotenv": "^8.2.0",
"google-auth-library": "^9.7.0",
"google-spreadsheet": "^4.1.1",
"googleapis": "^72.0.0",
"moment": "^2.29.4",
Expand Down
26 changes: 13 additions & 13 deletions src/api/google/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { GoogleSpreadsheet } = require('google-spreadsheet');
const { auth } = require('google-auth-library');
const client_config = require('../../../google_client.json');
const fetch = require('node-fetch');
const moment = require('moment-timezone');
Expand All @@ -19,19 +20,18 @@ module.exports = function (logger) {
*/
sheets.getGoogleSheet = async (spreadsheetId, forceUpdate) => {
if (!googleSheets[spreadsheetId] || forceUpdate) {
const doc = new GoogleSpreadsheet(spreadsheetId),
// Authentication using Google Service Account
creds = {
"private_key_id": process.env.GOOGLE_PRIVATE_KEY_ID,
"private_key": process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'),
"client_id": process.env.GOOGLE_CLIENT_ID
},
auth = {
... client_config,
... creds
};
await doc.useServiceAccountAuth(auth);

// Authentication using Google Service Account
const creds = {
"private_key_id": process.env.GOOGLE_PRIVATE_KEY_ID,
"private_key": process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'),
"client_id": process.env.GOOGLE_CLIENT_ID
};
const serviceAccountAuth = auth.fromJSON({
... client_config,
... creds
});
const doc = new GoogleSpreadsheet(spreadsheetId, serviceAccountAuth);

// loads document properties and worksheets
await doc.loadInfo();
googleSheets[spreadsheetId] = doc;
Expand Down
62 changes: 61 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ agent-base@6:
dependencies:
debug "4"

agent-base@^7.0.2:
version "7.1.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.0.tgz#536802b76bc0b34aa50195eb2442276d613e3434"
integrity sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==
dependencies:
debug "^4.3.4"

aggregate-error@^3.1.0:
version "3.1.0"
resolved "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz"
Expand Down Expand Up @@ -918,7 +925,7 @@ [email protected]:
dependencies:
ms "2.0.0"

debug@4:
debug@4, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
Expand Down Expand Up @@ -1329,6 +1336,16 @@ gaxios@^4.0.0:
is-stream "^2.0.0"
node-fetch "^2.6.7"

gaxios@^6.0.0, gaxios@^6.1.1:
version "6.3.0"
resolved "https://registry.yarnpkg.com/gaxios/-/gaxios-6.3.0.tgz#5cd858de47c6560caaf0f99bb5d89c5bdfbe9034"
integrity sha512-p+ggrQw3fBwH2F5N/PAI4k/G/y1art5OxKpb2J2chwNNHM4hHuAOtivjPuirMF4KNKwTTUal/lPfL2+7h2mEcg==
dependencies:
extend "^3.0.2"
https-proxy-agent "^7.0.1"
is-stream "^2.0.0"
node-fetch "^2.6.9"

gcp-metadata@^4.2.0:
version "4.3.1"
resolved "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-4.3.1.tgz"
Expand All @@ -1337,6 +1354,14 @@ gcp-metadata@^4.2.0:
gaxios "^4.0.0"
json-bigint "^1.0.0"

gcp-metadata@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/gcp-metadata/-/gcp-metadata-6.1.0.tgz#9b0dd2b2445258e7597f2024332d20611cbd6b8c"
integrity sha512-Jh/AIwwgaxan+7ZUUmRLCjtchyDiqh4KjBJ5tW3plBZb5iL/BPcso8A5DlzeD9qlw0duCamnNdpFjxwaT0KyKg==
dependencies:
gaxios "^6.0.0"
json-bigint "^1.0.0"

get-caller-file@^2.0.5:
version "2.0.5"
resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz"
Expand Down Expand Up @@ -1406,6 +1431,18 @@ google-auth-library@^7.0.2, google-auth-library@^7.14.0:
jws "^4.0.0"
lru-cache "^6.0.0"

google-auth-library@^9.7.0:
version "9.7.0"
resolved "https://registry.yarnpkg.com/google-auth-library/-/google-auth-library-9.7.0.tgz#dd99a08e2e3f70778de8be4ed8556460e237550a"
integrity sha512-I/AvzBiUXDzLOy4iIZ2W+Zq33W4lcukQv1nl7C8WUA6SQwyQwUwu3waNmWNAvzds//FG8SZ+DnKnW/2k6mQS8A==
dependencies:
base64-js "^1.3.0"
ecdsa-sig-formatter "^1.0.11"
gaxios "^6.1.1"
gcp-metadata "^6.1.0"
gtoken "^7.0.0"
jws "^4.0.0"

google-p12-pem@^3.1.3:
version "3.1.4"
resolved "https://registry.yarnpkg.com/google-p12-pem/-/google-p12-pem-3.1.4.tgz#123f7b40da204de4ed1fbf2fd5be12c047fc8b3b"
Expand Down Expand Up @@ -1462,6 +1499,14 @@ gtoken@^5.0.4:
google-p12-pem "^3.1.3"
jws "^4.0.0"

gtoken@^7.0.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/gtoken/-/gtoken-7.1.0.tgz#d61b4ebd10132222817f7222b1e6064bd463fc26"
integrity sha512-pCcEwRi+TKpMlxAQObHDQ56KawURgyAf6jtIY046fJ5tIv3zDe/LEIubckAO8fj6JnAxLdmWkUfNyulQ2iKdEw==
dependencies:
gaxios "^6.0.0"
jws "^4.0.0"

has-bigints@^1.0.1, has-bigints@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/has-bigints/-/has-bigints-1.0.2.tgz#0871bd3e3d51626f6ca0966668ba35d5602d6eaa"
Expand Down Expand Up @@ -1532,6 +1577,14 @@ https-proxy-agent@^5.0.0:
agent-base "6"
debug "4"

https-proxy-agent@^7.0.1:
version "7.0.4"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz#8e97b841a029ad8ddc8731f26595bad868cb4168"
integrity sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==
dependencies:
agent-base "^7.0.2"
debug "4"

[email protected]:
version "0.4.24"
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz"
Expand Down Expand Up @@ -2086,6 +2139,13 @@ [email protected], node-fetch@^2.0, node-fetch@^2.6.7:
dependencies:
whatwg-url "^5.0.0"

node-fetch@^2.6.9:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"

node-forge@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3"
Expand Down

0 comments on commit 7380c28

Please sign in to comment.