Skip to content

Conversation

@lucix-aws
Copy link
Contributor

Issue #

#509

Description of changes

Trim route53 resource ID prefixes that are generally returned by the service and round-tripped in other requests where the value is URI-bound.

See the added route53-tests for input examples.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lucix-aws lucix-aws requested a review from ianbotsf July 15, 2022 02:38
@lucix-aws lucix-aws requested a review from a team as a code owner July 15, 2022 02:38
@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-feat-route53-trimprefix

override val name: String
get() = "TrimResourcePrefix"

override val order: Byte = -128
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Why does this need to execute first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense in my mind that doing any modification on the user input would occur before serialization (so basically, it should execute first).

Copy link
Contributor

Choose a reason for hiding this comment

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

Important to note that the middleware itself also is ordered by phase. The initialization phase precedes serialization so it wouldn't matter what order they are in for codegen.

Comment on lines 47 to 59
write("val prefix = #S.toRegex()", "^/?.*?/")
withBlock("if (req.subject.#L?.contains(prefix) == true) {", "}", pathMember) {
write(
"val updated = req.subject.copy { #L = req.subject.#L?.replace(prefix, #S) }",
pathMember,
pathMember,
"",
)
write("next.call(#T(req.context, updated))", RuntimeTypes.Http.Operation.OperationRequest)
}
withBlock("else {", "}") {
write("next.call(req)")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: There's no need to if check here. Attempting to replace a pattern that doesn't match will have no effect:

val prefix = "^/?.*?/"
val updated = req.subject.copy { pathMember = req.subject.pathMember?.replace(prefix, "") }
next.call(OperationRequest(req.context, updated))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You avoid an object copy if you do the check, for what it's worth.

Comment on lines 47 to 54
write("val prefix = #S.toRegex()", "^/?.*?/")
withBlock("if (req.subject.#L?.contains(prefix) == true) {", "}", pathMember) {
write(
"val updated = req.subject.copy { #L = req.subject.#L?.replace(prefix, #S) }",
pathMember,
pathMember,
"",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: I personally find it easier to read codegen with fewer placeholder replacements. Consider using triple quotes instead of using #S with string literals:

write("""val prefix = "^/?.*?/".toRegex()""")
withBlock("if (req.subject.#L?.contains(prefix) == true) {", "}", pathMember) {
    write(
        """val updated = req.subject.copy { #L = req.subject.#L?.replace(prefix, "") }""",
        pathMember,
        pathMember,
    )

Comment on lines +69 to +81
apply GetReusableDelegationSet @httpRequestTests([
{
id: "GetReusableDelegationSetTrimDelegationSetId",
documentation: "This test validates that delegation set id is correctly trimmed",
method: "GET",
protocol: "aws.protocols#restXml",
uri: "/2013-04-01/delegationset/DELEGATIONSETID",
bodyMediaType: "application/xml",
params: {
"Id": "/delegationset/DELEGATIONSETID"
}
},
]) No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: How/why is delegationset being trimmed in this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • how - the generated regex catches it like anything else
  • why - Great question! this gets at the underlying issue that there's no real record of how this customization is meant to work other than how SDKs have implemented it. I learned today that this one in particular is pretty old, it goes back to 2012 in Java v1. Java v2's version basically came from porting over v1. There's apparently no reference for how it's supposed to work outside of how SDKs have written it.

This particular test case is one pulled from rust's codebase.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-feat-route53-trimprefix

@lucix-aws lucix-aws merged commit c8b6844 into main Jul 15, 2022
@lucix-aws lucix-aws deleted the feat-route53-trimprefix branch July 15, 2022 20:55
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