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

fix: codegen changes for calling aws sdk from local service #538

Merged

Conversation

rishav-karanjit
Copy link
Member

@rishav-karanjit rishav-karanjit commented Aug 23, 2024

Issue #, if available:

Description of changes:

  • Codegen changes for Calling aws sdk from local service
  • Ignoring smithy-dafny-codegen-cli workflows / gradle-build-smithy-dafny (macos-12) (pull_request) because this will be fixed from main

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@rishav-karanjit rishav-karanjit changed the title feat (TestModel): Add CallingAWSSDKFromLocal feat(TestModel): Add CallingAWSSDKFromLocal Aug 23, 2024
@rishav-karanjit rishav-karanjit changed the base branch from main-1.x to Golang/dev September 4, 2024 00:30
@rishav-karanjit rishav-karanjit changed the base branch from Golang/dev to main-1.x September 4, 2024 00:31

# Go

GO_DEPENDENCY_MODULE_NAMES := \
--dependency-library-name=com.amazonaws.kms=github.com/smithy-lang/smithy-dafny/kmsv2 \
--dependency-library-name=com.amazonaws.dynamodb=github.com/smithy-lang/smithy-dafny/ddbv2
--dependency-library-name=com.amazonaws.dynamodb=github.com/smithy-lang/smithy-dafny/ddbv2 \
--dependency-library-name=sdk.com.amazonaws.dynamodb=github.com/aws/aws-sdk-go-v2/service/dynamodb \
Copy link
Member Author

Choose a reason for hiding this comment

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

I need this to import kms or dynamodb and make client in native side

Copy link
Contributor

Choose a reason for hiding this comment

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

What would happen if the namespace for our model and the sdk collides?

@@ -45,10 +49,47 @@ structure CallDDBScanInput {
}

structure CallDDBScanOutput {
@required
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing required because I will have to return a value if its required. Also, having a check expect itemOutput.Value.Some? makes more sense

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not return 0 since this is an Integer?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I return 0 and if DDB has 0 item, the success case will have false failure.

conditionExpression: com.amazonaws.dynamodb#ConditionExpression
}

structure CallDDBPutItemOutput {
Copy link
Member Author

Choose a reason for hiding this comment

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

There is nothing I could return from PutItem call. So, this is empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

PutItemOutput.Attributes will return empty unless putitem has overridden a item

@@ -1,56 +0,0 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
Copy link
Member Author

Choose a reason for hiding this comment

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

Unlike what git diff shows. This is renaming file. Not removing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

This file is also a file name renaming change not deleting it.

@@ -806,7 +814,8 @@ private void generateSerializerFunctions(
);
var inputType = GoCodegenUtils.getType(
context.symbolProvider().toSymbol(visitingShape),
serviceShape.expectTrait(ServiceTrait.class)
serviceShape.expectTrait(ServiceTrait.class),
true
Copy link
Member Author

Choose a reason for hiding this comment

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

GoCodegenUtils.getType has now an update so that we can say to include namespace in the types or not. Previously, this boolean was not there so this is updated.

@@ -689,6 +689,8 @@ private class GoSymbolFormatter
public String apply(Object type, String indent) {
if (type instanceof Symbol) {
Symbol resolvedSymbol = (Symbol) type;
// get symbol name for literal
// Note: This literal could be changed in upcoming codes in this if block
Copy link
Member Author

Choose a reason for hiding this comment

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

Just some comments because I got confused read this codes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any change in the literal though? Aren't we required to change this to use map[string][ddbtypes.AttributeValue] ?

Copy link
Member Author

Choose a reason for hiding this comment

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

.build()
);
} else {
builder.putProperty(
"Referred",
symbolBuilderFor(
referredShape,
"I".concat(getDefaultShapeName(referredShape))
Copy link
Member Author

Choose a reason for hiding this comment

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

We have reversed the if else loop. So, this is in diff.

var inputType = GoCodegenUtils.getType(
symbolProvider.toSymbol(currentShape),
currentShape
currentShape,
isExternalShape
Copy link
Member Author

Choose a reason for hiding this comment

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

If external shape then include namespace or else don't include

@@ -60,9 +62,14 @@ public static String shapeNamespace(final Shape shape) {
}

public static String smithyTypesNamespace(final Shape shape) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The type namespace for service should be "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" (or KMS one) but there can be multiple service in a model and this will cause confusion between kms and ddb. So, I have decided to make it kmstypes or dynamodbtypes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes - we always need to alias it.

Copy link
Contributor

@ShubhamChaturvedi7 ShubhamChaturvedi7 left a comment

Choose a reason for hiding this comment

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

Some suggestions / clarifications below, otherwise LGTM.

@@ -45,10 +49,47 @@ structure CallDDBScanInput {
}

structure CallDDBScanOutput {
@required
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not return 0 since this is an Integer?


# Go

GO_DEPENDENCY_MODULE_NAMES := \
--dependency-library-name=com.amazonaws.kms=github.com/smithy-lang/smithy-dafny/kmsv2 \
--dependency-library-name=com.amazonaws.dynamodb=github.com/smithy-lang/smithy-dafny/ddbv2
--dependency-library-name=com.amazonaws.dynamodb=github.com/smithy-lang/smithy-dafny/ddbv2 \
--dependency-library-name=sdk.com.amazonaws.dynamodb=github.com/aws/aws-sdk-go-v2/service/dynamodb \
Copy link
Contributor

Choose a reason for hiding this comment

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

What would happen if the namespace for our model and the sdk collides?

@@ -689,6 +689,8 @@ private class GoSymbolFormatter
public String apply(Object type, String indent) {
if (type instanceof Symbol) {
Symbol resolvedSymbol = (Symbol) type;
// get symbol name for literal
// Note: This literal could be changed in upcoming codes in this if block
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any change in the literal though? Aren't we required to change this to use map[string][ddbtypes.AttributeValue] ?

Comment on lines +393 to +395
if (shape.hasTrait(ServiceTrait.class)) {
namespace =
shape.expectTrait(ServiceTrait.class).getSdkId().toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh so this is where the map case get handled as well.

Comment on lines +495 to +512
if (isExternalShape) {
if (SmithyNameResolver.isShapeFromAWSSDK(currentShape)) {
writer.addImportFromModule(
SmithyNameResolver.getGoModuleNameForSdkNamespace(
currentShape.getId().getNamespace()
),
"types",
SmithyNameResolver.smithyTypesNamespace(currentShape)
);
} else {
writer.addImportFromModule(
SmithyNameResolver.getGoModuleNameForSmithyNamespace(
currentShape.getId().getNamespace()
),
SmithyNameResolver.smithyTypesNamespace(currentShape)
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: This could be moved inside the SmithyNameResolver.

@@ -60,9 +62,14 @@ public static String shapeNamespace(final Shape shape) {
}

public static String smithyTypesNamespace(final Shape shape) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes - we always need to alias it.

Comment on lines +244 to +252
if (SmithyNameResolver.isShapeFromAWSSDK(shape)) {
writer.addImportFromModule(
SmithyNameResolver.getGoModuleNameForSdkNamespace(
shape.getId().getNamespace()
),
"types",
SmithyNameResolver.smithyTypesNamespace(shape)
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, all this can be moved inside the NameResolver and we can then avoid this repetition.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's do it in next PR once positional is merged.

@rishav-karanjit rishav-karanjit merged commit 02579d9 into rishav-awssdkFromLocal-Testmodel Nov 4, 2024
85 of 86 checks passed
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.

2 participants