Skip to content

Simply tool for extracting and editing the .aws/credentials

License

Notifications You must be signed in to change notification settings

rmtuckerphx/aws-profile-handler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-profile-handler

Simply tool for extracting and editing the .aws/credentials. You can add, get, list, and delete profile(s) synchronously, no 3p dependencies introduced.

Build Status Coverage Status GitHub license GitHub issues Maintainability dependencies Status npm version

How do I install it?

Install it into your package

npm install aws-profile-handler --save

Add a profile

let valid_credential_object = {
        "aws_access_key_id": "123",
        "aws_secret_access_key": "456"
};

let awsProfiler = require('aws-profile-handler');

// AWS credentials file path is optional as the last parameter. Default to ~/.aws/credentials
awsProfiler.addProfile('awesomeProfileName', valid_credential_object); 
awsProfiler.addProfile('awesomeProfileName', valid_credential_object, 'file/path/to/aws/credentials'); 


// .aws/credentials 
[awesomeProfileName]
aws_access_key_id=123
aws_secret_access_key=456

Get a profile's credentials

let awsProfiler = require('aws-profile-handler');

// AWS credentials file path is optional as the last parameter. Default to ~/.aws/credentials
awsProfiler.getProfileCredentials('awesomeProfileName');
awsProfiler.getProfileCredentials('awesomeProfileName', 'file/path/to/aws/credentials');


// return 'null' if profile doesn't exist
// return an object with 'aws_access_key_id' and 'aws_access_key_id'
{
    "aws_access_key_id": "123",
    "aws_secret_access_key": "456"
}

List profiles

let awsProfiler = require('aws-profile-handler');

// AWS credentials file path is optional as the last parameter. Default to ~/.aws/credentials
awsProfiler.listProfiles();
awsProfiler.listProfiles('file/path/to/aws/credentials');

// return a list of all the profiles' name
// ['awesomeProfileName', 'something', 'else', 'if', 'exists'];

Delete a profile

let awsProfiler = require('aws-profile-handler');

// AWS credentials file path is optional as the last parameter. Default to ~/.aws/credentials
awsProfiler.deleteProfile('lameProfileName');
awsProfiler.deleteProfile('lameProfileName', 'file/path/to/aws/credentials');

Error

Four customized errors would be thrown.

  1. If format is invalid.
// error.message:
'Invalid AWS credential file. Cannot have nested sessions'
  1. If one or more values are missing.
// .aws/credentials
[badProfile]
aws_access_key_id=
aws_secret_access_key=idIsMissing

// error.message
'Invalid AWS credential file. Incomplete key/value pair'
  1. If input credentials object is invalid.
let missingOneKey = {
    aws_access_key_id: 1
}

let haveOneExtraKey = {
    aws_access_key_id: 1,
    aws_secret_access_key: 2,
    extra: 3
}

let wrongName = {
    aws_secret_access_key: 2,
    extra: 3
}

// error.message
'Invalid input: credentials schema is invalid.'
  1. If require input parameters are missing.
awsProfileHandler.addProfile();
// error.message
'Invalid Input: profile name cannot be omitted nor only contains white spaces.'

awsProfileHandler.addProfile('profile');
// error.message
'Invalid Input: credentials cannot be omitted nor empty.'

Note:

Version 1.X.X is deprecated, the last V1 update was 1.1.0.

About

Simply tool for extracting and editing the .aws/credentials

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%