Files
rustfs-console/lib/sts.ts
T
安正超 ca87e9e007 fix: status home redirect (#47)
* feat: move status route and format repo

* fix: resolve lint warnings

* fix: load bucket usage asynchronously

* fix: sign version config request

* fix: show spinner for bucket usage loading

* fix: prevent object list fetch loop

* fix: dedupe list requests

* feat: add sidebar version footer
2026-02-04 21:42:11 +08:00

30 lines
874 B
TypeScript

import { AssumeRoleCommand, STSClient } from "@aws-sdk/client-sts"
import type { AwsCredentialIdentity, AwsCredentialIdentityProvider } from "@aws-sdk/types"
import type { SiteConfig } from "@/types/config"
export async function getStsToken(
credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider,
roleArn: string,
customConfig: SiteConfig,
) {
const stsClient = new STSClient({
endpoint: customConfig.s3.endpoint,
region: customConfig.s3.region || "us-east-1",
credentials: credentials,
})
const command = new AssumeRoleCommand({
RoleArn: roleArn,
RoleSessionName: "console",
DurationSeconds: customConfig.session?.durationSeconds || 3600 * 12,
})
const response = await stsClient.send(command)
if (!response.Credentials) {
throw new Error("Failed to retrieve credentials")
}
return response.Credentials
}