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

commonMain.aws.sdk.kotlin.services.eventbridge.endpoints.internal.EndpointResolverAdapter.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.eventbridge.endpoints.internal

import aws.sdk.kotlin.runtime.http.interceptors.AwsBusinessMetric
import aws.sdk.kotlin.services.eventbridge.EventBridgeClient
import aws.sdk.kotlin.services.eventbridge.endpoints.EventBridgeEndpointParameters
import aws.sdk.kotlin.services.eventbridge.model.PutEventsRequest
import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAttributes
import aws.smithy.kotlin.runtime.businessmetrics.AccountIdBasedEndpointAccountId
import aws.smithy.kotlin.runtime.businessmetrics.ServiceEndpointOverride
import aws.smithy.kotlin.runtime.businessmetrics.SmithyBusinessMetric
import aws.smithy.kotlin.runtime.businessmetrics.emitBusinessMetric
import aws.smithy.kotlin.runtime.client.SdkClientOption
import aws.smithy.kotlin.runtime.client.endpoints.Endpoint
import aws.smithy.kotlin.runtime.collections.get
import aws.smithy.kotlin.runtime.http.operation.EndpointResolver
import aws.smithy.kotlin.runtime.http.operation.HttpOperationContext
import aws.smithy.kotlin.runtime.http.operation.ResolveEndpointRequest

internal class EndpointResolverAdapter(
    private val config: EventBridgeClient.Config
): EndpointResolver {

    override suspend fun resolve(request: ResolveEndpointRequest): Endpoint {
        val params = resolveEndpointParams(config, request)
        val endpoint = config.endpointProvider.resolveEndpoint(params)

        if (endpoint.attributes.contains(ServiceEndpointOverride)) request.context.emitBusinessMetric(SmithyBusinessMetric.SERVICE_ENDPOINT_OVERRIDE)
        if (endpoint.attributes.contains(AccountIdBasedEndpointAccountId)) request.context.emitBusinessMetric(SmithyBusinessMetric.ACCOUNT_ID_BASED_ENDPOINT)
        if (endpoint.attributes.contains(AwsSigningAttributes.SigningService) && endpoint.attributes[AwsSigningAttributes.SigningService] == "s3express") request.context.emitBusinessMetric(AwsBusinessMetric.S3_EXPRESS_BUCKET)

        return endpoint
    }
}

internal fun resolveEndpointParams(config: EventBridgeClient.Config, request: ResolveEndpointRequest): EventBridgeEndpointParameters {
    return EventBridgeEndpointParameters {
        region = config.region
        bindAwsBuiltins(config, request)
        endpoint = config.endpointUrl?.toString()
        val opName = request.context[SdkClientOption.OperationName]
        opContextBindings[opName]?.invoke(this, request)
    }
}
private typealias BindOperationContextParamsFn = (EventBridgeEndpointParameters.Builder, ResolveEndpointRequest) -> Unit

private val opContextBindings = mapOf (
    "PutEvents" to ::bindPutEventsEndpointContext,
)

private fun bindPutEventsEndpointContext(builder: EventBridgeEndpointParameters.Builder, request: ResolveEndpointRequest): Unit {
    @Suppress("UNCHECKED_CAST")
    val input = request.context[HttpOperationContext.OperationInput] as PutEventsRequest
    builder.endpointId = input.endpointId
}

private fun EventBridgeEndpointParameters.Builder.bindAwsBuiltins(config: EventBridgeClient.Config, request: ResolveEndpointRequest) {
    useDualStack = config.useDualStack
    useFips = config.useFips
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy