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

commonMain.aws.sdk.kotlin.services.shield.endpoints.DefaultShieldEndpointProvider.kt Maven / Gradle / Ivy

There is a newer version: 1.3.76
Show newest version
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.shield.endpoints

import aws.sdk.kotlin.services.shield.endpoints.internal.partition
import aws.smithy.kotlin.runtime.client.endpoints.Endpoint
import aws.smithy.kotlin.runtime.client.endpoints.EndpointProviderException
import aws.smithy.kotlin.runtime.client.endpoints.SigningContextAttributeKey
import aws.smithy.kotlin.runtime.http.auth.sigV4
import aws.smithy.kotlin.runtime.net.Url
import aws.smithy.kotlin.runtime.net.UrlDecoding
import aws.smithy.kotlin.runtime.util.attributesOf

/**
 * The default endpoint provider as specified by the service model.
 */
public class DefaultShieldEndpointProvider: ShieldEndpointProvider {
    public override suspend fun resolveEndpoint(params: ShieldEndpointParameters): Endpoint {
        if (
            params.endpoint != null
        ) {
            if (
                params.useFips == true
            ) {
                throw EndpointProviderException("Invalid Configuration: FIPS and custom endpoint are not supported")
            }
            if (
                params.useDualStack == true
            ) {
                throw EndpointProviderException("Invalid Configuration: Dualstack and custom endpoint are not supported")
            }
            return Endpoint(
                Url.parse(params.endpoint, UrlDecoding.DecodeAll - UrlDecoding.DecodePath),
            )
        }
        if (
            params.region != null
        ) {
            run {
                val partitionResult = partition(params.region)
                if (
                    partitionResult != null
                ) {
                    if (
                        partitionResult?.name == "aws" &&
                        params.useFips == false &&
                        params.useDualStack == false
                    ) {
                        return Endpoint(
                            Url.parse("https://shield.us-east-1.amazonaws.com", UrlDecoding.DecodeAll - UrlDecoding.DecodePath),
                            attributes = attributesOf {
                                SigningContextAttributeKey to listOf(
                                    sigV4(
                                        serviceName = "shield",
                                        disableDoubleUriEncode = false,
                                        signingRegion = "us-east-1",
                                    ),
                                )
                            },
                        )
                    }
                    if (
                        partitionResult?.name == "aws" &&
                        params.useFips == true &&
                        params.useDualStack == false
                    ) {
                        return Endpoint(
                            Url.parse("https://shield-fips.us-east-1.amazonaws.com", UrlDecoding.DecodeAll - UrlDecoding.DecodePath),
                            attributes = attributesOf {
                                SigningContextAttributeKey to listOf(
                                    sigV4(
                                        serviceName = "shield",
                                        disableDoubleUriEncode = false,
                                        signingRegion = "us-east-1",
                                    ),
                                )
                            },
                        )
                    }
                    if (
                        params.useFips == true &&
                        params.useDualStack == true
                    ) {
                        if (
                            true == partitionResult?.supportsFIPS &&
                            true == partitionResult?.supportsDualStack
                        ) {
                            return Endpoint(
                                Url.parse("https://shield-fips.${params.region}.${partitionResult?.dualStackDnsSuffix}", UrlDecoding.DecodeAll - UrlDecoding.DecodePath),
                            )
                        }
                        throw EndpointProviderException("FIPS and DualStack are enabled, but this partition does not support one or both")
                    }
                    if (
                        params.useFips == true
                    ) {
                        if (
                            partitionResult?.supportsFIPS == true
                        ) {
                            return Endpoint(
                                Url.parse("https://shield-fips.${params.region}.${partitionResult?.dnsSuffix}", UrlDecoding.DecodeAll - UrlDecoding.DecodePath),
                            )
                        }
                        throw EndpointProviderException("FIPS is enabled but this partition does not support FIPS")
                    }
                    if (
                        params.useDualStack == true
                    ) {
                        if (
                            true == partitionResult?.supportsDualStack
                        ) {
                            return Endpoint(
                                Url.parse("https://shield.${params.region}.${partitionResult?.dualStackDnsSuffix}", UrlDecoding.DecodeAll - UrlDecoding.DecodePath),
                            )
                        }
                        throw EndpointProviderException("DualStack is enabled but this partition does not support DualStack")
                    }
                    return Endpoint(
                        Url.parse("https://shield.${params.region}.${partitionResult?.dnsSuffix}", UrlDecoding.DecodeAll - UrlDecoding.DecodePath),
                    )
                }
            }
        }
        throw EndpointProviderException("Invalid Configuration: Missing Region")

        throw EndpointProviderException("endpoint rules were exhausted without a match")
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy