chipchat-tokens-to-google-secretmanager-mixin
Advanced tools
Comparing version 1.5.0 to 1.5.1
{ | ||
"name": "chipchat-tokens-to-google-secretmanager-mixin", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -10,6 +10,5 @@ # Store Authentication tokens of ChatShipper in Google Cloud Secret Storage | ||
These tokens expire though. And altough the chipchat sdk will automatically refresh the tokens for you, | ||
when the access token expires, the sdk will request new tokens with the refreshToken, | ||
it only remembers those tokens while the app is running. When you restart it will use the tokens | ||
you passed to the initilialization process again. Which will work as long as the refreshToken is valid, which is a month (at the moment) | ||
These tokens expire though. And altough the chipchat sdk will automatically refresh the tokens for you when the access token expires, | ||
it only remembers those new tokens while the app is running. When you restart it will use the old tokens again that | ||
you passed to the initilialization process. Which will work as long as the refreshToken is valid, which is a month (at the moment) | ||
@@ -21,3 +20,3 @@ So you need some way to store the (new) tokens somewhere **save** and reuse them. Tokens give access and should be kept very save. | ||
This package uses the Google Secret Manager to store the tokens. It idoes so by overwriting the special **chipchat** functions **getTokens** and **setTokens** via a mixin to add the store to google secrets functionality. | ||
This package uses the Google Secret Manager to store the tokens. It does so by overwriting the special **chipchat** functions **getTokens** and **setTokens** via a mixin to add the store to google secrets functionality. | ||
@@ -45,2 +44,4 @@ You need to have basic understandings of the Google platform and have your service account file with sufficient rights to the project stored locally. | ||
or even easier while in the cs2-bots/bot dir call the **scripts/addsecret** script. | ||
Now that you have got you tokens in the store, lets use them via the mixin module like this: | ||
@@ -65,3 +66,2 @@ ```js | ||
``` | ||
> test.js | ||
@@ -68,0 +68,0 @@ install the needed packages and test with node version 10 (use **nvm**) or higher: |
@@ -86,6 +86,7 @@ const debug = require('debug'); | ||
} | ||
}).then(async ([newsecret]) => { | ||
}).then(async (newsecret) => { | ||
// cleanup old secret versions | ||
if (newsecret) { | ||
log('setTokens: new secret version', newsecret.name); | ||
if (newsecret && newsecret[0]) { | ||
const newsecretversion = newsecret[0]; | ||
log('setTokens: new secret version', newsecretversion.name); | ||
const [versions] = await client.listSecretVersions({ | ||
@@ -96,3 +97,3 @@ parent: `${storename}/${tokenid}_tokens` | ||
for await (const version of versions) { | ||
if (version.name !== newsecret.name && version.state === 'ENABLED') { | ||
if (version.name !== newsecretversion.name && version.state === 'ENABLED') { | ||
log(`setTokens: removing old token version ${version.name}`); | ||
@@ -99,0 +100,0 @@ await client.destroySecretVersion({ name: version.name }); |
12795
159