All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.sdk.kotlin.runtime.auth.credentials.internal.CredentialsExt.kt Maven / Gradle / Ivy

There is a newer version: 1.3.76
Show newest version
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */
package aws.sdk.kotlin.runtime.auth.credentials.internal

import aws.sdk.kotlin.runtime.client.AwsClientOption
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.collections.emptyAttributes
import aws.smithy.kotlin.runtime.collections.mutableAttributes
import aws.smithy.kotlin.runtime.collections.setIfValueNotNull
import aws.smithy.kotlin.runtime.identity.IdentityAttributes
import aws.smithy.kotlin.runtime.time.Instant

internal fun credentials(
    accessKeyId: String,
    secretAccessKey: String,
    sessionToken: String? = null,
    expiration: Instant? = null,
    providerName: String? = null,
    accountId: String? = null,
): Credentials {
    val attributes = when {
        providerName != null || accountId != null -> mutableAttributes().apply {
            setIfValueNotNull(IdentityAttributes.ProviderName, providerName)
            setIfValueNotNull(AwsClientOption.AccountId, accountId)
        }
        else -> emptyAttributes()
    }
    return Credentials(accessKeyId, secretAccessKey, sessionToken, expiration, attributes = attributes)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy