Skip to content

Commit

Permalink
Updating the project tests and dependencies. Adding a deployment to C…
Browse files Browse the repository at this point in the history
…odeArtifact.
  • Loading branch information
richmar10 committed Nov 2, 2023
1 parent 491fdd2 commit ce0a82b
Show file tree
Hide file tree
Showing 8 changed files with 6,169 additions and 213 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CI
on:
pull_request:
push:
branches:
- master
jobs:
tests:
runs-on: [self-hosted, Linux, AWS]
timeout-minutes: 5
steps:
- name: Checkout code
uses: Brightspace/third-party-actions@actions/checkout

- name: Setup node
uses: Brightspace/third-party-actions@actions/setup-node
with:
node-version-file: .nvmrc
cache: npm

- name: Add CodeArtifact npm registry
uses: Brightspace/codeartifact-actions/npm/add-registry@main
with:
auth-token: ${{secrets.CODEARTIFACT_AUTH_TOKEN}}

- name: Install node modules
run: npm ci

- name: Lint and license check
run: |
npm run lint
npm run test:license
- name: Run Tests
run: npm run test
release:
runs-on: [ self-hosted, Linux, AWS ]
timeout-minutes: 10
if: github.ref == 'refs/heads/master'
needs: tests
steps:
- name: Checkout code
uses: Brightspace/third-party-actions@actions/checkout
with:
persist-credentials: false

- name: Setup node
uses: Brightspace/third-party-actions@actions/setup-node
with:
node-version-file: .nvmrc
cache: npm

- name: Add CodeArtifact npm registry
uses: Brightspace/codeartifact-actions/npm/add-registry@main
with:
auth-token: ${{secrets.CODEARTIFACT_AUTH_TOKEN}}

- name: Install node modules
run: npm ci

- name: Lint, License Check and Generate Types
run: |
npm run lint
npm run test:license
- name: Get CodeArtifact Authorization Token
uses: Brightspace/codeartifact-actions/get-authorization-token@main
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}

- name: Semantic Release
uses: BrightspaceUI/actions/semantic-release@main
with:
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.D2L_GITHUB_TOKEN }}
NPM: true
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
152 changes: 76 additions & 76 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
'use strict';

const oauthSignature = require('oauth-signature');
const CryptoJS = require('crypto-js');
const sha1 = require('crypto-js/sha1');
const url = require('url');
const uuid = require('uuid');

module.exports = function(request) {
request.sign = function(creds) {
this.toSign = true;
this.consumerKey = creds.consumerKey;
this.consumerSecret = creds.consumerSecret;
return this;
};

request.hashBody = function() {
this.toHashBody = true;
return this;
};

request.signOAuth = function() {
const oauthHeader = {
oauth_version: '1.0',
oauth_nonce: uuid.v4(),
oauth_timestamp: Math.floor(Date.now() / 1000),
oauth_consumer_key: this.consumerKey,
oauth_signature_method: 'HMAC-SHA1'
};

if (this.toHashBody) {
const stringifiedBody = (typeof this._data !== 'string') ?
JSON.stringify(this._data) : this._data;

oauthHeader.oauth_body_hash = sha1(stringifiedBody).toString(CryptoJS.enc.Base64);
}

const oauthParams = {};
const queryParams = url.parse(this.url, true).query;
for (const attrname of Object.keys(queryParams)) {
oauthParams[attrname] = queryParams[attrname];
}
for (const attrname of Object.keys(oauthHeader)) {
oauthParams[attrname] = oauthHeader[attrname];
}

oauthHeader.oauth_signature = oauthSignature.generate(
this.method,
this.url,
oauthParams,
this.consumerSecret,
'',
{
encodeSignature: false
});

const headerArray = [];
for (const key of Object.keys(oauthHeader)) {
headerArray.push(`${key}="${encodeURIComponent(oauthHeader[key])}"`);
}

this.set('Authorization', `OAuth ${headerArray.join(',')}`);
};

const oldEnd = request.end;

request.end = function() {
this.end = oldEnd;

if (this.toSign) {
this.signOAuth();
}

return this.end.apply(this, arguments);
};
};
'use strict';

const oauthSignature = require('oauth-signature');
const CryptoJS = require('crypto-js');
const sha1 = require('crypto-js/sha1');
const url = require('url');
const uuid = require('uuid');

module.exports = function(request) {
request.sign = function(creds) {
this.toSign = true;
this.consumerKey = creds.consumerKey;
this.consumerSecret = creds.consumerSecret;
return this;
};

request.hashBody = function() {
this.toHashBody = true;
return this;
};

request.signOAuth = function() {
const oauthHeader = {
oauth_version: '1.0',
oauth_nonce: uuid.v4(),
oauth_timestamp: Math.floor(Date.now() / 1000),
oauth_consumer_key: this.consumerKey,
oauth_signature_method: 'HMAC-SHA1'
};

if (this.toHashBody) {
const stringifiedBody = (typeof this._data !== 'string') ?
JSON.stringify(this._data) : this._data;

oauthHeader.oauth_body_hash = sha1(stringifiedBody).toString(CryptoJS.enc.Base64);
}

const oauthParams = {};
const queryParams = url.parse(this.url, true).query;
for (const attrname of Object.keys(queryParams)) {
oauthParams[attrname] = queryParams[attrname];
}
for (const attrname of Object.keys(oauthHeader)) {
oauthParams[attrname] = oauthHeader[attrname];
}

oauthHeader.oauth_signature = oauthSignature.generate(
this.method,
this.url,
oauthParams,
this.consumerSecret,
'',
{
encodeSignature: false
});

const headerArray = [];
for (const key of Object.keys(oauthHeader)) {
headerArray.push(`${key}="${encodeURIComponent(oauthHeader[key])}"`);
}

this.set('Authorization', `OAuth ${headerArray.join(',')}`);
};

const oldEnd = request.end;

request.end = function() {
this.end = oldEnd;

if (this.toSign) {
this.signOAuth();
}

return this.end.apply(this, arguments);
};
};
Loading

0 comments on commit ce0a82b

Please sign in to comment.