-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from leighton-digital:SM-12
SM-12
- Loading branch information
Showing
4 changed files
with
79 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ on: | |
|
||
env: | ||
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }} | ||
MAJOR_VERSION: ${{ secrets.MAJOR_VERSION }} | ||
|
||
jobs: | ||
publish: | ||
|
@@ -21,7 +22,7 @@ jobs: | |
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 'latest' | ||
node-version: '18' | ||
|
||
- name: Install dependencies | ||
run: npm ci --prefer-offline | ||
|
@@ -55,11 +56,11 @@ jobs: | |
PATCH_VERSION=0 | ||
fi | ||
FULL_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION" | ||
echo "::set-output name=tag::$FULL_VERSION" | ||
echo "FULL_VERSION=$FULL_VERSION" >> $GITHUB_ENV | ||
- name: Tag the new version | ||
run: | | ||
git tag ${{ steps.version.outputs.tag }} | ||
git tag ${{ env.FULL_VERSION }} | ||
git push https://[email protected]/${{ github.repository }} --tags | ||
- name: Configure .npmrc for GitHub Packages | ||
|
@@ -68,4 +69,6 @@ jobs: | |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.DEPLOY_TOKEN }}" >> .npmrc | ||
- name: Publish to GitHub Packages | ||
run: npm publish | ||
run: npm publish --access public | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,77 @@ | ||
const Redis = require('ioredis'); | ||
const AWS = require('aws-sdk'); | ||
const logger = require('../logging/logger'); | ||
const apm = require('elastic-apm-node'); | ||
|
||
const redisClient = new Redis({ | ||
host: process.env.REDIS_HOST, | ||
port: process.env.REDIS_PORT, | ||
password: process.env.REDIS_PASSWORD, | ||
}); | ||
const region = process.env.AWS_REGION; | ||
const secretId = process.env.REDIS_SECRET_ID; | ||
|
||
redisClient.on('connect', () => { | ||
logger.info('Connected to Redis'); | ||
apm.setCustomContext({ message: 'Connected to Redis' }); | ||
const sts = new AWS.STS({ | ||
region: region | ||
}); | ||
|
||
redisClient.on('error', (err) => { | ||
logger.error('Redis error:', err); | ||
apm.captureError(err); | ||
}); | ||
|
||
module.exports = redisClient; | ||
async function assumeRole() { | ||
const token = fs.readFileSync(tokenFile, 'utf8'); | ||
|
||
const params = { | ||
RoleArn: roleArn, | ||
RoleSessionName: 'web-identity-session', | ||
WebIdentityToken: token | ||
}; | ||
|
||
const data = await sts.assumeRoleWithWebIdentity(params).promise(); | ||
return { | ||
accessKeyId: data.Credentials.AccessKeyId, | ||
secretAccessKey: data.Credentials.SecretAccessKey, | ||
sessionToken: data.Credentials.SessionToken | ||
}; | ||
} | ||
|
||
async function getRedisCredentials() { | ||
const credentials = await assumeRole(); | ||
const secretsManager = new AWS.SecretsManager({ | ||
region: region, | ||
credentials: credentials, | ||
}); | ||
|
||
try { | ||
const data = await secretsManager.getSecretValue({ SecretId: secretId }).promise(); | ||
if ('SecretString' in data) { | ||
return JSON.parse(data.SecretString); | ||
} else { | ||
const buff = Buffer.from(data.SecretBinary, 'base64'); | ||
return JSON.parse(buff.toString('ascii')); | ||
} | ||
} catch (err) { | ||
logger.error('Error retrieving Redis credentials:', err); | ||
throw err; | ||
} | ||
} | ||
|
||
(async function initializeRedis() { | ||
try { | ||
const redisCredentials = await getRedisCredentials(); | ||
|
||
const redisClient = new Redis({ | ||
host: redisCredentials.endpoint, | ||
port: redisCredentials.port | ||
}); | ||
|
||
redisClient.on('connect', () => { | ||
logger.info('Connected to Redis'); | ||
apm.setCustomContext({ message: 'Connected to Redis' }); | ||
}); | ||
|
||
redisClient.on('error', (err) => { | ||
logger.error('Redis error:', err); | ||
apm.captureError(err); | ||
}); | ||
|
||
module.exports = redisClient; | ||
|
||
} catch (err) { | ||
logger.error('Failed to initialize Redis client:', err); | ||
process.exit(1); | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters