-
Notifications
You must be signed in to change notification settings - Fork 124
feat(foundation): Add foundation modules to feature branch #3193
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bf874a3
Add projects for foundation and foundation-aws
mattcreaser 5d5de13
Add Result type to foundation library
mattcreaser 978f317
Add AwsCredentials and provider interface
mattcreaser d908ea3
Add functions to convert credentials for AWS SDK
mattcreaser d01c6a3
Add internal result functions
mattcreaser eb73104
Add AmplifyException base class
mattcreaser e0ffcdf
Add tests for Result mappers
mattcreaser ad5f001
Add Foundation api dump
mattcreaser 828da9a
Rename foundation-bridge
mattcreaser d91369a
Remove smithy -> amplify credentials mapper
mattcreaser 01d115f
Add tests for smithy credentials mapping
mattcreaser 7329acf
Update foundation api file
mattcreaser 41ecda9
Add tests for credential provider mapping
mattcreaser 3807e29
Add explicit typing in SmithyCredentialsTest
mattcreaser e90d64e
Add more operators for Result
mattcreaser e2afd31
Add contracts to Result operators
mattcreaser 446107f
Update API after package name change
mattcreaser acef215
Use string interpolation in exception toString
mattcreaser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| plugins { | ||
| alias(libs.plugins.amplify.kmp) | ||
| } | ||
|
|
||
| kotlin { | ||
| sourceSets { | ||
| commonMain { | ||
| dependencies { | ||
| api(project(":foundation")) | ||
| api(libs.aws.credentials) | ||
| } | ||
| } | ||
|
|
||
| commonTest { | ||
| dependencies { | ||
| implementation(libs.test.kotest.assertions) | ||
| implementation(libs.test.kotlin.coroutines) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest /> |
47 changes: 47 additions & 0 deletions
47
...ge/src/commonMain/kotlin/com/amplifyframework/foundation/credentials/SmithyCredentials.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package com.amplifyframework.foundation.credentials | ||
|
|
||
| import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials | ||
| import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider | ||
| import aws.smithy.kotlin.runtime.collections.Attributes | ||
| import aws.smithy.kotlin.runtime.time.Instant as SmithyInstant | ||
| import com.amplifyframework.annotations.InternalAmplifyApi | ||
| import kotlin.time.ExperimentalTime | ||
| import kotlin.time.Instant | ||
|
|
||
| @InternalAmplifyApi | ||
| @OptIn(ExperimentalTime::class) | ||
| fun AwsCredentials.toSmithyCredentials(): Credentials = when (this) { | ||
| is AwsCredentials.Static -> Credentials( | ||
| accessKeyId = this.accessKeyId, | ||
| secretAccessKey = this.secretAccessKey | ||
| ) | ||
| is AwsCredentials.Temporary -> Credentials( | ||
| accessKeyId = this.accessKeyId, | ||
| secretAccessKey = this.secretAccessKey, | ||
| sessionToken = this.sessionToken, | ||
| expiration = this.expiration.toSmithyInstant() | ||
| ) | ||
| } | ||
|
|
||
| @InternalAmplifyApi | ||
| fun AwsCredentialsProvider<*>.toSmithyProvider() = object : CredentialsProvider { | ||
| override suspend fun resolve(attributes: Attributes) = this@toSmithyProvider.resolve().toSmithyCredentials() | ||
| } | ||
|
|
||
| @OptIn(ExperimentalTime::class) | ||
| private fun Instant.toSmithyInstant() = SmithyInstant.fromEpochSeconds(epochSeconds) |
95 changes: 95 additions & 0 deletions
95
...rc/commonTest/kotlin/com/amplifyframework/foundation/credentials/SmithyCredentialsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package com.amplifyframework.foundation.credentials | ||
|
|
||
| import aws.smithy.kotlin.runtime.collections.emptyAttributes | ||
| import aws.smithy.kotlin.runtime.time.Instant as SmithyInstant | ||
| import io.kotest.matchers.nulls.shouldBeNull | ||
| import io.kotest.matchers.shouldBe | ||
| import kotlin.time.ExperimentalTime | ||
| import kotlin.time.Instant | ||
| import kotlinx.coroutines.test.runTest | ||
| import org.junit.Test | ||
|
|
||
| @OptIn(ExperimentalTime::class) | ||
| class SmithyCredentialsTest { | ||
| private val expiration = Instant.fromEpochSeconds(1770130997) | ||
|
|
||
| @Test | ||
| fun `maps static credentials`() { | ||
| val awsCredentials = AwsCredentials.Static( | ||
| accessKeyId = "access", | ||
| secretAccessKey = "secret" | ||
| ) | ||
|
|
||
| val mapped = awsCredentials.toSmithyCredentials() | ||
|
|
||
| mapped.accessKeyId shouldBe "access" | ||
| mapped.secretAccessKey shouldBe "secret" | ||
| mapped.sessionToken.shouldBeNull() | ||
| mapped.expiration.shouldBeNull() | ||
| } | ||
|
|
||
| @Test | ||
| fun `maps temporary credentials`() { | ||
| val awsCredentials = AwsCredentials.Temporary( | ||
| accessKeyId = "access", | ||
| secretAccessKey = "secret", | ||
| sessionToken = "session", | ||
| expiration = expiration | ||
| ) | ||
|
|
||
| val mapped = awsCredentials.toSmithyCredentials() | ||
|
|
||
| mapped.accessKeyId shouldBe "access" | ||
| mapped.secretAccessKey shouldBe "secret" | ||
| mapped.sessionToken shouldBe "session" | ||
| mapped.expiration shouldBe SmithyInstant.fromEpochSeconds(expiration.epochSeconds) | ||
| } | ||
|
|
||
| @Test | ||
| fun `provider maps static credentials`() = runTest { | ||
| val staticProvider = AwsCredentialsProvider<AwsCredentials> { | ||
| AwsCredentials.Static(accessKeyId = "access", secretAccessKey = "secret") | ||
| } | ||
| val mappedProvider = staticProvider.toSmithyProvider() | ||
| val credentials = mappedProvider.resolve(emptyAttributes()) | ||
|
|
||
| credentials.accessKeyId shouldBe "access" | ||
| credentials.secretAccessKey shouldBe "secret" | ||
| credentials.sessionToken.shouldBeNull() | ||
| credentials.expiration.shouldBeNull() | ||
| } | ||
|
|
||
| @Test | ||
| fun `provider maps temporary credentials`() = runTest { | ||
| val temporaryProvider = AwsCredentialsProvider<AwsCredentials> { | ||
| AwsCredentials.Temporary( | ||
| accessKeyId = "access", | ||
| secretAccessKey = "secret", | ||
| sessionToken = "session", | ||
| expiration = expiration | ||
| ) | ||
| } | ||
| val mappedProvider = temporaryProvider.toSmithyProvider() | ||
| val credentials = mappedProvider.resolve(emptyAttributes()) | ||
|
|
||
| credentials.accessKeyId shouldBe "access" | ||
| credentials.secretAccessKey shouldBe "secret" | ||
| credentials.sessionToken shouldBe "session" | ||
| credentials.expiration shouldBe SmithyInstant.fromEpochSeconds(expiration.epochSeconds) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| public abstract interface class com/amplifyframework/foundation/credentials/AwsCredentials { | ||
| public abstract fun getAccessKeyId ()Ljava/lang/String; | ||
| public abstract fun getSecretAccessKey ()Ljava/lang/String; | ||
| } | ||
|
|
||
| public final class com/amplifyframework/foundation/credentials/AwsCredentials$Static : com/amplifyframework/foundation/credentials/AwsCredentials { | ||
| public fun <init> (Ljava/lang/String;Ljava/lang/String;)V | ||
| public fun getAccessKeyId ()Ljava/lang/String; | ||
| public fun getSecretAccessKey ()Ljava/lang/String; | ||
| } | ||
|
|
||
| public final class com/amplifyframework/foundation/credentials/AwsCredentials$Temporary : com/amplifyframework/foundation/credentials/AwsCredentials { | ||
| public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/time/Instant;)V | ||
| public fun getAccessKeyId ()Ljava/lang/String; | ||
| public final fun getExpiration ()Lkotlin/time/Instant; | ||
| public fun getSecretAccessKey ()Ljava/lang/String; | ||
| public final fun getSessionToken ()Ljava/lang/String; | ||
| } | ||
|
|
||
| public abstract interface class com/amplifyframework/foundation/credentials/AwsCredentialsProvider { | ||
| public abstract fun resolve (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; | ||
| } | ||
|
|
||
| public abstract class com/amplifyframework/foundation/exceptions/AmplifyException : java/lang/Exception { | ||
| public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V | ||
| public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;ILkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
| public final fun getRecoverySuggestion ()Ljava/lang/String; | ||
| public fun toString ()Ljava/lang/String; | ||
| } | ||
|
|
||
| public abstract interface class com/amplifyframework/foundation/results/Result { | ||
| } | ||
|
|
||
| public final class com/amplifyframework/foundation/results/Result$Failure : com/amplifyframework/foundation/results/Result { | ||
| public fun <init> (Ljava/lang/Object;)V | ||
| public final fun component1 ()Ljava/lang/Object; | ||
| public final fun copy (Ljava/lang/Object;)Lcom/amplifyframework/foundation/results/Result$Failure; | ||
| public static synthetic fun copy$default (Lcom/amplifyframework/foundation/results/Result$Failure;Ljava/lang/Object;ILjava/lang/Object;)Lcom/amplifyframework/foundation/results/Result$Failure; | ||
| public fun equals (Ljava/lang/Object;)Z | ||
| public final fun getError ()Ljava/lang/Object; | ||
| public fun hashCode ()I | ||
| public fun toString ()Ljava/lang/String; | ||
| } | ||
|
|
||
| public final class com/amplifyframework/foundation/results/Result$Success : com/amplifyframework/foundation/results/Result { | ||
| public fun <init> (Ljava/lang/Object;)V | ||
| public final fun component1 ()Ljava/lang/Object; | ||
| public final fun copy (Ljava/lang/Object;)Lcom/amplifyframework/foundation/results/Result$Success; | ||
| public static synthetic fun copy$default (Lcom/amplifyframework/foundation/results/Result$Success;Ljava/lang/Object;ILjava/lang/Object;)Lcom/amplifyframework/foundation/results/Result$Success; | ||
| public fun equals (Ljava/lang/Object;)Z | ||
| public final fun getData ()Ljava/lang/Object; | ||
| public fun hashCode ()I | ||
| public fun toString ()Ljava/lang/String; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| plugins { | ||
| alias(libs.plugins.amplify.kmp) | ||
| alias(libs.plugins.amplify.publishing) | ||
| } | ||
|
|
||
| kotlin { | ||
| sourceSets { | ||
| commonMain { | ||
| dependencies { | ||
| api(project(":annotations")) | ||
| } | ||
| } | ||
|
|
||
| commonTest { | ||
| dependencies { | ||
| implementation(libs.test.kotest.assertions) | ||
| implementation(project(":testutils")) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| POM_ARTIFACT_ID=foundation | ||
| POM_NAME=Amplify Framework for Android - Foundation | ||
| POM_DESCRIPTION=Amplify Framework for Android - Foundational library | ||
| POM_PACKAGING=aar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest /> |
58 changes: 58 additions & 0 deletions
58
...ation/src/commonMain/kotlin/com/amplifyframework/foundation/credentials/AwsCredentials.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package com.amplifyframework.foundation.credentials | ||
|
|
||
| import kotlin.time.ExperimentalTime | ||
| import kotlin.time.Instant | ||
|
|
||
| /** | ||
| * Provides access to the AWS credentials used for accessing AWS services: AWS | ||
| * access key ID and secret access key. These credentials are used to securely | ||
| * sign requests to AWS services. | ||
| * | ||
| * For more details on AWS access keys, | ||
| * [see](https://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html) | ||
| */ | ||
| sealed interface AwsCredentials { | ||
| /** | ||
| * The AWS access key ID for this credentials object. | ||
| */ | ||
| val accessKeyId: String | ||
|
|
||
| /** | ||
| * The AWS secret access key for this credentials object. | ||
| */ | ||
| val secretAccessKey: String | ||
|
|
||
| /** | ||
| * Long-term AWS credentials, such as those granted to Admin Users | ||
| */ | ||
| class Static( | ||
| override val accessKeyId: String, | ||
| override val secretAccessKey: String | ||
| ) : AwsCredentials | ||
|
|
||
| /** | ||
| * Temporary credentials, such as those vended by STS | ||
| */ | ||
| @OptIn(ExperimentalTime::class) | ||
| class Temporary( | ||
| override val accessKeyId: String, | ||
| override val secretAccessKey: String, | ||
| val sessionToken: String, | ||
| val expiration: Instant | ||
| ) : AwsCredentials | ||
| } |
26 changes: 26 additions & 0 deletions
26
...c/commonMain/kotlin/com/amplifyframework/foundation/credentials/AwsCredentialsProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package com.amplifyframework.foundation.credentials | ||
|
|
||
| /** | ||
| * Interface for providers of AWS Credentials | ||
| */ | ||
| fun interface AwsCredentialsProvider<out T : AwsCredentials> { | ||
| /** | ||
| * Resolve and return the credentials | ||
| */ | ||
| suspend fun resolve(): T | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.