async getCredentials()

in src/providers/default.ts [69:103]


  async getCredentials(): Promise<Credentials> {
    if (this.lastUsedProvider) {
      const inner = await this.lastUsedProvider.getCredentials();
      return Credentials.builder()
        .withAccessKeyId(inner.accessKeyId)
        .withAccessKeySecret(inner.accessKeySecret)
        .withSecurityToken(inner.securityToken)
        .withProviderName(`${this.getProviderName()}/${this.lastUsedProvider.getProviderName()}`)
        .build();
    }

    const errors = [];
    for (const provider of this.providers) {
      this.lastUsedProvider = provider;
      let inner;
      try {
        inner = await provider.getCredentials();
      } catch (ex) {
        errors.push(ex);
        continue;
      }
      if (inner) {
        return Credentials.builder()
          .withAccessKeyId(inner.accessKeyId)
          .withAccessKeySecret(inner.accessKeySecret)
          .withSecurityToken(inner.securityToken)
          .withProviderName(`${this.getProviderName()}/${this.lastUsedProvider.getProviderName()}`)
          .build();
      }
    }

    throw new Error(`unable to get credentials from any of the providers in the chain: ${errors.map((e) => {
      return e.message;
    }).join(', ')}`);
  }