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

Async S3 Client Presigned Url Download API #5587

Open
wants to merge 9 commits into
base: feature/master/presigned-url-download
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ private Map<String, ShapeModel> constructInputShapes() {
Input input = operation.getInput();

if (input != null) {
if (input.getFqcn() != null) {
ShapeModel shapeModel = new ShapeModel();
shapeModel.setFqcn(input.getFqcn());
shapeModel.setMarshallerFqcn(input.getMarshallerFqcn());
shapeModel.setType(ShapeType.Request);
javaShapes.put(operationName, shapeModel);
continue;
}

String javaRequestShapeName = getNamingStrategy()
.getRequestClassName(operationName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -183,12 +184,21 @@ public Map<String, OperationModel> constructOperations() {
operationModel.setOperationContextParams(op.getOperationContextParams());
operationModel.setAuth(getAuthFromOperation(op));

if (op.getInput() != null && op.getInput().getFqcn() != null) {
operationModel.setPresignedUrl(op.getInput().getFqcn().toLowerCase(Locale.ROOT).contains("presigned"));
}

Input input = op.getInput();
if (input != null) {
String originalShapeName = input.getShape();
String inputShape = namingStrategy.getRequestClassName(operationName);
String documentation = input.getDocumentation() != null ? input.getDocumentation() :
c2jShapes.get(originalShapeName).getDocumentation();

String documentation = null;
if (input.getDocumentation() != null) {
documentation = input.getDocumentation();
} else if (c2jShapes.get(originalShapeName) != null) {
documentation = c2jShapes.get(originalShapeName).getDocumentation();
}

operationModel.setInput(new VariableModel(unCapitalize(inputShape), inputShape)
.withDocumentation(documentation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,11 @@ private boolean isGreedy(Shape parentShape, Map<String, Shape> allC2jShapes, Par
*/
private String findRequestUri(Shape parentShape, Map<String, Shape> allC2jShapes) {
return builder.getService().getOperations().values().stream()
.filter(o -> o.getInput() != null)
.filter(o -> allC2jShapes.get(o.getInput().getShape()).equals(parentShape))
.map(o -> o.getHttp().getRequestUri())
.findFirst().orElseThrow(() -> new RuntimeException("Could not find request URI for input shape"));
.filter(o -> o.getInput() != null)
.filter(o -> allC2jShapes.get(o.getInput().getShape()) != null)
.filter(o -> allC2jShapes.get(o.getInput().getShape()).equals(parentShape))
.map(o -> o.getHttp().getRequestUri())
.findFirst().orElseThrow(() -> new RuntimeException("Could not find request URI for input shape"));
}

private String deriveUnmarshallerLocationName(Shape memberShape, String memberName, Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
import software.amazon.awssdk.codegen.model.intermediate.MemberModel;
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
import software.amazon.awssdk.codegen.model.intermediate.ShapeModel;
import software.amazon.awssdk.codegen.model.intermediate.ShapeType;
import software.amazon.awssdk.codegen.model.rules.endpoints.EndpointTestSuiteModel;
import software.amazon.awssdk.codegen.model.service.AuthType;
import software.amazon.awssdk.codegen.model.service.CustomOperationContextParam;
import software.amazon.awssdk.codegen.model.service.EndpointRuleSetModel;
import software.amazon.awssdk.codegen.model.service.Input;
import software.amazon.awssdk.codegen.model.service.Operation;
import software.amazon.awssdk.codegen.model.service.Paginators;
import software.amazon.awssdk.codegen.model.service.ServiceModel;
Expand Down Expand Up @@ -221,21 +223,28 @@ private void linkMembersToShapes(IntermediateModel model) {
}

private void linkOperationsToInputOutputShapes(IntermediateModel model) {
for (Map.Entry<String, OperationModel> entry : model.getOperations().entrySet()) {

Operation operation = service.getOperations().get(entry.getKey());

if (entry.getValue().getInput() != null) {
entry.getValue().setInputShape(model.getShapes().get(entry.getValue().getInput().getSimpleType()));
model.getOperations().forEach((key, value) -> {

Operation operation = service.getOperations().get(key);

Input input = operation.getInput();
if (input != null && input.getFqcn() != null) {
ShapeModel shapeModel = new ShapeModel();
shapeModel.setFqcn(input.getFqcn());
shapeModel.setMarshallerFqcn(input.getMarshallerFqcn());
shapeModel.setType(ShapeType.Request);
value.setInputShape(shapeModel);
} else if (value.getInput() != null) {
value.setInputShape(model.getShapes().get(value.getInput().getSimpleType()));
}

if (operation.getOutput() != null) {
String outputShapeName = operation.getOutput().getShape();
ShapeModel outputShape =
model.getShapeByNameAndC2jName(entry.getValue().getReturnType().getReturnType(), outputShapeName);
entry.getValue().setOutputShape(outputShape);
model.getShapeByNameAndC2jName(value.getReturnType().getReturnType(), outputShapeName);
value.setOutputShape(outputShape);
}
}
});
}

private void linkCustomAuthorizationToRequestShapes(IntermediateModel model) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.customization.processors;

import java.util.Map;
import software.amazon.awssdk.codegen.customization.CodegenCustomizationProcessor;
import software.amazon.awssdk.codegen.model.config.customization.CustomSdkOperations;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.service.Operation;
import software.amazon.awssdk.codegen.model.service.ServiceModel;

public class CustomSdkOperationsProcessor implements CodegenCustomizationProcessor {

private final CustomSdkOperations customSdkOperations;

CustomSdkOperationsProcessor(CustomSdkOperations customSdkOperations) {
this.customSdkOperations = customSdkOperations;
}

@Override
public void preprocess(ServiceModel serviceModel) {
Map<String, Operation> operations = serviceModel.getOperations();

if (customSdkOperations != null) {
operations.putAll(customSdkOperations.getOperations());
serviceModel.setOperations(operations);
}
}

@Override
public void postprocess(IntermediateModel intermediateModel) {
// added custom operations in service model instead of intermediate model
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static CodegenCustomizationProcessor getProcessorFor(
new ShapeModifiersProcessor(config.getShapeModifiers()),
new ShapeSubstitutionsProcessor(config.getShapeSubstitutions()),
new CustomSdkShapesProcessor(config.getCustomSdkShapes()),
new CustomSdkOperationsProcessor(config.getCustomSdkOperations()),
new OperationModifiersProcessor(config.getOperationModifiers()),
new RemoveExceptionMessagePropertyProcessor(),
new UseLegacyEventGenerationSchemeProcessor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void postprocess(IntermediateModel intermediateModel) {
}

private boolean isExplicitStringPayload(Map<String, Shape> c2jShapes, Shape shape) {
if (shape.getPayload() == null) {
if (shape == null || shape.getPayload() == null) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ public static ShapeModel findMemberShapeModelByC2jNameIfExists(IntermediateModel
}

public static List<ShapeModel> findShapesByC2jName(IntermediateModel intermediateModel, String shapeC2jName) {
return intermediateModel.getShapes().values().stream().filter(s -> s.getC2jName().equals(shapeC2jName)).collect(toList());
return intermediateModel.getShapes().values().stream()
.filter(s -> s.getC2jName() != null)
.filter(s -> s.getC2jName().equals(shapeC2jName)).collect(toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

we can do shapeC2jName.equals to avoid additional null check as below

intermediateModel.getShapes().values().stream()
    .filter(s -> shapeC2jName.equals(s.getC2jName()))
    .collect(toList());

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.model.config.customization;

import java.util.Collections;
import java.util.Map;
import software.amazon.awssdk.codegen.model.service.Operation;

public class CustomSdkOperations {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please mention the Json in Java doc of how this class looks like

private Map<String, Operation> operations;
Copy link
Contributor

Choose a reason for hiding this comment

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

operations more sounds like List , can we rename it to something that conveys its a Map


public Map<String, Operation> getOperations() {
return operations;
}

public void setOperations(Map<String, Operation> operations) {
this.operations = operations != null ? Collections.unmodifiableMap(operations) : Collections.emptyMap();
}

public Operation getOperation(String operationName) {
return operations.get(operationName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class CustomizationConfig {
private Map<String, OperationModifier> operationModifiers;
private Map<String, ShapeSubstitution> shapeSubstitutions;
private CustomSdkShapes customSdkShapes;
private CustomSdkOperations customSdkOperations;
private Map<String, ShapeModifier> shapeModifiers;
/**
* Sets the custom field name that identifies the type of modeled exception for JSON protocols.
Expand Down Expand Up @@ -373,6 +374,14 @@ public void setCustomSdkShapes(CustomSdkShapes customSdkShapes) {
this.customSdkShapes = customSdkShapes;
}

public CustomSdkOperations getCustomSdkOperations() {
return customSdkOperations;
}

public void setCustomSdkOperations(CustomSdkOperations customSdkOperations) {
this.customSdkOperations = customSdkOperations;
}

public Map<String, ShapeSubstitution> getShapeSubstitutions() {
return shapeSubstitutions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class OperationModel extends DocumentationModel {

private boolean httpChecksumRequired;

private boolean isPresignedUrl;

private HttpChecksum httpChecksum;

private RequestCompression requestcompression;
Expand Down Expand Up @@ -338,6 +340,14 @@ public void setHttpChecksumRequired(boolean httpChecksumRequired) {
this.httpChecksumRequired = httpChecksumRequired;
}

public boolean isPresignedUrl() {
return isPresignedUrl;
}

public void setPresignedUrl(boolean isPresignedUrl) {
this.isPresignedUrl = isPresignedUrl;
}

public HttpChecksum getHttpChecksum() {
return httpChecksum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class ShapeModel extends DocumentationModel implements HasDeprecation {
private String c2jName;
// shapeName might be later modified by the customization.
private String shapeName;
private String fqcn;
private String marshallerFqcn;
// the local variable name inside marshaller/unmarshaller implementation
private boolean deprecated;
private String deprecatedMessage;
Expand Down Expand Up @@ -93,6 +95,22 @@ public void setShapeName(String shapeName) {
this.shapeName = shapeName;
}

public String getFqcn() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I donot think we should directly gives Fqcn for operations , We already have

  "customSdkShapes": {
    "shapes":{
      "SdkPartType":{
        "type":"string",
        "enum":[
          "DEFAULT",
          "LAST"
        ]
      }
    }
  }

Can we use it and pass the input and outputs as modeled structures ?

return fqcn;
}

public void setFqcn(String fqcn) {
this.fqcn = fqcn;
}

public String getMarshallerFqcn() {
return marshallerFqcn;
}

public void setMarshallerFqcn(String marshallerFqcn) {
this.marshallerFqcn = marshallerFqcn;
}

@Override
public boolean isDeprecated() {
return deprecated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class Input {

private String shape;

private String fqcn;

private String marshallerFqcn;

private String documentation;

private String locationName;
Expand All @@ -33,6 +37,22 @@ public void setShape(String shape) {
this.shape = shape;
}

public String getFqcn() {
return fqcn;
}

public void setFqcn(String fqcn) {
this.fqcn = fqcn;
}

public String getMarshallerFqcn() {
return marshallerFqcn;
}

public void setMarshallerFqcn(String marshallerFqcn) {
this.marshallerFqcn = marshallerFqcn;
}

public String getDocumentation() {
return documentation;
}
Expand Down
Loading
Loading