@aws-sdk/credential-provider-process 3.901.0 → 3.906.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist-cjs/index.js +71 -107
  2. package/package.json +2 -2
package/dist-cjs/index.js CHANGED
@@ -1,115 +1,79 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- fromProcess: () => fromProcess
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
-
28
- // src/fromProcess.ts
1
+ 'use strict';
29
2
 
3
+ var sharedIniFileLoader = require('@smithy/shared-ini-file-loader');
4
+ var propertyProvider = require('@smithy/property-provider');
5
+ var child_process = require('child_process');
6
+ var util = require('util');
7
+ var client = require('@aws-sdk/core/client');
30
8
 
31
- // src/resolveProcessCredentials.ts
32
- var import_property_provider = require("@smithy/property-provider");
33
- var import_shared_ini_file_loader = require("@smithy/shared-ini-file-loader");
34
- var import_child_process = require("child_process");
35
- var import_util = require("util");
36
-
37
- // src/getValidatedProcessCredentials.ts
38
- var import_client = require("@aws-sdk/core/client");
39
- var getValidatedProcessCredentials = /* @__PURE__ */ __name((profileName, data, profiles) => {
40
- if (data.Version !== 1) {
41
- throw Error(`Profile ${profileName} credential_process did not return Version 1.`);
42
- }
43
- if (data.AccessKeyId === void 0 || data.SecretAccessKey === void 0) {
44
- throw Error(`Profile ${profileName} credential_process returned invalid credentials.`);
45
- }
46
- if (data.Expiration) {
47
- const currentTime = /* @__PURE__ */ new Date();
48
- const expireTime = new Date(data.Expiration);
49
- if (expireTime < currentTime) {
50
- throw Error(`Profile ${profileName} credential_process returned expired credentials.`);
9
+ const getValidatedProcessCredentials = (profileName, data, profiles) => {
10
+ if (data.Version !== 1) {
11
+ throw Error(`Profile ${profileName} credential_process did not return Version 1.`);
51
12
  }
52
- }
53
- let accountId = data.AccountId;
54
- if (!accountId && profiles?.[profileName]?.aws_account_id) {
55
- accountId = profiles[profileName].aws_account_id;
56
- }
57
- const credentials = {
58
- accessKeyId: data.AccessKeyId,
59
- secretAccessKey: data.SecretAccessKey,
60
- ...data.SessionToken && { sessionToken: data.SessionToken },
61
- ...data.Expiration && { expiration: new Date(data.Expiration) },
62
- ...data.CredentialScope && { credentialScope: data.CredentialScope },
63
- ...accountId && { accountId }
64
- };
65
- (0, import_client.setCredentialFeature)(credentials, "CREDENTIALS_PROCESS", "w");
66
- return credentials;
67
- }, "getValidatedProcessCredentials");
68
-
69
- // src/resolveProcessCredentials.ts
70
- var resolveProcessCredentials = /* @__PURE__ */ __name(async (profileName, profiles, logger) => {
71
- const profile = profiles[profileName];
72
- if (profiles[profileName]) {
73
- const credentialProcess = profile["credential_process"];
74
- if (credentialProcess !== void 0) {
75
- const execPromise = (0, import_util.promisify)(import_shared_ini_file_loader.externalDataInterceptor?.getTokenRecord?.().exec ?? import_child_process.exec);
76
- try {
77
- const { stdout } = await execPromise(credentialProcess);
78
- let data;
79
- try {
80
- data = JSON.parse(stdout.trim());
81
- } catch {
82
- throw Error(`Profile ${profileName} credential_process returned invalid JSON.`);
13
+ if (data.AccessKeyId === undefined || data.SecretAccessKey === undefined) {
14
+ throw Error(`Profile ${profileName} credential_process returned invalid credentials.`);
15
+ }
16
+ if (data.Expiration) {
17
+ const currentTime = new Date();
18
+ const expireTime = new Date(data.Expiration);
19
+ if (expireTime < currentTime) {
20
+ throw Error(`Profile ${profileName} credential_process returned expired credentials.`);
83
21
  }
84
- return getValidatedProcessCredentials(profileName, data, profiles);
85
- } catch (error) {
86
- throw new import_property_provider.CredentialsProviderError(error.message, { logger });
87
- }
88
- } else {
89
- throw new import_property_provider.CredentialsProviderError(`Profile ${profileName} did not contain credential_process.`, { logger });
90
22
  }
91
- } else {
92
- throw new import_property_provider.CredentialsProviderError(`Profile ${profileName} could not be found in shared credentials file.`, {
93
- logger
94
- });
95
- }
96
- }, "resolveProcessCredentials");
23
+ let accountId = data.AccountId;
24
+ if (!accountId && profiles?.[profileName]?.aws_account_id) {
25
+ accountId = profiles[profileName].aws_account_id;
26
+ }
27
+ const credentials = {
28
+ accessKeyId: data.AccessKeyId,
29
+ secretAccessKey: data.SecretAccessKey,
30
+ ...(data.SessionToken && { sessionToken: data.SessionToken }),
31
+ ...(data.Expiration && { expiration: new Date(data.Expiration) }),
32
+ ...(data.CredentialScope && { credentialScope: data.CredentialScope }),
33
+ ...(accountId && { accountId }),
34
+ };
35
+ client.setCredentialFeature(credentials, "CREDENTIALS_PROCESS", "w");
36
+ return credentials;
37
+ };
97
38
 
98
- // src/fromProcess.ts
99
- var fromProcess = /* @__PURE__ */ __name((init = {}) => async ({ callerClientConfig } = {}) => {
100
- init.logger?.debug("@aws-sdk/credential-provider-process - fromProcess");
101
- const profiles = await (0, import_shared_ini_file_loader.parseKnownFiles)(init);
102
- return resolveProcessCredentials(
103
- (0, import_shared_ini_file_loader.getProfileName)({
104
- profile: init.profile ?? callerClientConfig?.profile
105
- }),
106
- profiles,
107
- init.logger
108
- );
109
- }, "fromProcess");
110
- // Annotate the CommonJS export names for ESM import in node:
39
+ const resolveProcessCredentials = async (profileName, profiles, logger) => {
40
+ const profile = profiles[profileName];
41
+ if (profiles[profileName]) {
42
+ const credentialProcess = profile["credential_process"];
43
+ if (credentialProcess !== undefined) {
44
+ const execPromise = util.promisify(sharedIniFileLoader.externalDataInterceptor?.getTokenRecord?.().exec ?? child_process.exec);
45
+ try {
46
+ const { stdout } = await execPromise(credentialProcess);
47
+ let data;
48
+ try {
49
+ data = JSON.parse(stdout.trim());
50
+ }
51
+ catch {
52
+ throw Error(`Profile ${profileName} credential_process returned invalid JSON.`);
53
+ }
54
+ return getValidatedProcessCredentials(profileName, data, profiles);
55
+ }
56
+ catch (error) {
57
+ throw new propertyProvider.CredentialsProviderError(error.message, { logger });
58
+ }
59
+ }
60
+ else {
61
+ throw new propertyProvider.CredentialsProviderError(`Profile ${profileName} did not contain credential_process.`, { logger });
62
+ }
63
+ }
64
+ else {
65
+ throw new propertyProvider.CredentialsProviderError(`Profile ${profileName} could not be found in shared credentials file.`, {
66
+ logger,
67
+ });
68
+ }
69
+ };
111
70
 
112
- 0 && (module.exports = {
113
- fromProcess
114
- });
71
+ const fromProcess = (init = {}) => async ({ callerClientConfig } = {}) => {
72
+ init.logger?.debug("@aws-sdk/credential-provider-process - fromProcess");
73
+ const profiles = await sharedIniFileLoader.parseKnownFiles(init);
74
+ return resolveProcessCredentials(sharedIniFileLoader.getProfileName({
75
+ profile: init.profile ?? callerClientConfig?.profile,
76
+ }), profiles, init.logger);
77
+ };
115
78
 
79
+ exports.fromProcess = fromProcess;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/credential-provider-process",
3
- "version": "3.901.0",
3
+ "version": "3.906.0",
4
4
  "description": "AWS credential provider that sources credential_process from ~/.aws/credentials and ~/.aws/config",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "license": "Apache-2.0",
28
28
  "dependencies": {
29
- "@aws-sdk/core": "3.901.0",
29
+ "@aws-sdk/core": "3.906.0",
30
30
  "@aws-sdk/types": "3.901.0",
31
31
  "@smithy/property-provider": "^4.2.0",
32
32
  "@smithy/shared-ini-file-loader": "^4.3.0",