-
Notifications
You must be signed in to change notification settings - Fork 915
Add initial AuthSchemeProvider codegen #4025
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
gosar
merged 6 commits into
feature/master/sra-identity-auth
from
gosar/sra-ia-authScheme-service-interfaces
May 24, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d843a6f
Add initial AuthSchemeProvider codegen
gosar c197b12
Refactor to remove some duplication
gosar cd22005
Add AuthSchemeProvider marker interface
gosar 34da7d0
Add/update generated javadoc
gosar 41b457d
Use ".auth.scheme" for java package
gosar 54f74d5
Fix java package in expected test output
gosar 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
69 changes: 69 additions & 0 deletions
69
...src/main/java/software/amazon/awssdk/codegen/emitters/tasks/AuthSchemeGeneratorTasks.java
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,69 @@ | ||
/* | ||
* Copyright 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 software.amazon.awssdk.codegen.emitters.tasks; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import software.amazon.awssdk.codegen.emitters.GeneratorTask; | ||
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams; | ||
import software.amazon.awssdk.codegen.emitters.PoetGeneratorTask; | ||
import software.amazon.awssdk.codegen.poet.auth.scheme.AuthSchemeParamsSpec; | ||
import software.amazon.awssdk.codegen.poet.auth.scheme.AuthSchemeProviderSpec; | ||
import software.amazon.awssdk.codegen.poet.auth.scheme.DefaultAuthSchemeParamsSpec; | ||
import software.amazon.awssdk.codegen.poet.auth.scheme.DefaultAuthSchemeProviderSpec; | ||
|
||
public final class AuthSchemeGeneratorTasks extends BaseGeneratorTasks { | ||
private final GeneratorTaskParams generatorTaskParams; | ||
|
||
public AuthSchemeGeneratorTasks(GeneratorTaskParams dependencies) { | ||
super(dependencies); | ||
this.generatorTaskParams = dependencies; | ||
} | ||
|
||
@Override | ||
protected List<GeneratorTask> createTasks() throws Exception { | ||
List<GeneratorTask> tasks = new ArrayList<>(); | ||
tasks.add(generateParamsInterface()); | ||
tasks.add(generateProviderInterface()); | ||
tasks.add(generateDefaultParamsImpl()); | ||
tasks.add(generateDefaultProviderImpl()); | ||
return tasks; | ||
} | ||
|
||
private GeneratorTask generateParamsInterface() { | ||
return new PoetGeneratorTask(authSchemeDir(), model.getFileHeader(), new AuthSchemeParamsSpec(model)); | ||
} | ||
|
||
private GeneratorTask generateDefaultParamsImpl() { | ||
return new PoetGeneratorTask(authSchemeInternalDir(), model.getFileHeader(), new DefaultAuthSchemeParamsSpec(model)); | ||
} | ||
|
||
private GeneratorTask generateProviderInterface() { | ||
return new PoetGeneratorTask(authSchemeDir(), model.getFileHeader(), new AuthSchemeProviderSpec(model)); | ||
} | ||
|
||
private GeneratorTask generateDefaultProviderImpl() { | ||
return new PoetGeneratorTask(authSchemeInternalDir(), model.getFileHeader(), new DefaultAuthSchemeProviderSpec(model)); | ||
} | ||
|
||
private String authSchemeDir() { | ||
return generatorTaskParams.getPathProvider().getAuthSchemeDirectory(); | ||
} | ||
|
||
private String authSchemeInternalDir() { | ||
return generatorTaskParams.getPathProvider().getAuthSchemeInternalDirectory(); | ||
} | ||
} |
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
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
130 changes: 130 additions & 0 deletions
130
...n/src/main/java/software/amazon/awssdk/codegen/poet/auth/scheme/AuthSchemeParamsSpec.java
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,130 @@ | ||
/* | ||
* Copyright 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 software.amazon.awssdk.codegen.poet.auth.scheme; | ||
|
||
import com.squareup.javapoet.ClassName; | ||
import com.squareup.javapoet.CodeBlock; | ||
import com.squareup.javapoet.MethodSpec; | ||
import com.squareup.javapoet.ParameterSpec; | ||
import com.squareup.javapoet.ParameterizedTypeName; | ||
import com.squareup.javapoet.TypeSpec; | ||
import java.util.Optional; | ||
import javax.lang.model.element.Modifier; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; | ||
import software.amazon.awssdk.codegen.poet.ClassSpec; | ||
import software.amazon.awssdk.codegen.poet.PoetUtils; | ||
|
||
public class AuthSchemeParamsSpec implements ClassSpec { | ||
private final IntermediateModel intermediateModel; | ||
private final AuthSchemeSpecUtils authSchemeSpecUtils; | ||
|
||
public AuthSchemeParamsSpec(IntermediateModel intermediateModel) { | ||
this.intermediateModel = intermediateModel; | ||
this.authSchemeSpecUtils = new AuthSchemeSpecUtils(intermediateModel); | ||
} | ||
|
||
@Override | ||
public ClassName className() { | ||
return authSchemeSpecUtils.parametersInterfaceName(); | ||
} | ||
|
||
@Override | ||
public TypeSpec poetSpec() { | ||
TypeSpec.Builder b = PoetUtils.createInterfaceBuilder(className()) | ||
.addModifiers(Modifier.PUBLIC) | ||
.addAnnotation(SdkPublicApi.class) | ||
.addJavadoc(interfaceJavadoc()) | ||
.addMethod(builderMethod()) | ||
.addType(builderInterfaceSpec()); | ||
|
||
addAccessorMethods(b); | ||
return b.build(); | ||
} | ||
|
||
private CodeBlock interfaceJavadoc() { | ||
CodeBlock.Builder b = CodeBlock.builder(); | ||
|
||
b.add("The parameters object used to resolve the auth schemes for the $N service.", | ||
intermediateModel.getMetadata().getServiceName()); | ||
|
||
return b.build(); | ||
} | ||
|
||
private MethodSpec builderMethod() { | ||
return MethodSpec.methodBuilder("builder") | ||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC) | ||
.returns(authSchemeSpecUtils.parametersInterfaceBuilderInterfaceName()) | ||
.addStatement("return $T.builder()", authSchemeSpecUtils.parametersDefaultImplName()) | ||
.addJavadoc("Get a new builder for creating a {@link $T}.", | ||
authSchemeSpecUtils.parametersInterfaceName()) | ||
.build(); | ||
} | ||
|
||
private TypeSpec builderInterfaceSpec() { | ||
TypeSpec.Builder b = TypeSpec.interfaceBuilder(authSchemeSpecUtils.parametersInterfaceBuilderInterfaceName()) | ||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC) | ||
.addJavadoc("A builder for a {@link $T}.", authSchemeSpecUtils.parametersInterfaceName()); | ||
|
||
addBuilderSetterMethods(b); | ||
|
||
b.addMethod(MethodSpec.methodBuilder("build") | ||
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) | ||
.returns(className()) | ||
.addJavadoc("Returns a {@link $T} object that is created from the properties that have been set " | ||
+ "on the builder.", authSchemeSpecUtils.parametersInterfaceName()) | ||
.build()); | ||
|
||
return b.build(); | ||
} | ||
|
||
private void addAccessorMethods(TypeSpec.Builder b) { | ||
b.addMethod(MethodSpec.methodBuilder("operation") | ||
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) | ||
.returns(String.class) | ||
.addJavadoc("Returns the operation for which to resolve the auth scheme.") | ||
.build()); | ||
|
||
if (authSchemeSpecUtils.usesSigV4()) { | ||
b.addMethod(MethodSpec.methodBuilder("region") | ||
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) | ||
// TODO: Should region be Regions? (Regions.class isn't available here though) | ||
.returns(ParameterizedTypeName.get(Optional.class, String.class)) | ||
.addJavadoc("Returns the region. The region is optional. The region parameter may be used " | ||
+ "with $S auth scheme. By default, the region will be empty.", "aws.auth#sigv4") | ||
.build()); | ||
} | ||
} | ||
|
||
private void addBuilderSetterMethods(TypeSpec.Builder b) { | ||
b.addMethod(MethodSpec.methodBuilder("operation") | ||
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) | ||
.addParameter(ParameterSpec.builder(String.class, "operation").build()) | ||
.returns(authSchemeSpecUtils.parametersInterfaceBuilderInterfaceName()) | ||
.addJavadoc("Set the operation for which to resolve the auth scheme.") | ||
.build()); | ||
|
||
if (authSchemeSpecUtils.usesSigV4()) { | ||
b.addMethod(MethodSpec.methodBuilder("region") | ||
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) | ||
.addParameter(ParameterSpec.builder(String.class, "region").build()) | ||
.returns(authSchemeSpecUtils.parametersInterfaceBuilderInterfaceName()) | ||
.addJavadoc("Set the region. The region parameter may be used with the $S auth scheme.", | ||
"aws.auth#sigv4") // TODO: Reference the SigV4 AuthScheme when implemented | ||
.build()); | ||
} | ||
} | ||
} |
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.
my.service.package.name.auth.authscheme
is also another option that sounds good to me. Does it make sense to haveauthscheme
a sub-package of theauth
package?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 like
auth
as prefixThere 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.
Updated to use
.auth.scheme
.