Skip to content

Commit 0cf3757

Browse files
authored
refactor!: abstract AwsSigner to support multiple backing implementations (#626)
1 parent f332ad9 commit 0cf3757

File tree

844 files changed

+6159
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

844 files changed

+6159
-27
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
description = "Types for AWS credentials"
7+
extra["displayName"] = "Smithy :: Kotlin :: AWS Credentials"
8+
extra["moduleName"] = "aws.smithy.kotlin.runtime.auth.awscredentials"
9+
10+
kotlin {
11+
sourceSets {
12+
commonMain {
13+
dependencies {
14+
// For Instant
15+
api(project(":runtime:runtime-core"))
16+
}
17+
}
18+
19+
all {
20+
languageSettings.optIn("aws.smithy.kotlin.runtime.util.InternalApi")
21+
}
22+
}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
package aws.smithy.kotlin.runtime.auth.awscredentials
6+
7+
import aws.smithy.kotlin.runtime.time.Instant
8+
9+
/**
10+
* Represents a set of AWS credentials
11+
*
12+
* For more information see [AWS security credentials](https://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html#AccessKeys)
13+
*/
14+
public data class Credentials(
15+
val accessKeyId: String,
16+
val secretAccessKey: String,
17+
val sessionToken: String? = null,
18+
val expiration: Instant? = null,
19+
val providerName: String? = null,
20+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
package aws.smithy.kotlin.runtime.auth.awscredentials
6+
7+
/**
8+
* Represents a producer/source of AWS credentials
9+
*/
10+
public interface CredentialsProvider {
11+
/**
12+
* Request credentials from the provider
13+
*/
14+
public suspend fun getCredentials(): Credentials
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
description = "Common types for AWS signing"
7+
extra["displayName"] = "Smithy :: Kotlin :: AWS Signing Common"
8+
extra["moduleName"] = "aws.smithy.kotlin.runtime.auth.signing.awssigning"
9+
10+
kotlin {
11+
sourceSets {
12+
commonMain {
13+
dependencies {
14+
api(project(":runtime:auth:aws-credentials"))
15+
api(project(":runtime:protocol:http"))
16+
implementation(project(":runtime:logging"))
17+
}
18+
}
19+
20+
all {
21+
languageSettings.optIn("aws.smithy.kotlin.runtime.util.InternalApi")
22+
}
23+
}
24+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
package aws.smithy.kotlin.runtime.auth.awssigning
6+
7+
import aws.smithy.kotlin.runtime.http.request.HttpRequest
8+
9+
/**
10+
* A component capable of signing requests and request chunks for AWS APIs.
11+
*/
12+
interface AwsSigner {
13+
/**
14+
* Signs an HTTP request according to the supplied signing configuration
15+
* @param request The request to sign
16+
* @param config The signing configuration
17+
* @return The signed request
18+
*/
19+
suspend fun sign(request: HttpRequest, config: AwsSigningConfig): AwsSigningResult<HttpRequest>
20+
21+
/**
22+
* Signs a body chunk according to the supplied signing configuration
23+
* @param chunkBody The chunk payload to sign
24+
* @param prevSignature The signature of the previous component of the request (either the initial request itself
25+
* for the first chunk or the previous chunk otherwise)
26+
* @param config The signing configuration
27+
* @return The signing result, which provides access to all signing-related result properties
28+
*/
29+
suspend fun signChunk(
30+
chunkBody: ByteArray,
31+
prevSignature: ByteArray,
32+
config: AwsSigningConfig,
33+
): AwsSigningResult<Unit>
34+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
package aws.smithy.kotlin.runtime.auth.awssigning
6+
7+
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider
8+
import aws.smithy.kotlin.runtime.client.ClientOption
9+
import aws.smithy.kotlin.runtime.time.Instant
10+
import aws.smithy.kotlin.runtime.util.AttributeKey
11+
12+
/**
13+
* [ClientOption] instances related to signing.
14+
*/
15+
object AwsSigningAttributes {
16+
/**
17+
* The signer implementation to use
18+
*/
19+
val Signer: ClientOption<AwsSigner> = ClientOption("Signer")
20+
21+
/**
22+
* AWS region to be used for signing the request
23+
*/
24+
val SigningRegion: ClientOption<String> = ClientOption("AwsSigningRegion")
25+
26+
/**
27+
* The signature version 4 service signing name to use in the credential scope when signing requests.
28+
* See: https://docs.aws.amazon.com/general/latest/gr/sigv4_elements.html
29+
*/
30+
val SigningService: ClientOption<String> = ClientOption("AwsSigningService")
31+
32+
/**
33+
* Override the date to complete the signing process with. Defaults to current time when not specified.
34+
*
35+
* **Note**: This is an advanced configuration option that does not normally need to be set manually.
36+
*/
37+
val SigningDate: ClientOption<Instant> = ClientOption("SigningDate")
38+
39+
/**
40+
* The [CredentialsProvider] to complete the signing process with. Defaults to the provider configured
41+
* on the service client.
42+
*
43+
* **Note**: This is an advanced configuration option that does not normally need to be set manually.
44+
*/
45+
val CredentialsProvider: ClientOption<CredentialsProvider> = ClientOption("CredentialsProvider")
46+
47+
/**
48+
* The source for the body hash.
49+
*
50+
* **Note**: This is an advanced configuration option that does not normally need to be set manually.
51+
*/
52+
val BodyHash: ClientOption<BodyHash> = ClientOption("BodyHash")
53+
54+
/**
55+
* The signed body header type.
56+
*
57+
* **Note**: This is an advanced configuration option that does not normally need to be set manually.
58+
*/
59+
val SignedBodyHeader: ClientOption<AwsSignedBodyHeader> = ClientOption("SignedBodyHeader")
60+
61+
/**
62+
* The signature of the HTTP request. This will only exist after the request has been signed.
63+
*/
64+
val RequestSignature: AttributeKey<ByteArray> = AttributeKey("AWS_HTTP_SIGNATURE")
65+
}

0 commit comments

Comments
 (0)