@aws-sdk/credential-provider-process
Advanced tools
Comparing version 3.183.0 to 3.186.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06) | ||
**Note:** Version bump only for package @aws-sdk/credential-provider-process | ||
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03) | ||
@@ -8,0 +16,0 @@ |
@@ -0,6 +1,17 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { getProfileName, parseKnownFiles } from "@aws-sdk/shared-ini-file-loader"; | ||
import { resolveProcessCredentials } from "./resolveProcessCredentials"; | ||
export const fromProcess = (init = {}) => async () => { | ||
const profiles = await parseKnownFiles(init); | ||
return resolveProcessCredentials(getProfileName(init), profiles); | ||
export var fromProcess = function (init) { | ||
if (init === void 0) { init = {}; } | ||
return function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var profiles; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, parseKnownFiles(init)]; | ||
case 1: | ||
profiles = _a.sent(); | ||
return [2, resolveProcessCredentials(getProfileName(init), profiles)]; | ||
} | ||
}); | ||
}); }; | ||
}; |
@@ -1,21 +0,17 @@ | ||
export const getValidatedProcessCredentials = (profileName, data) => { | ||
import { __assign } from "tslib"; | ||
export var getValidatedProcessCredentials = function (profileName, data) { | ||
if (data.Version !== 1) { | ||
throw Error(`Profile ${profileName} credential_process did not return Version 1.`); | ||
throw Error("Profile ".concat(profileName, " credential_process did not return Version 1.")); | ||
} | ||
if (data.AccessKeyId === undefined || data.SecretAccessKey === undefined) { | ||
throw Error(`Profile ${profileName} credential_process returned invalid credentials.`); | ||
throw Error("Profile ".concat(profileName, " credential_process returned invalid credentials.")); | ||
} | ||
if (data.Expiration) { | ||
const currentTime = new Date(); | ||
const expireTime = new Date(data.Expiration); | ||
var currentTime = new Date(); | ||
var expireTime = new Date(data.Expiration); | ||
if (expireTime < currentTime) { | ||
throw Error(`Profile ${profileName} credential_process returned expired credentials.`); | ||
throw Error("Profile ".concat(profileName, " credential_process returned expired credentials.")); | ||
} | ||
} | ||
return { | ||
accessKeyId: data.AccessKeyId, | ||
secretAccessKey: data.SecretAccessKey, | ||
...(data.SessionToken && { sessionToken: data.SessionToken }), | ||
...(data.Expiration && { expiration: new Date(data.Expiration) }), | ||
}; | ||
return __assign(__assign({ accessKeyId: data.AccessKeyId, secretAccessKey: data.SecretAccessKey }, (data.SessionToken && { sessionToken: data.SessionToken })), (data.Expiration && { expiration: new Date(data.Expiration) })); | ||
}; |
@@ -0,1 +1,2 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { CredentialsProviderError } from "@aws-sdk/property-provider"; | ||
@@ -5,30 +6,36 @@ import { exec } from "child_process"; | ||
import { getValidatedProcessCredentials } from "./getValidatedProcessCredentials"; | ||
export const resolveProcessCredentials = async (profileName, profiles) => { | ||
const profile = profiles[profileName]; | ||
if (profiles[profileName]) { | ||
const credentialProcess = profile["credential_process"]; | ||
if (credentialProcess !== undefined) { | ||
const execPromise = promisify(exec); | ||
try { | ||
const { stdout } = await execPromise(credentialProcess); | ||
let data; | ||
export var resolveProcessCredentials = function (profileName, profiles) { return __awaiter(void 0, void 0, void 0, function () { | ||
var profile, credentialProcess, execPromise, stdout, data, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
profile = profiles[profileName]; | ||
if (!profiles[profileName]) return [3, 7]; | ||
credentialProcess = profile["credential_process"]; | ||
if (!(credentialProcess !== undefined)) return [3, 5]; | ||
execPromise = promisify(exec); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4, execPromise(credentialProcess)]; | ||
case 2: | ||
stdout = (_a.sent()).stdout; | ||
data = void 0; | ||
try { | ||
data = JSON.parse(stdout.trim()); | ||
} | ||
catch { | ||
throw Error(`Profile ${profileName} credential_process returned invalid JSON.`); | ||
catch (_b) { | ||
throw Error("Profile ".concat(profileName, " credential_process returned invalid JSON.")); | ||
} | ||
return getValidatedProcessCredentials(profileName, data); | ||
} | ||
catch (error) { | ||
throw new CredentialsProviderError(error.message); | ||
} | ||
return [2, getValidatedProcessCredentials(profileName, data)]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
throw new CredentialsProviderError(error_1.message); | ||
case 4: return [3, 6]; | ||
case 5: throw new CredentialsProviderError("Profile ".concat(profileName, " did not contain credential_process.")); | ||
case 6: return [3, 8]; | ||
case 7: throw new CredentialsProviderError("Profile ".concat(profileName, " could not be found in shared credentials file.")); | ||
case 8: return [2]; | ||
} | ||
else { | ||
throw new CredentialsProviderError(`Profile ${profileName} did not contain credential_process.`); | ||
} | ||
} | ||
else { | ||
throw new CredentialsProviderError(`Profile ${profileName} could not be found in shared credentials file.`); | ||
} | ||
}; | ||
}); | ||
}); }; |
{ | ||
"name": "@aws-sdk/credential-provider-process", | ||
"version": "3.183.0", | ||
"version": "3.186.0", | ||
"description": "AWS credential provider that sources credential_process from ~/.aws/credentials and ~/.aws/config", | ||
@@ -27,5 +27,5 @@ "main": "./dist-cjs/index.js", | ||
"dependencies": { | ||
"@aws-sdk/property-provider": "3.183.0", | ||
"@aws-sdk/shared-ini-file-loader": "3.183.0", | ||
"@aws-sdk/types": "3.183.0", | ||
"@aws-sdk/property-provider": "3.186.0", | ||
"@aws-sdk/shared-ini-file-loader": "3.186.0", | ||
"@aws-sdk/types": "3.186.0", | ||
"tslib": "^2.3.1" | ||
@@ -32,0 +32,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54049
201
+ Added@aws-sdk/property-provider@3.186.0(transitive)
+ Added@aws-sdk/shared-ini-file-loader@3.186.0(transitive)
+ Added@aws-sdk/types@3.186.0(transitive)
- Removed@aws-sdk/property-provider@3.183.0(transitive)
- Removed@aws-sdk/shared-ini-file-loader@3.183.0(transitive)
- Removed@aws-sdk/types@3.183.0(transitive)
Updated@aws-sdk/types@3.186.0