import { g as getProfileName, a as CredentialsProviderError, s as setCredentialFeature } from './role-executor-C4-3bmgC.js';
import { p as parseKnownFiles } from './parseKnownFiles-CJ9mk9wZ.js';
import { e as externalDataInterceptor } from './externalDataInterceptor-C3C4cObe.js';
import { exec } from 'node:child_process';
import { promisify } from 'node:util';
import './paths-2M_UxD_H.js';
import 'node:fs';
import 'node:path';
import 'node:os';
import 'node:events';
import 'node:diagnostics_channel';
import 'fs';
import 'events';
import 'util';
import 'path';
import 'assert';
import 'worker_threads';
import 'module';
import 'node:url';
import 'url';
import 'buffer';
import 'node:module';
import 'node:crypto';
import 'node:process';
import 'node:async_hooks';
import './credential-pool-B04qO8at.js';
import './index-IVoIz4D5.js';
import 'constants';
import 'stream';
import './config-B0nEjgSh.js';
import './json-DXl7iDYg.js';
import './lock-BoHF25mx.js';
import 'node:fs/promises';
import './index-Ca4C2M45.js';
import './role-resolver-DF9BQ_U6.js';
import 'node:stream';
import 'crypto';
import 'os';
import 'node:http2';
import 'fs/promises';
import 'node:net';
import './loadSharedConfigFiles-BEZDzu24.js';
import './readFile-CxwXhymG.js';
import './getSSOTokenFromFile-yZAJxDci.js';

//#region ../../node_modules/.pnpm/@aws-sdk+credential-provider-process@3.972.37/node_modules/@aws-sdk/credential-provider-process/dist-es/getValidatedProcessCredentials.js
var getValidatedProcessCredentials = (profileName, data, profiles) => {
	if (data.Version !== 1) throw Error(`Profile ${profileName} credential_process did not return Version 1.`);
	if (data.AccessKeyId === void 0 || data.SecretAccessKey === void 0) throw Error(`Profile ${profileName} credential_process returned invalid credentials.`);
	if (data.Expiration) {
		const currentTime = /* @__PURE__ */ new Date();
		if (new Date(data.Expiration) < currentTime) throw Error(`Profile ${profileName} credential_process returned expired credentials.`);
	}
	let accountId = data.AccountId;
	if (!accountId && profiles?.[profileName]?.aws_account_id) accountId = profiles[profileName].aws_account_id;
	const credentials = {
		accessKeyId: data.AccessKeyId,
		secretAccessKey: data.SecretAccessKey,
		...data.SessionToken && { sessionToken: data.SessionToken },
		...data.Expiration && { expiration: new Date(data.Expiration) },
		...data.CredentialScope && { credentialScope: data.CredentialScope },
		...accountId && { accountId }
	};
	setCredentialFeature(credentials, "CREDENTIALS_PROCESS", "w");
	return credentials;
};
//#endregion
//#region ../../node_modules/.pnpm/@aws-sdk+credential-provider-process@3.972.37/node_modules/@aws-sdk/credential-provider-process/dist-es/resolveProcessCredentials.js
var resolveProcessCredentials = async (profileName, profiles, logger) => {
	const profile = profiles[profileName];
	if (profiles[profileName]) {
		const credentialProcess = profile["credential_process"];
		if (credentialProcess !== void 0) {
			const execPromise = promisify(externalDataInterceptor?.getTokenRecord?.().exec ?? exec);
			try {
				const { stdout } = await execPromise(credentialProcess);
				let data;
				try {
					data = JSON.parse(stdout.trim());
				} catch {
					throw Error(`Profile ${profileName} credential_process returned invalid JSON.`);
				}
				return getValidatedProcessCredentials(profileName, data, profiles);
			} catch (error) {
				throw new CredentialsProviderError(error.message, { logger });
			}
		} else throw new CredentialsProviderError(`Profile ${profileName} did not contain credential_process.`, { logger });
	} else throw new CredentialsProviderError(`Profile ${profileName} could not be found in shared credentials file.`, { logger });
};
//#endregion
//#region ../../node_modules/.pnpm/@aws-sdk+credential-provider-process@3.972.37/node_modules/@aws-sdk/credential-provider-process/dist-es/fromProcess.js
var fromProcess = (init = {}) => async ({ callerClientConfig } = {}) => {
	init.logger?.debug("@aws-sdk/credential-provider-process - fromProcess");
	const profiles = await parseKnownFiles(init);
	return resolveProcessCredentials(getProfileName({ profile: init.profile ?? callerClientConfig?.profile }), profiles, init.logger);
};

export { fromProcess };
//# sourceMappingURL=dist-es6-B4uDqNxl.js.map
