Skip to content

Commit 6cf81c7

Browse files
cenedhrynjoviegas
andauthored
[Draft] Feature/string array endpoint params (#5168)
* feat(StringArrayEndpointParams) Codegen String Array Enpoint params and Auth schemes params based on end-point-rule-set.json. (#5122) * Support Customization string array endpoint params for S3 access grants, until all SDKs add support for string array. (#5137) * new(StringArrayEndpointParams) Codegeneration of OperationContextParams defined for a Operation. (#5146) * Extracting existing JMESPath runtime to a separate class (#5155) * new(StringArrayEndpointParams) Customization of Operation Context params and adding customizations for S3 (#5159) * Converts endpoint param list of string to list of value (#5169) * Generates JmesPath expressions for operation context parameters (#5172) * Supporting wildcard and keys fn in JmesPathRuntime (#5198) * Adds functional tests for list of string auth params (#5216) * Changelog --------- Co-authored-by: John Viegas <[email protected]> Co-authored-by: John Viegas <[email protected]>
1 parent 0e24853 commit 6cf81c7

File tree

60 files changed

+2777
-569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2777
-569
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Adds capability to resolve endpoint and auth scheme parameters of type list of string as well as new functions to JmesPath runtime (keys and wildcard)"
6+
}

codegen/src/main/java/software/amazon/awssdk/codegen/AddMetadata.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ private static void configurePackageName(Metadata metadata,
104104
.withPaginatorsPackageName(namingStrategy.getPaginatorsPackageName(service))
105105
.withWaitersPackageName(namingStrategy.getWaitersPackageName(service))
106106
.withEndpointRulesPackageName(namingStrategy.getEndpointRulesPackageName(service))
107-
.withAuthSchemePackageName(namingStrategy.getAuthSchemePackageName(service));
107+
.withAuthSchemePackageName(namingStrategy.getAuthSchemePackageName(service))
108+
.withJmesPathPackageName(namingStrategy.getJmesPathPackageName(service));
108109
}
109110

110111
/**

codegen/src/main/java/software/amazon/awssdk/codegen/AddOperations.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public Map<String, OperationModel> constructOperations() {
180180
operationModel.setHttpChecksum(op.getHttpChecksum());
181181
operationModel.setRequestcompression(op.getRequestcompression());
182182
operationModel.setStaticContextParams(op.getStaticContextParams());
183+
operationModel.setOperationContextParams(op.getOperationContextParams());
183184
operationModel.setAuth(getAuthFromOperation(op));
184185

185186
Input input = op.getInput();

codegen/src/main/java/software/amazon/awssdk/codegen/IntermediateModelBuilder.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import software.amazon.awssdk.codegen.model.intermediate.ShapeModel;
3939
import software.amazon.awssdk.codegen.model.rules.endpoints.EndpointTestSuiteModel;
4040
import software.amazon.awssdk.codegen.model.service.AuthType;
41+
import software.amazon.awssdk.codegen.model.service.CustomOperationContextParam;
4142
import software.amazon.awssdk.codegen.model.service.EndpointRuleSetModel;
4243
import software.amazon.awssdk.codegen.model.service.Operation;
4344
import software.amazon.awssdk.codegen.model.service.Paginators;
@@ -167,10 +168,43 @@ public IntermediateModel build() {
167168
setSimpleMethods(trimmedModel);
168169

169170
namingStrategy.validateCustomerVisibleNaming(trimmedModel);
170-
171+
customizeEndpointParameters(fullModel, endpointRuleSet);
172+
customizeOperationContextParams(trimmedModel, fullModel.getCustomizationConfig().getCustomOperationContextParams());
171173
return trimmedModel;
172174
}
173175

176+
private static void customizeOperationContextParams(IntermediateModel trimmedModel,
177+
List<CustomOperationContextParam> customOperationContextParams) {
178+
179+
if (CollectionUtils.isNullOrEmpty(customOperationContextParams)) {
180+
return;
181+
}
182+
customOperationContextParams.forEach(customOperationContextParam -> {
183+
String operationName = customOperationContextParam.getOperationName();
184+
OperationModel operation = trimmedModel.getOperation(operationName);
185+
if (operation == null) {
186+
throw new IllegalStateException(
187+
"Could not find operation " + operationName + " to customize Operation Context Params.");
188+
}
189+
if (operation.getOperationContextParams() != null) {
190+
throw new IllegalStateException(
191+
"Cannot customize operation " + operationName + " which already has OperationContextParams.");
192+
}
193+
operation.setOperationContextParams(customOperationContextParam.getOperationContextParamsMap());
194+
});
195+
}
196+
197+
private void customizeEndpointParameters(IntermediateModel fullModel, EndpointRuleSetModel endpointRuleSet) {
198+
if (fullModel.getCustomizationConfig().getEndpointParameters() != null) {
199+
fullModel.getCustomizationConfig().getEndpointParameters().keySet().forEach(key -> {
200+
if (endpointRuleSet.getParameters().containsKey(key)) {
201+
throw new IllegalStateException("Duplicate parameters found in customizationConfig");
202+
}
203+
});
204+
fullModel.getCustomizationConfig().getEndpointParameters().forEach(endpointRuleSet.getParameters()::put);
205+
}
206+
}
207+
174208
/**
175209
* Link the member to it's corresponding shape (if it exists).
176210
*

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/GeneratorPathProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,7 @@ public String getAuthSchemeInternalDirectory() {
104104
return sourceDirectory + "/" + Utils.packageToDirectory(model.getMetadata().getFullInternalAuthSchemePackageName());
105105
}
106106

107+
public String getJmesPathInternalDirectory() {
108+
return sourceDirectory + "/" + Utils.packageToDirectory(model.getMetadata().getFullInternalJmesPathPackageName());
109+
}
107110
}

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/EndpointProviderTasks.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import java.util.Arrays;
2020
import java.util.Collection;
2121
import java.util.List;
22+
import java.util.Locale;
2223
import java.util.Map;
2324
import software.amazon.awssdk.codegen.emitters.GeneratorTask;
2425
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
2526
import software.amazon.awssdk.codegen.emitters.PoetGeneratorTask;
2627
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
28+
import software.amazon.awssdk.codegen.model.rules.endpoints.ParameterModel;
2729
import software.amazon.awssdk.codegen.model.service.ClientContextParam;
2830
import software.amazon.awssdk.codegen.poet.rules.ClientContextParamsClassSpec;
2931
import software.amazon.awssdk.codegen.poet.rules.DefaultPartitionDataProviderSpec;
@@ -57,6 +59,9 @@ protected List<GeneratorTask> createTasks() throws Exception {
5759
tasks.add(generateDefaultProvider());
5860
tasks.add(new RulesEngineRuntimeGeneratorTask(generatorTaskParams));
5961
}
62+
if (shouldGenerateJmesPathRuntime()) {
63+
tasks.add(new JmesPathRuntimeGeneratorTask(generatorTaskParams));
64+
}
6065
tasks.addAll(generateInterceptors());
6166
if (shouldGenerateEndpointTests()) {
6267
tasks.add(generateProviderTests());
@@ -149,4 +154,27 @@ private boolean hasClientContextParams() {
149154
(customClientContextParams != null && !customClientContextParams.isEmpty());
150155
}
151156

157+
private boolean shouldGenerateJmesPathRuntime() {
158+
boolean isAlreadyGenerated = model.hasWaiters();
159+
if (isAlreadyGenerated) {
160+
return true;
161+
}
162+
163+
Map<String, ParameterModel> endpointParameters = model.getCustomizationConfig().getEndpointParameters();
164+
if (endpointParameters == null) {
165+
return false;
166+
}
167+
168+
return endpointParameters.values().stream().anyMatch(this::paramRequiresPathParserRuntime);
169+
}
170+
171+
private boolean paramRequiresPathParserRuntime(ParameterModel parameterModel) {
172+
return paramIsOperationalContextParam(parameterModel) &&
173+
"stringarray".equals(parameterModel.getType().toLowerCase(Locale.US));
174+
}
175+
176+
//TODO (string-array-params): resolve this logical test before finalizing coding
177+
private boolean paramIsOperationalContextParam(ParameterModel parameterModel) {
178+
return true;
179+
}
152180
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.emitters.tasks;
17+
18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.io.UncheckedIOException;
21+
import java.util.Collections;
22+
import java.util.List;
23+
import software.amazon.awssdk.codegen.emitters.GeneratorTask;
24+
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
25+
import software.amazon.awssdk.codegen.emitters.SimpleGeneratorTask;
26+
import software.amazon.awssdk.utils.IoUtils;
27+
28+
public final class JmesPathRuntimeGeneratorTask extends BaseGeneratorTasks {
29+
public static final String RUNTIME_CLASS_NAME = "JmesPathRuntime";
30+
31+
private final String runtimeClassDir;
32+
private final String runtimePackageName;
33+
private final String fileHeader;
34+
private final String runtimeClassCode;
35+
36+
public JmesPathRuntimeGeneratorTask(GeneratorTaskParams generatorTaskParams) {
37+
super(generatorTaskParams);
38+
this.runtimeClassDir = generatorTaskParams.getPathProvider().getJmesPathInternalDirectory();
39+
this.runtimePackageName = generatorTaskParams.getModel().getMetadata().getFullInternalJmesPathPackageName();
40+
this.fileHeader = generatorTaskParams.getModel().getFileHeader();
41+
this.runtimeClassCode = loadRuntimeCode();
42+
}
43+
44+
@Override
45+
protected List<GeneratorTask> createTasks() throws Exception {
46+
String codeContents =
47+
"package " + runtimePackageName + ";\n" +
48+
"\n"
49+
+ runtimeClassCode;
50+
51+
String fileName = RUNTIME_CLASS_NAME + ".java";
52+
return Collections.singletonList(new SimpleGeneratorTask(runtimeClassDir, fileName, fileHeader,
53+
() -> codeContents));
54+
}
55+
56+
private static String loadRuntimeCode() {
57+
try {
58+
InputStream is = JmesPathRuntimeGeneratorTask.class.getResourceAsStream(
59+
String.format("/software/amazon/awssdk/codegen/jmespath/%s.java.resource", RUNTIME_CLASS_NAME));
60+
return IoUtils.toUtf8String(is);
61+
} catch (IOException ioe) {
62+
throw new UncheckedIOException(ioe);
63+
}
64+
}
65+
}

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/WaitersGeneratorTasks.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected List<GeneratorTask> createTasks() {
4646
generatorTasks.addAll(createSyncTasks());
4747
generatorTasks.addAll(createAsyncTasks());
4848
generatorTasks.add(new WaitersRuntimeGeneratorTask(generatorTaskParams));
49+
generatorTasks.add(new JmesPathRuntimeGeneratorTask(generatorTaskParams));
4950
return generatorTasks;
5051
}
5152

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/WaitersRuntimeGeneratorTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected List<GeneratorTask> createTasks() throws Exception {
5656
private static String loadWaitersRuntimeCode() {
5757
try {
5858
InputStream is = WaitersRuntimeGeneratorTask.class.getResourceAsStream(
59-
"/software/amazon/awssdk/codegen/waiters/WaitersRuntime.java.resource");
59+
"/software/amazon/awssdk/codegen/waiters/WaitersRuntime.java.resource");
6060
return IoUtils.toUtf8String(is);
6161
} catch (IOException ioe) {
6262
throw new UncheckedIOException(ioe);

codegen/src/main/java/software/amazon/awssdk/codegen/internal/Constant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public final class Constant {
7272

7373
public static final String PACKAGE_NAME_AUTH_SCHEME_PATTERN = "%s.auth.scheme";
7474

75+
public static final String PACKAGE_NAME_JMESPATH_PATTERN = "%s.jmespath";
76+
7577
public static final String PACKAGE_NAME_SMOKE_TEST_PATTERN = "%s.smoketests";
7678

7779
public static final String PACKAGE_NAME_CUSTOM_AUTH_PATTERN = "%s.auth";

0 commit comments

Comments
 (0)