-
Notifications
You must be signed in to change notification settings - Fork 55
refactor(rt)!: split auth and signing packages; expose a method to sign requests #318
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
Changes from all commits
16b7cae
e9ff041
9505cd6
181c62d
b8a6bc7
d533c6d
a38b851
d8f0fe6
e53826b
4163d12
9862c65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.runtime.auth.signing | ||
|
|
||
| import aws.sdk.kotlin.crt.auth.signing.AwsSigner | ||
| import aws.sdk.kotlin.runtime.crt.toSignableCrtRequest | ||
| import aws.sdk.kotlin.runtime.crt.update | ||
| import aws.smithy.kotlin.runtime.http.request.HttpRequest | ||
| import aws.smithy.kotlin.runtime.http.request.toBuilder | ||
|
|
||
| /** | ||
| * Container for signed output and signature | ||
| * | ||
| * @property output The signed output type (e.g. HttpRequest) | ||
| * @property signature The resulting signature. Depending on the requested signature type and algorithm, | ||
| * this value will be in one of the following formats: | ||
| * | ||
| * 1. [AwsSignatureType.HTTP_REQUEST_VIA_HEADERS] - hex encoding of the binary signature value | ||
| * 2. [AwsSignatureType.HTTP_REQUEST_VIA_QUERY_PARAMS] - hex encoding of the binary signature value | ||
| * 3. [AwsSignatureType.HTTP_REQUEST_CHUNK] (SIGV4) - hex encoding of the binary signature value | ||
| * 4. [AwsSignatureType.HTTP_REQUEST_CHUNK] (SIGV4_ASYMMETRIC) - '*'-padded hex encoding of the binary signature value | ||
| * 5. [AwsSignatureType.HTTP_REQUEST_EVENT] - binary signature value (NYI) | ||
| * | ||
| */ | ||
| public data class SigningResult<T>(val output: T, val signature: ByteArray) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question why is equals/hashCode impl required for this type?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Data classes don't handle arrays as expected. What you want usually is to compare the contents of the array not whether they are the same instance (which is what it will do by default). Intellij even warns you of this and generates the more appropriate one for you. |
||
| override fun equals(other: Any?): Boolean { | ||
| if (this === other) return true | ||
| if (other == null || this::class != other::class) return false | ||
|
|
||
| other as SigningResult<*> | ||
|
|
||
| if (output != other.output) return false | ||
| if (!signature.contentEquals(other.signature)) return false | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| override fun hashCode(): Int { | ||
| var result = output?.hashCode() ?: 0 | ||
| result = 31 * result + signature.contentHashCode() | ||
| return result | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sign [HttpRequest] using the given signing [config] | ||
| * | ||
| * @param request the HTTP request to sign | ||
| * @param config the signing configuration to use | ||
| * @return the signing result | ||
| */ | ||
| public suspend fun sign(request: HttpRequest, config: AwsSigningConfig): SigningResult<HttpRequest> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above regarding kdoc |
||
| val crtRequest = request.toSignableCrtRequest() | ||
| val crtResult = AwsSigner.sign(crtRequest, config.toCrt()) | ||
| val crtSignedRequest = checkNotNull(crtResult.signedRequest) { "Signed request unexpectedly null" } | ||
| val builder = request.toBuilder() | ||
| builder.update(crtSignedRequest) | ||
| val output = builder.build() | ||
| return SigningResult(output, crtResult.signature) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| package aws.sdk.kotlin.runtime.auth | ||
| /* | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my bad |
||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.runtime.auth.signing | ||
|
|
||
| import aws.sdk.kotlin.crt.auth.signing.AwsSignatureType | ||
| import aws.sdk.kotlin.crt.auth.signing.AwsSignedBodyHeaderType | ||
| import aws.sdk.kotlin.crt.auth.signing.AwsSignedBodyValue | ||
| import aws.sdk.kotlin.crt.auth.signing.AwsSigner | ||
| import aws.sdk.kotlin.crt.auth.signing.AwsSigningConfig | ||
| import aws.sdk.kotlin.runtime.auth.credentials.CredentialsProvider | ||
| import aws.sdk.kotlin.runtime.auth.credentials.toCrt | ||
| import aws.sdk.kotlin.runtime.crt.path | ||
| import aws.sdk.kotlin.runtime.crt.queryParameters | ||
| import aws.sdk.kotlin.runtime.crt.toCrtHeaders | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion
I assume the intent is that customers may use this type since there is no internal markers. the KDoc should probably be a bit more thorough in this case, specifying details for parameters for example.