-
Notifications
You must be signed in to change notification settings - Fork 31
Service sdk sigv4 #1381
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
Service sdk sigv4 #1381
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
de7f820
sigv4
4e0e733
sigv4
1206186
sigv4
1955a1c
sigv4a
47d7389
Merge branch 'server-sdk-main' of github.com:smithy-lang/smithy-kotli…
140366e
fix
514e764
separate files
0db31ec
unit test
b243c8c
fix
3d8bd69
move ktor stub generator under ktor dir
a34a833
fix
27f533b
modify key for auth testing, better readability
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
871 changes: 0 additions & 871 deletions
871
...odegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/KtorStubGenerator.kt
This file was deleted.
Oops, something went wrong.
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
58 changes: 58 additions & 0 deletions
58
...egen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/service/ktor/Authentication.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 @@ | ||
package software.amazon.smithy.kotlin.codegen.service.ktor | ||
|
||
import software.amazon.smithy.aws.traits.auth.SigV4ATrait | ||
import software.amazon.smithy.aws.traits.auth.SigV4Trait | ||
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes | ||
import software.amazon.smithy.kotlin.codegen.core.withBlock | ||
import software.amazon.smithy.kotlin.codegen.model.getTrait | ||
import software.amazon.smithy.kotlin.codegen.service.ServiceTypes | ||
|
||
internal fun KtorStubGenerator.writeAuthentication() { | ||
delegator.useFileWriter("UserPrincipal.kt", "$pkgName.auth") { writer -> | ||
writer.withBlock("public data class UserPrincipal(", ")") { | ||
write("val user: String") | ||
} | ||
} | ||
|
||
delegator.useFileWriter("Validation.kt", "$pkgName.auth") { writer -> | ||
|
||
writer.withBlock("internal object BearerValidation {", "}") { | ||
withBlock("public fun bearerValidation(token: String): UserPrincipal? {", "}") { | ||
write("// TODO: implement me") | ||
write("if (true) return UserPrincipal(#S) else return null", "Authenticated User") | ||
} | ||
} | ||
} | ||
|
||
delegator.useFileWriter("Authentication.kt", "$pkgName.auth") { writer -> | ||
writer.withBlock("internal fun #T.configureAuthentication() {", "}", RuntimeTypes.KtorServerCore.Application) { | ||
write("") | ||
withBlock( | ||
"#T(#T) {", | ||
"}", | ||
RuntimeTypes.KtorServerCore.install, | ||
RuntimeTypes.KtorServerAuth.Authentication, | ||
) { | ||
withBlock("#T(#S) {", "}", RuntimeTypes.KtorServerAuth.bearer, "auth-bearer") { | ||
write("realm = #S", "Access to API") | ||
write("authenticate { cred -> BearerValidation.bearerValidation(cred.token) }") | ||
} | ||
withBlock("sigV4(name = #S) {", "}", "aws-sigv4") { | ||
write("region = #T.region", ServiceTypes(pkgName).serviceFrameworkConfig) | ||
val serviceSigV4AuthTrait = serviceShape.getTrait<SigV4Trait>() | ||
if (serviceSigV4AuthTrait != null) { | ||
write("service = #S", serviceSigV4AuthTrait.name) | ||
} | ||
luigi617 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
withBlock("sigV4A(name = #S) {", "}", "aws-sigv4a") { | ||
write("region = #T.region", ServiceTypes(pkgName).serviceFrameworkConfig) | ||
val serviceSigV4AAuthTrait = serviceShape.getTrait<SigV4ATrait>() | ||
if (serviceSigV4AAuthTrait != null) { | ||
write("service = #S", serviceSigV4AAuthTrait.name) | ||
} | ||
} | ||
write("provider(#S) { authenticate { ctx -> ctx.principal(Unit) } }", "no-auth") | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
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.
Should we be rendering the
block from above if the service doesn't have the SigV4 trait?
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.
I think yes, because once generated, you should allow user to use sigv4 if they want to add it manually