-
Notifications
You must be signed in to change notification settings - Fork 51
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
Conversation
} | ||
|
||
private void loadFields() { | ||
if (context.getService().hasTrait(SigV4Trait.class)) { |
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.
Instead of bringing in a new dependency for smithy-aws-traits
, you can check trait application by ShapeId
.
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") |
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.
We should avoid bringing in AWS dependencies.
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.
+1
public static Symbol tString = universe("string"); | ||
public static final Symbol STRING = universe("string"); |
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.
Any reason for this change, but not to the other Symbol
s?
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 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.
writer.write(""" | ||
func (*$T) operationName() string { | ||
return $S | ||
} | ||
""", |
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.
Fix indentation here
/** | ||
* Entry point into smithy client auth generation. | ||
*/ | ||
public class AuthGenerator { |
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.
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 { |
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.
nit: would annotate this with @SmithyInternalApi
|
||
import software.amazon.smithy.codegen.core.Symbol; | ||
|
||
public record AuthParametersResolver(Symbol resolver) { } |
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.
nit: would annotate this with @SmithyInternalApi
}; | ||
} | ||
|
||
private void loadBindings() { |
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.
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 { |
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.
nit: would annotate this with @SmithyInternalApi
public GoWriter.Writable generate() { | ||
loadBindings(); | ||
|
||
var paramsSymbol = SymbolUtils.createPointableSymbolBuilder(AuthParametersGenerator.STRUCT_NAME).build(); |
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.
Can we use AuthParametersGenerator.STRUCT_SYMBOL
where paramsSymbol
is used?
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.
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") |
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.
+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); |
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 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") |
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.
nit, but is this because the constant names aren't all uppercased?
operationName()
interface on input structures.GoIntegration
support for loading both auth params and resolvers.