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

generate auth params and bindings #453

Merged
merged 2 commits into from
Sep 27, 2023
Merged

Conversation

lucix-aws
Copy link
Contributor

  • Add code generation for modeled auth resolver parameters.
    • The only "universal" param is the operation name. This is resolved by implementing an operationName() interface on input structures.
    • An additional "region" field is generated for sigv4x services.
  • Add codegen for auth resolver param bindings.
  • Add GoIntegration support for loading both auth params and resolvers.

}

private void loadFields() {
if (context.getService().hasTrait(SigV4Trait.class)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of bringing in a new dependency for smithy-aws-traits, you can check trait application by ShapeId.

Suggested change
if (context.getService().hasTrait(SigV4Trait.class)) {
if (context.getService().hasTrait(ShapeId.from("aws.auth#sigv4"))) {

Overall though, it would be nice to add REGION for Sigv4x through a RuntimeClientPlugin rather than special cased here.

@@ -21,6 +21,7 @@ extra["moduleName"] = "software.amazon.smithy.go.codegen"

dependencies {
api("software.amazon.smithy:smithy-codegen-core:$smithyVersion")
api("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid bringing in AWS dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

public static Symbol tString = universe("string");
public static final Symbol STRING = universe("string");
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for this change, but not to the other Symbols?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put these GoUniverseTypes into a PR first but using them ended up triggering spotbugs/checkstyle errors. I only changed the ones I needed but I'll update them all.

Comment on lines 133 to 137
writer.write("""
func (*$T) operationName() string {
return $S
}
""",
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix indentation here

/**
* Entry point into smithy client auth generation.
*/
public class AuthGenerator {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would annotate this with @SmithyInternalApi

* SigV4[A] will also have a field for the region.
* Additional parameters can be loaded via GoIntegration.
*/
public class AuthParametersGenerator {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would annotate this with @SmithyInternalApi


import software.amazon.smithy.codegen.core.Symbol;

public record AuthParametersResolver(Symbol resolver) { }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would annotate this with @SmithyInternalApi

};
}

private void loadBindings() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe a better name would be loadResolvers()?

* The only value bound by default is the operation name. Generators must load additional bindings through
* GoIntegration.
*/
public class AuthParametersResolverGenerator {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would annotate this with @SmithyInternalApi

public GoWriter.Writable generate() {
loadBindings();

var paramsSymbol = SymbolUtils.createPointableSymbolBuilder(AuthParametersGenerator.STRUCT_NAME).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use AuthParametersGenerator.STRUCT_SYMBOL where paramsSymbol is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this predates that symbol. Will update.

@@ -21,6 +21,7 @@ extra["moduleName"] = "software.amazon.smithy.go.codegen"

dependencies {
api("software.amazon.smithy:smithy-codegen-core:$smithyVersion")
api("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@@ -247,6 +247,11 @@ void execute() {
protocolGenerator.generateEndpointResolution(context);
});

writers.useFileWriter("auth.go", settings.getModuleName(), writer -> {
ProtocolGenerator.GenerationContext context = contextBuilder.writer(writer).build();
protocolGenerator.generateAuth(context);
Copy link
Contributor

Choose a reason for hiding this comment

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

should auth scheme generation be part of protocol generation? i remember the reasoning we used to put endpoint generation in there. we made the argument that an endpoint does have the transport protocol baked into it, so it is tied to a protocol. and the upside was that putting endpoint generation in protocol generation guarantees only one will be chosen.
i think this same sort of reasoning could be applied to auth scheme.
but im second-guessing whether we should have put endpoint generation in there at all. i think if we put auth scheme in protocol generation as well, we should prob get a better understanding of what belongs in here and what doesnt

@@ -21,32 +21,33 @@
* Collection of Symbol constants for golang universe types.
* See <a href="https://go.dev/ref/spec#Predeclared_identifiers">predeclared identifiers</a>.
*/
@SuppressWarnings("checkstyle:ConstantName")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, but is this because the constant names aren't all uppercased?

@lucix-aws lucix-aws merged commit 0ecb0d3 into feat-sraauth Sep 27, 2023
1 check passed
@lucix-aws lucix-aws deleted the feat-sraauth-params branch September 27, 2023 23:36
lucix-aws added a commit that referenced this pull request Oct 2, 2023
lucix-aws added a commit that referenced this pull request Oct 16, 2023
lucix-aws added a commit that referenced this pull request Oct 16, 2023
lucix-aws added a commit that referenced this pull request Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants