async updateCredential()

in src/uri_credential.ts [30:54]


  async updateCredential(): Promise<void> {
    const url = this.credentialsURI;
    const response = await httpx.request(url, { readTimeout: this.readTimeout, connectTimeout: this.connectTimeout });
    if (response.statusCode !== 200) {
      throw new Error(`Get credentials from ${url} failed, status code is ${response.statusCode}`);
    }
    const body = (await httpx.read(response, 'utf8')) as string;
    let json;
    try {
      json = JSON.parse(body);
    } catch (ex) {
      throw new Error(`Get credentials from ${url} failed, unmarshal response failed, JSON is: ${body}`);
    }

    if (json.Code !== 'Success') {
      throw new Error(`Get credentials from ${url} failed, Code is ${json.Code}`);
    }

    this.sessionCredential = {
      AccessKeyId: json.AccessKeyId,
      AccessKeySecret: json.AccessKeySecret,
      Expiration: json.Expiration,
      SecurityToken: json.SecurityToken,
    };
  }