Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const client = new Client({
endpoint: "your-instance.cn-hangzhou.ots.aliyuncs.com",
accessKeyID: "YOUR_ACCESS_KEY_ID",
accessKeySecret: "YOUR_ACCESS_KEY_SECRET",
stsToken: "YOUR_STS_TOKEN", // optional
instanceName: "your-instance",
});

Expand Down
1 change: 1 addition & 0 deletions cspell.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ words:
- aliyun
- plainbuffer
- alicloud
- ststoken
1 change: 1 addition & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const H_OTS_API_VERSION = "x-ots-apiversion";
export const H_OTS_CONTENT_MD5 = "x-ots-contentmd5";
export const H_OTS_DATE = "x-ots-date";
export const H_OTS_INSTANCE_NAME = "x-ots-instancename";
export const H_OTS_STS_TOKEN = "x-ots-ststoken";
export const H_OTS_SIGNATURE = "x-ots-signature";

// OTS API Name
Expand Down
6 changes: 5 additions & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ClientConfig, OTSApiName, RequestOptions } from "./type";
import { createHash, createHmac } from "node:crypto";
import ky from "ky";
import { API_VERSION, H_OTS_ACCESS_KEY_ID, H_OTS_API_VERSION, H_OTS_CONTENT_MD5, H_OTS_DATE, H_OTS_INSTANCE_NAME, H_OTS_PREFIX, H_OTS_SIGNATURE, USER_AGENT } from "./const";
import { API_VERSION, H_OTS_ACCESS_KEY_ID, H_OTS_API_VERSION, H_OTS_CONTENT_MD5, H_OTS_DATE, H_OTS_INSTANCE_NAME, H_OTS_PREFIX, H_OTS_SIGNATURE, H_OTS_STS_TOKEN, USER_AGENT } from "./const";

const DEFAULT_REQUEST_OPTIONS = {
retry: 2,
Expand All @@ -21,6 +21,10 @@ export class Request {
[H_OTS_INSTANCE_NAME]: this.config.instanceName,
}, options.headers);

if (this.config.stsToken) {
headers[H_OTS_STS_TOKEN] = this.config.stsToken;
}

headers[H_OTS_SIGNATURE] = this.sign(options.apiName, headers);
headers["User-Agent"] = USER_AGENT;

Expand Down
1 change: 1 addition & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface ClientConfig {
endpoint: string;
accessKeyID: string;
accessKeySecret: string;
stsToken?: string;
instanceName: string;
}

Expand Down
Loading