private load()

in src/client.ts [141:239]


  private load(config: Config, provider: CredentialsProvider): void {
    if (provider) {
      this.credential = new InnerCredentialsClient(provider.getProviderName(), provider);
      return;
    }
    if (!config) {
      this.credential = new InnerCredentialsClient('default', DefaultCredentialsProvider.builder().build());
      return;
    }

    if (!config.type) {
      throw new Error('Missing required type option');
    }

    switch (config.type) {
    case 'access_key':
      this.credential = new InnerCredentialsClient('access_key', StaticAKCredentialsProvider.builder()
        .withAccessKeyId(config.accessKeyId)
        .withAccessKeySecret(config.accessKeySecret)
        .build());
      break;
    case 'sts':
      this.credential = new InnerCredentialsClient('sts', StaticSTSCredentialsProvider.builder()
        .withAccessKeyId(config.accessKeyId)
        .withAccessKeySecret(config.accessKeySecret)
        .withSecurityToken(config.securityToken)
        .build());
      break;
    case 'ecs_ram_role':
      this.credential = new InnerCredentialsClient('ecs_ram_role', ECSRAMRoleCredentialsProvider.builder()
        .withRoleName(config.roleName)
        .withDisableIMDSv1(config.disableIMDSv1)
        .withAsyncCredentialUpdateEnabled(config.asyncCredentialUpdateEnabled)
        .withReadTimeout(config.timeout)
        .withConnectTimeout(config.connectTimeout)
        .build());
      break;
    case 'ram_role_arn': {
      let credentialsProvider: CredentialsProvider;
      if (config.securityToken) {
        credentialsProvider = StaticSTSCredentialsProvider.builder()
          .withAccessKeyId(config.accessKeyId)
          .withAccessKeySecret(config.accessKeySecret)
          .withSecurityToken(config.securityToken)
          .build();
      } else {
        credentialsProvider = StaticAKCredentialsProvider.builder()
          .withAccessKeyId(config.accessKeyId)
          .withAccessKeySecret(config.accessKeySecret)
          .build();
      }
      this.credential = new InnerCredentialsClient('ram_role_arn', RAMRoleARNCredentialsProvider.builder()
        .withCredentialsProvider(credentialsProvider)
        .withRoleArn(config.roleArn)
        .withPolicy(config.policy)
        .withDurationSeconds(config.roleSessionExpiration)
        .withRoleSessionName(config.roleSessionName)
        .withReadTimeout(config.timeout)
        .withConnectTimeout(config.connectTimeout)
        .withEnableVpc(config.enableVpc)
        .withStsEndpoint(config.stsEndpoint)
        .withStsRegionId(config.stsRegionId)
        .withExternalId(config.externalId)
        // .withHttpOptions(runtime)
        .build());
    }
      break;
    case 'oidc_role_arn':
      this.credential = new InnerCredentialsClient('oidc_role_arn', OIDCRoleArnCredentialsProvider.builder()
        .withRoleArn(config.roleArn)
        .withOIDCProviderArn(config.oidcProviderArn)
        .withOIDCTokenFilePath(config.oidcTokenFilePath)
        .withRoleSessionName(config.roleSessionName)
        .withPolicy(config.policy)
        .withDurationSeconds(config.roleSessionExpiration)
        .withStsEndpoint(config.stsEndpoint)
        .withStsRegionId(config.stsRegionId)
        .withEnableVpc(config.enableVpc)
        .withReadTimeout(config.timeout)
        .withConnectTimeout(config.connectTimeout)
        .build());
      break;
    case 'rsa_key_pair':
      this.credential = new RsaKeyPairCredential(config.publicKeyId, config.privateKeyFile);
      break;
    case 'bearer':
      this.credential = new BearerTokenCredential(config.bearerToken);
      break;
    case 'credentials_uri':
      this.credential = new InnerCredentialsClient('credentials_uri', URICredentialsProvider.builder()
        .withCredentialsURI(config.credentialsURI)
        .withReadTimeout(config.timeout)
        .withConnectTimeout(config.connectTimeout)
        .build());
      break;
    default:
      throw new Error('Invalid type option, support: access_key, sts, ecs_ram_role, ram_role_arn, rsa_key_pair, credentials_uri');
    }
  }