mirror of
https://github.com/rustfs/console.git
synced 2026-11-03 23:05:19 +08:00
* 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
30 lines
874 B
TypeScript
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
|
|
}
|