diff --git a/dist/alks.js b/dist/alks.js index dd9b2ec3..f60681ea 100644 --- a/dist/alks.js +++ b/dist/alks.js @@ -75,7 +75,7 @@ var alks = (function () { 'Content-Type': 'application/json' }; if (opts.accessToken) { - headers['Authorize'] = "Bearer " + (opts.accessToken); + headers['Authorization'] = "Bearer " + (opts.accessToken); delete opts.accessToken; } if (opts.userid || opts.password) { diff --git a/dist/alks.min.js b/dist/alks.min.js index 1a2da24d..1c9f94d3 100644 --- a/dist/alks.min.js +++ b/dist/alks.min.js @@ -1 +1 @@ -var alks=function(){"use strict";var n=window.fetch.bind(window),t=function(e,t){void 0===t&&(t={}),this.defaults=Object.assign({},t,{_fetch:n},e)};t.prototype.create=function(e){return new t(e,this.defaults)},t.prototype.getAccounts=function(e){return this._doFetch("getAccounts",e).then(function(t){return Object.keys(t.accountListRole).map(function(e){return{account:e,role:t.accountListRole[e][0].role,iamKeyActive:t.accountListRole[e][0].iamKeyActive}})})},t.prototype.getKeys=function(e){return this._doFetch("getKeys",e).then(function(e){return r(e,["accessKey","secretKey","sessionToken"])})},t.prototype.getIAMKeys=function(e){return this._doFetch("getIAMKeys",e).then(function(e){return r(e,["accessKey","secretKey","sessionToken"])})},t.prototype.getAWSRoleTypes=function(e){return this._doFetch("getAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.getNonServiceAWSRoleTypes=function(e){return this._doFetch("getNonServiceAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.createRole=function(e){return this._doFetch("createRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),r(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.createNonServiceRole=function(e){return this._doFetch("createNonServiceRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),r(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.listAWSAccountRoles=function(e){return this._doFetch("listAWSAccountRoles",e).then(function(e){return JSON.parse(e.jsonAWSRoleList).map(function(e){return e.split("/").slice(-1)[0]})})},t.prototype.getAccountRole=function(t){return this._doFetch("getAccountRole",t).then(function(e){if(!e.roleExists)throw new Error("Role "+t.roleName+" does not exist in this account");return e.roleARN})},t.prototype.deleteRole=function(e){return this._doFetch("deleteRole",e).then(function(){return!0})},t.prototype.createAccessKeys=function(e){return this._doFetch("accessKeys",e).then(function(e){return r(e,["iamUserArn","accessKey","secretKey","addedIAMUserToGroup"])})},t.prototype.deleteIAMUser=function(e){return this._doFetch("IAMUser",e,"DELETE").then(function(){return!0})},t.prototype._doFetch=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n="POST");var r=Object.assign({},this.defaults,t),o={"Content-Type":"application/json"};r.accessToken&&(o.Authorize="Bearer "+r.accessToken,delete r.accessToken),(r.userid||r.password)&&console.error("The userid and password properties are deprecated and should be replaced with an access token");var s=r._fetch(r.baseUrl+"/"+e+"/",{method:n,headers:o,body:JSON.stringify(r)}),c=s.then(function(e){return e.json()}).catch(function(){});return Promise.all([s,c]).then(function(e){var t=e[0],n=e[1];if(!t.ok)throw n&&n.statusMessage&&"Success"!==n.statusMessage?new Error(n.statusMessage):n&&n.errors&&n.errors.length?new Error(n.errors[0]):new Error(t.statusText);return n})};var r=function(n,e){return e.reduce(function(e,t){return e[t]=n[t],e},{})};return new t}(); +var alks=function(){"use strict";var n=window.fetch.bind(window),t=function(e,t){void 0===t&&(t={}),this.defaults=Object.assign({},t,{_fetch:n},e)};t.prototype.create=function(e){return new t(e,this.defaults)},t.prototype.getAccounts=function(e){return this._doFetch("getAccounts",e).then(function(t){return Object.keys(t.accountListRole).map(function(e){return{account:e,role:t.accountListRole[e][0].role,iamKeyActive:t.accountListRole[e][0].iamKeyActive}})})},t.prototype.getKeys=function(e){return this._doFetch("getKeys",e).then(function(e){return r(e,["accessKey","secretKey","sessionToken"])})},t.prototype.getIAMKeys=function(e){return this._doFetch("getIAMKeys",e).then(function(e){return r(e,["accessKey","secretKey","sessionToken"])})},t.prototype.getAWSRoleTypes=function(e){return this._doFetch("getAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.getNonServiceAWSRoleTypes=function(e){return this._doFetch("getNonServiceAWSRoleTypes",e).then(function(e){return JSON.parse(e.roleTypes)})},t.prototype.createRole=function(e){return this._doFetch("createRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),r(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.createNonServiceRole=function(e){return this._doFetch("createNonServiceRole",e).then(function(e){return e.denyArns=e.denyArns.split(","),r(e,["roleArn","denyArns","instanceProfileArn","addedRoleToInstanceProfile"])})},t.prototype.listAWSAccountRoles=function(e){return this._doFetch("listAWSAccountRoles",e).then(function(e){return JSON.parse(e.jsonAWSRoleList).map(function(e){return e.split("/").slice(-1)[0]})})},t.prototype.getAccountRole=function(t){return this._doFetch("getAccountRole",t).then(function(e){if(!e.roleExists)throw new Error("Role "+t.roleName+" does not exist in this account");return e.roleARN})},t.prototype.deleteRole=function(e){return this._doFetch("deleteRole",e).then(function(){return!0})},t.prototype.createAccessKeys=function(e){return this._doFetch("accessKeys",e).then(function(e){return r(e,["iamUserArn","accessKey","secretKey","addedIAMUserToGroup"])})},t.prototype.deleteIAMUser=function(e){return this._doFetch("IAMUser",e,"DELETE").then(function(){return!0})},t.prototype._doFetch=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n="POST");var r=Object.assign({},this.defaults,t),o={"Content-Type":"application/json"};r.accessToken&&(o.Authorization="Bearer "+r.accessToken,delete r.accessToken),(r.userid||r.password)&&console.error("The userid and password properties are deprecated and should be replaced with an access token");var s=r._fetch(r.baseUrl+"/"+e+"/",{method:n,headers:o,body:JSON.stringify(r)}),c=s.then(function(e){return e.json()}).catch(function(){});return Promise.all([s,c]).then(function(e){var t=e[0],n=e[1];if(!t.ok)throw n&&n.statusMessage&&"Success"!==n.statusMessage?new Error(n.statusMessage):n&&n.errors&&n.errors.length?new Error(n.errors[0]):new Error(t.statusText);return n})};var r=function(n,e){return e.reduce(function(e,t){return e[t]=n[t],e},{})};return new t}(); diff --git a/lib/alks.node.js b/lib/alks.node.js index c07bd170..b0ed3d52 100644 --- a/lib/alks.node.js +++ b/lib/alks.node.js @@ -393,7 +393,7 @@ class alks { }; if (opts.accessToken) { - headers['Authorize'] = `Bearer ${opts.accessToken}`; + headers['Authorization'] = `Bearer ${opts.accessToken}`; delete opts.accessToken; } diff --git a/package-lock.json b/package-lock.json index 89ebc42e..8ded83e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "alks.js", - "version": "0.1.2", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/alks.js b/src/alks.js index e7926333..619fcec2 100755 --- a/src/alks.js +++ b/src/alks.js @@ -391,7 +391,7 @@ class alks { } if (opts.accessToken) { - headers['Authorize'] = `Bearer ${opts.accessToken}` + headers['Authorization'] = `Bearer ${opts.accessToken}` delete opts.accessToken }