mirror of
https://github.com/aws-actions/configure-aws-credentials.git
synced 2026-09-02 05:55:10 +09:00
Add initial implementation
This commit is contained in:
committed by
Clare Liguori
parent
6c5c32e279
commit
bb4ecd82fd
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"commonjs": true,
|
||||||
|
"es6": true,
|
||||||
|
"node": true,
|
||||||
|
"jest": true
|
||||||
|
},
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"globals": {
|
||||||
|
"Atomics": "readonly",
|
||||||
|
"SharedArrayBuffer": "readonly"
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2018
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
}
|
||||||
|
}
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
# comment this out distribution branches
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Editors
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Other Dependency directories
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# next.js build output
|
||||||
|
.next
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
name: 'Setup AWS'
|
||||||
|
description: 'Setup an AWS CLI compatible environment'
|
||||||
|
inputs:
|
||||||
|
aws-access-key-id:
|
||||||
|
description: 'Your AWS access key id credential'
|
||||||
|
required: true
|
||||||
|
aws-secret-access-key:
|
||||||
|
description: 'Your AWS secret access key credential'
|
||||||
|
required: true
|
||||||
|
aws-default-region:
|
||||||
|
description: 'Default AWS region, e.g. us-east-2'
|
||||||
|
required: true
|
||||||
|
aws-default-output:
|
||||||
|
description: 'Default output format, e.g. json'
|
||||||
|
required: false
|
||||||
|
default: json
|
||||||
|
runs:
|
||||||
|
using: 'node12'
|
||||||
|
main: 'dist/index.js'
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
const io = require('@actions/io');
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
try {
|
||||||
|
// Get inputs
|
||||||
|
const accessKeyId = core.getInput('aws-access-key-id', { required: true });
|
||||||
|
const secretAccessKey = core.getInput('aws-secret-access-key', { required: true });
|
||||||
|
const defaultRegion = core.getInput('aws-default-region', { required: true });
|
||||||
|
const outputFormat = core.getInput('aws-default-output', { required: false });
|
||||||
|
const awsHome = path.join(process.env.RUNNER_TEMP, '.aws');
|
||||||
|
|
||||||
|
// Ensure awsHome is a directory that exists
|
||||||
|
await io.mkdirP(awsHome);
|
||||||
|
|
||||||
|
// Configure the AWS CLI using environment variables
|
||||||
|
|
||||||
|
// AWS_ACCESS_KEY_ID:
|
||||||
|
// Specifies an AWS access key associated with an IAM user or role
|
||||||
|
core.exportVariable('AWS_ACCESS_KEY_ID', accessKeyId);
|
||||||
|
|
||||||
|
// AWS_SECRET_ACCESS_KEY:
|
||||||
|
// Specifies the secret key associated with the access key. This is essentially the "password" for the access key.
|
||||||
|
core.exportVariable('AWS_SECRET_ACCESS_KEY', secretAccessKey);
|
||||||
|
|
||||||
|
// AWS_DEFAULT_REGION:
|
||||||
|
// Specifies the AWS Region to send requests to
|
||||||
|
core.exportVariable('AWS_DEFAULT_REGION', defaultRegion);
|
||||||
|
|
||||||
|
// AWS_DEFAULT_OUTPUT:
|
||||||
|
// Specifies the output format to use
|
||||||
|
core.exportVariable('AWS_DEFAULT_OUTPUT', outputFormat);
|
||||||
|
|
||||||
|
// AWS_CONFIG_FILE:
|
||||||
|
// Specifies the location of the file that the AWS CLI uses to store configuration profiles.
|
||||||
|
core.exportVariable('AWS_CONFIG_FILE', path.join(awsHome, 'config'));
|
||||||
|
|
||||||
|
// AWS_SHARED_CREDENTIALS_FILE:
|
||||||
|
// Specifies the location of the file that the AWS CLI uses to store access keys.
|
||||||
|
core.exportVariable('AWS_SHARED_CREDENTIALS_FILE', path.join(awsHome, 'credentials'));
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.setFailed(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = run;
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
const core = require('@actions/core');
|
||||||
|
const io = require('@actions/io');
|
||||||
|
|
||||||
|
const run = require('.');
|
||||||
|
|
||||||
|
jest.mock('@actions/core');
|
||||||
|
jest.mock('@actions/io');
|
||||||
|
|
||||||
|
describe('Setup AWS', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('MY-AWS-ACCESS-KEY-ID') // aws-access-key-id
|
||||||
|
.mockReturnValueOnce('MY-AWS-SECRET-ACCESS-KEY') // aws-secret-access-key
|
||||||
|
.mockReturnValueOnce('us-east-2') // aws-default-region
|
||||||
|
.mockReturnValueOnce('json'); // aws-default-output
|
||||||
|
});
|
||||||
|
|
||||||
|
test('exports env vars', async () => {
|
||||||
|
await run();
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledTimes(6);
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'MY-AWS-ACCESS-KEY-ID');
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'MY-AWS-SECRET-ACCESS-KEY');
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_REGION', 'us-east-2');
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_OUTPUT', 'json');
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_CONFIG_FILE', '/runner/home/.aws/config');
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SHARED_CREDENTIALS_FILE', '/runner/home/.aws/credentials');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('aws can be configured for a different region', async () => {
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('MY-AWS-ACCESS-KEY-ID') // aws-access-key-id
|
||||||
|
.mockReturnValueOnce('MY-AWS-SECRET-ACCESS-KEY') // aws-secret-access-key
|
||||||
|
.mockReturnValueOnce('eu-west-1') // aws-default-region
|
||||||
|
.mockReturnValueOnce('json'); // aws-default-output
|
||||||
|
|
||||||
|
await run();
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_REGION', 'eu-west-1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('error is caught by core.setFailed', async () => {
|
||||||
|
io.mkdirP = jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation(() => {
|
||||||
|
throw new Error();
|
||||||
|
});
|
||||||
|
|
||||||
|
await run();
|
||||||
|
|
||||||
|
expect(core.setFailed).toBeCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
testEnvironment: 'node',
|
||||||
|
setupFiles: ['./jest.setup-env.js']
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
process.env.RUNNER_TEMP = '/runner/home';
|
||||||
Generated
+5360
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"name": "setup-aws",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "Setup AWS",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"lint": "eslint **.js",
|
||||||
|
"package": "ncc build index.js -o dist",
|
||||||
|
"test": "eslint **.js && jest --coverage"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/aws/setup-aws.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"AWS",
|
||||||
|
"GitHub",
|
||||||
|
"Actions",
|
||||||
|
"JavaScript"
|
||||||
|
],
|
||||||
|
"author": "GitHub",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/aws/setup-aws/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/aws/setup-aws#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.2.0",
|
||||||
|
"@actions/exec": "^1.0.1",
|
||||||
|
"@actions/io": "^1.0.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@zeit/ncc": "^0.20.5",
|
||||||
|
"eslint": "^6.5.1",
|
||||||
|
"jest": "^24.9.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user