Skip to content

Commit

Permalink
workaround for credentials chain issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacobsson committed Aug 16, 2020
1 parent 15cfb0a commit 5dff044
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const os = require("os");
const fs = require("fs");
const path = require("path");
const sha1 = require("sha1");
const storage = require("node-persist");

var iniLoader = AWS.util.iniLoader;

Expand All @@ -16,7 +15,24 @@ AWS.SingleSignOnCredentials = AWS.util.inherit(AWS.Credentials, {
this.filename = options.filename;
this.profile =
options.profile || process.env.AWS_PROFILE || AWS.util.defaultProfile;
this.get(options.callback || AWS.util.fn.noop);
},

init: function(options) {
const filepath =
process.env.AWS_CONFIG_FILE || path.join(os.homedir(), ".aws", "config");
var profiles = AWS.util.getProfilesFromSharedConfig(iniLoader, filepath);
var profile = profiles[this.profile] || {};

if (Object.keys(profile).length === 0) {
throw AWS.util.error(
new Error("Profile " + this.profile + " not found"),
{ code: "ProcessCredentialsProviderFailure" }
);
}
if (profile.sso_start_url) {
AWS.config.update({ credentials: new AWS.SingleSignOnCredentials() });
this.get((options || {}).callback || AWS.util.fn.noop);
}
},

/**
Expand Down Expand Up @@ -60,13 +76,14 @@ AWS.SingleSignOnCredentials = AWS.util.inherit(AWS.Credentials, {
roleName: profile.sso_role_name,
};
if (!request) {
console.log(`Cached credentials not found under ${cachePath}. Please make sure you log in with 'aws sso login' first`);
console.log(
`Cached credentials not found under ${cachePath}. Please make sure you log in with 'aws sso login' first`
);
}
sso.getRoleCredentials(request, (err, c) => {
if (!c) {
console.log(err.message);
console.log("Please log in using 'aws sso login'");

}
self.expired = false;
AWS.util.update(self, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mhlabs/aws-sdk-sso",
"version": "0.0.4",
"version": "0.0.5",
"description": "Credentials provider for AWS Single Sign-On",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 5dff044

Please sign in to comment.