'use strict';

var _7WVEMAKW_cjs = require('./7WVEMAKW.cjs');
var P5BPMTGP_cjs = require('./P5BPMTGP.cjs');
require('./WDSPHVPJ.cjs');
var JGLHYXTW_cjs = require('./JGLHYXTW.cjs');
var U7VZULNU_cjs = require('./U7VZULNU.cjs');
var child_process = require('child_process');
var util = require('util');

// ../../node_modules/.pnpm/@aws-sdk+credential-provider-process@3.879.0/node_modules/@aws-sdk/credential-provider-process/dist-es/index.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@aws-sdk+credential-provider-process@3.879.0/node_modules/@aws-sdk/credential-provider-process/dist-es/fromProcess.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@aws-sdk+credential-provider-process@3.879.0/node_modules/@aws-sdk/credential-provider-process/dist-es/resolveProcessCredentials.js
U7VZULNU_cjs.init_cjs_shims();

// ../../node_modules/.pnpm/@aws-sdk+credential-provider-process@3.879.0/node_modules/@aws-sdk/credential-provider-process/dist-es/getValidatedProcessCredentials.js
U7VZULNU_cjs.init_cjs_shims();
var getValidatedProcessCredentials = /* @__PURE__ */ U7VZULNU_cjs.__name((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();
    const expireTime = new Date(data.Expiration);
    if (expireTime < 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
    }
  };
  _7WVEMAKW_cjs.setCredentialFeature(credentials, "CREDENTIALS_PROCESS", "w");
  return credentials;
}, "getValidatedProcessCredentials");

// ../../node_modules/.pnpm/@aws-sdk+credential-provider-process@3.879.0/node_modules/@aws-sdk/credential-provider-process/dist-es/resolveProcessCredentials.js
var resolveProcessCredentials = /* @__PURE__ */ U7VZULNU_cjs.__name(async (profileName, profiles, logger) => {
  const profile = profiles[profileName];
  if (profiles[profileName]) {
    const credentialProcess = profile["credential_process"];
    if (credentialProcess !== void 0) {
      const execPromise = util.promisify(child_process.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 JGLHYXTW_cjs.CredentialsProviderError(error.message, {
          logger
        });
      }
    } else {
      throw new JGLHYXTW_cjs.CredentialsProviderError(`Profile ${profileName} did not contain credential_process.`, {
        logger
      });
    }
  } else {
    throw new JGLHYXTW_cjs.CredentialsProviderError(`Profile ${profileName} could not be found in shared credentials file.`, {
      logger
    });
  }
}, "resolveProcessCredentials");

// ../../node_modules/.pnpm/@aws-sdk+credential-provider-process@3.879.0/node_modules/@aws-sdk/credential-provider-process/dist-es/fromProcess.js
var fromProcess = /* @__PURE__ */ U7VZULNU_cjs.__name((init = {}) => async ({ callerClientConfig } = {}) => {
  init.logger?.debug("@aws-sdk/credential-provider-process - fromProcess");
  const profiles = await P5BPMTGP_cjs.parseKnownFiles(init);
  return resolveProcessCredentials(P5BPMTGP_cjs.getProfileName({
    profile: init.profile ?? callerClientConfig?.profile
  }), profiles, init.logger);
}, "fromProcess");

exports.fromProcess = fromProcess;
//# sourceMappingURL=LH4V3GFX.cjs.map
//# sourceMappingURL=LH4V3GFX.cjs.map