Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: endpoints2: aws middleware and integration changes #751

Merged
merged 4 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import aws.smithy.kotlin.runtime.time.Instant
import aws.smithy.kotlin.runtime.time.ManualClock
import aws.smithy.kotlin.runtime.time.epochMilliseconds
import aws.smithy.kotlin.runtime.time.fromEpochMilliseconds
import aws.smithy.kotlin.runtime.util.net.Host
import io.kotest.matchers.string.shouldContain
import io.mockk.coVerify
import io.mockk.spyk
Expand Down Expand Up @@ -503,7 +504,7 @@ class ImdsCredentialsProviderTest {
override suspend fun roundTrip(context: ExecutionContext, request: HttpRequest): HttpCall {
if (successfulCallCount >= 2) {
return HttpCall(
HttpRequest(HttpMethod.GET, Url(Protocol.HTTP, "test", Protocol.HTTP.defaultPort, "/path/foo/bar"), Headers.Empty, HttpBody.Empty),
HttpRequest(HttpMethod.GET, Url(Protocol.HTTP, Host.parse("test"), Protocol.HTTP.defaultPort, "/path/foo/bar"), Headers.Empty, HttpBody.Empty),
HttpResponse(HttpStatusCode.InternalServerError, Headers.Empty, HttpBody.Empty),
testClock.now(),
testClock.now(),
Expand Down Expand Up @@ -578,7 +579,7 @@ class ImdsCredentialsProviderTest {
val internalServerErrorEngine = object : HttpClientEngineBase("internalServerError") {
override suspend fun roundTrip(context: ExecutionContext, request: HttpRequest): HttpCall {
return HttpCall(
HttpRequest(HttpMethod.GET, Url(Protocol.HTTP, "test", Protocol.HTTP.defaultPort, "/path/foo/bar"), Headers.Empty, HttpBody.Empty),
HttpRequest(HttpMethod.GET, Url(Protocol.HTTP, Host.parse("test"), Protocol.HTTP.defaultPort, "/path/foo/bar"), Headers.Empty, HttpBody.Empty),
HttpResponse(HttpStatusCode.InternalServerError, Headers.Empty, HttpBody.Empty),
testClock.now(),
testClock.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,13 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

aajtodd marked this conversation as resolved.
Show resolved Hide resolved
package aws.sdk.kotlin.runtime.endpoint

import aws.sdk.kotlin.runtime.InternalSdkApi
import aws.smithy.kotlin.runtime.http.Url
import aws.smithy.kotlin.runtime.auth.awssigning.SigningContext
import aws.smithy.kotlin.runtime.http.endpoints.Endpoint
import aws.smithy.kotlin.runtime.util.AttributeKey

/**
* Represents the endpoint a service client should make API operation calls to.
*
* The SDK will automatically resolve these endpoints per API client using an internal resolver.
*
* @property endpoint The endpoint clients will use to make API calls
* to e.g. "{service-id}.{region}.amazonaws.com"
* @property credentialScope Custom signing constraint overrides
*/
// TODO: remove when endpoints2 is fully implemented
public data class AwsEndpoint(
public val endpoint: Endpoint,
public val credentialScope: CredentialScope? = null,
) {
public constructor(url: Url, credentialScope: CredentialScope? = null) : this(Endpoint(url), credentialScope)
public constructor(url: String, credentialScope: CredentialScope? = null) : this(Endpoint(Url.parse(url)), credentialScope)
}

/**
* Static attribute key for AWS endpoint auth schemes.
*/
Expand All @@ -51,3 +32,16 @@ public sealed class AuthScheme {
public val signingRegionSet: List<String>,
) : AuthScheme()
}

/**
* Sugar extension to pull an auth scheme out of the attribute set.
*
* FUTURE: Right now we only support sigv4. The auth scheme property can include multiple schemes, for now we only pull
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return a list of auth schemes then?

Endpoint.authSchemes(): List<AuthScheme> = 
    attributes.getOrNull(AuthSchemesAttributeKey) ?: emptyList()

Then have a separate extensions like Endpoint.hasSigV4 or Endpoint.supportsSigv4?

e.g.

@InternalSdkApi
public fun Endpoint.supportsSigv4(): Boolean = 
    authSchemes().find { it is AuthScheme.SigV4} != null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I don't think it's necessary in the current context of us only supporting sigv4. When we have sigv4a as a first-class citizen the logic to retrieve this (it's basically used for presigning and for setting request context values for request signing) would have to evolve and at that point it would need extensions like this.

* out the sigv4 one if present.
*/
@InternalSdkApi
public fun Endpoint.authScheme(): AuthScheme.SigV4? =
attributes.getOrNull(AuthSchemesAttributeKey)?.find { it is AuthScheme.SigV4 } as AuthScheme.SigV4?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correctness: as? AuthScheme.SigV4


@InternalSdkApi
public fun AuthScheme.SigV4.asSigningContext(): SigningContext = SigningContext(signingName, signingRegion)

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,21 @@ public data class PartitionConfig(
* The resource identifier is further split based on the type or scope delimiter present (if any).
*/
@InternalSdkApi
public fun parseArn(value: String): Arn? {
val split = value.split(':', limit = ARN_COMPONENT_COUNT)
if (split[0] != "arn") return null
if (split.size != ARN_COMPONENT_COUNT) return null
if (split[5] == "") return null
public fun parseArn(value: String?): Arn? =
value?.let {
val split = it.split(':', limit = ARN_COMPONENT_COUNT)
if (split[0] != "arn") return null
if (split.size != ARN_COMPONENT_COUNT) return null
if (split[5] == "") return null

return Arn(
split[1],
split[2],
split[3],
split[4],
split[5].split(':', '/'),
)
}
return Arn(
split[1],
split[2],
split[3],
split[4],
split[5].split(':', '/'),
)
}

/**
* Represents a parsed form of an ARN (Amazon Resource Name).
Expand Down

This file was deleted.

Loading