diff --git a/.github/actions/polymorph_codegen/action.yml b/.github/actions/polymorph_codegen/action.yml index 66d0f7566..bd5fee546 100644 --- a/.github/actions/polymorph_codegen/action.yml +++ b/.github/actions/polymorph_codegen/action.yml @@ -116,6 +116,12 @@ runs: # run: | # make polymorph_rust ${{ steps.dependencies.outputs.PROJECT_DEPENDENCIES }} + - name: Regenerate Go code using smithy-dafny + working-directory: ./${{ inputs.library }} + shell: bash + run: | + make polymorph_go + - name: Check regenerated code against commited code # Composite action inputs seem to not actually support booleans properly for some reason if: inputs.diff-generated-code == 'true' diff --git a/.github/workflows/library_codegen.yml b/.github/workflows/library_codegen.yml index 90922d0fe..d534b5733 100644 --- a/.github/workflows/library_codegen.yml +++ b/.github/workflows/library_codegen.yml @@ -20,6 +20,7 @@ jobs: # Note dotnet is only used for formatting generated code # in this workflow dotnet-version: ["6.0.x"] + go-version: [1.23] os: [ubuntu-latest] runs-on: ${{ matrix.os }} defaults: @@ -61,6 +62,15 @@ jobs: - name: Install Smithy-Dafny codegen dependencies uses: ./.github/actions/install_smithy_dafny_codegen_dependencies + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + + - name: Install Go imports + run: | + go install golang.org/x/tools/cmd/goimports@latest + - uses: ./.github/actions/polymorph_codegen with: dafny: ${{ env.DAFNY_VERSION }} diff --git a/AwsEncryptionSDK/runtimes/go/ImplementationFromDafny-go/WrappedAwsCryptographyEncryptionSdkService/shim.go b/AwsEncryptionSDK/runtimes/go/ImplementationFromDafny-go/WrappedAwsCryptographyEncryptionSdkService/shim.go new file mode 100644 index 000000000..13b92b3a1 --- /dev/null +++ b/AwsEncryptionSDK/runtimes/go/ImplementationFromDafny-go/WrappedAwsCryptographyEncryptionSdkService/shim.go @@ -0,0 +1,43 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package WrappedAwsCryptographyEncryptionSdkService + +import ( + "context" + + "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Wrappers" + "github.com/aws/aws-encryption-sdk-dafny/releases/go/encryption-sdk/AwsCryptographyEncryptionSdkTypes" + "github.com/aws/aws-encryption-sdk-dafny/releases/go/encryption-sdk/awscryptographyencryptionsdksmithygenerated" +) + +type Shim struct { + AwsCryptographyEncryptionSdkTypes.IAwsEncryptionSdkClient + client *awscryptographyencryptionsdksmithygenerated.Client +} + +func (_static *CompanionStruct_Default___) WrappedESDK(inputConfig AwsCryptographyEncryptionSdkTypes.AwsEncryptionSdkConfig) Wrappers.Result { + var nativeConfig = awscryptographyencryptionsdksmithygenerated.AwsEncryptionSdkConfig_FromDafny(inputConfig) + var nativeClient, nativeError = awscryptographyencryptionsdksmithygenerated.NewClient(nativeConfig) + if nativeError != nil { + return Wrappers.Companion_Result_.Create_Failure_(AwsCryptographyEncryptionSdkTypes.Companion_Error_.Create_Opaque_(nativeError)) + } + return Wrappers.Companion_Result_.Create_Success_(&Shim{client: nativeClient}) +} + +func (shim *Shim) Encrypt(input AwsCryptographyEncryptionSdkTypes.EncryptInput) Wrappers.Result { + var native_request = awscryptographyencryptionsdksmithygenerated.EncryptInput_FromDafny(input) + var native_response, native_error = shim.client.Encrypt(context.Background(), native_request) + if native_error != nil { + return Wrappers.Companion_Result_.Create_Failure_(awscryptographyencryptionsdksmithygenerated.Error_ToDafny(native_error)) + } + return Wrappers.Companion_Result_.Create_Success_(awscryptographyencryptionsdksmithygenerated.EncryptOutput_ToDafny(*native_response)) +} + +func (shim *Shim) Decrypt(input AwsCryptographyEncryptionSdkTypes.DecryptInput) Wrappers.Result { + var native_request = awscryptographyencryptionsdksmithygenerated.DecryptInput_FromDafny(input) + var native_response, native_error = shim.client.Decrypt(context.Background(), native_request) + if native_error != nil { + return Wrappers.Companion_Result_.Create_Failure_(awscryptographyencryptionsdksmithygenerated.Error_ToDafny(native_error)) + } + return Wrappers.Companion_Result_.Create_Success_(awscryptographyencryptionsdksmithygenerated.DecryptOutput_ToDafny(*native_response)) +} diff --git a/AwsEncryptionSDK/runtimes/go/TestsFromDafny-go/awscryptographyencryptionsdksmithygeneratedtypes/enums.go b/AwsEncryptionSDK/runtimes/go/TestsFromDafny-go/awscryptographyencryptionsdksmithygeneratedtypes/enums.go new file mode 100644 index 000000000..0322a937c --- /dev/null +++ b/AwsEncryptionSDK/runtimes/go/TestsFromDafny-go/awscryptographyencryptionsdksmithygeneratedtypes/enums.go @@ -0,0 +1,17 @@ +// Code generated by smithy-go-codegen DO NOT EDIT. + +package awscryptographyencryptionsdksmithygeneratedtypes + +type NetV4_0_0_RetryPolicy string + +const ( + NetV4_0_0_RetryPolicyForbidRetry NetV4_0_0_RetryPolicy = "FORBID_RETRY" + NetV4_0_0_RetryPolicyAllowRetry NetV4_0_0_RetryPolicy = "ALLOW_RETRY" +) + +func (NetV4_0_0_RetryPolicy) Values() []NetV4_0_0_RetryPolicy { + return []NetV4_0_0_RetryPolicy{ + "FORBID_RETRY", + "ALLOW_RETRY", + } +} diff --git a/AwsEncryptionSDK/runtimes/go/examples/main.go b/AwsEncryptionSDK/runtimes/go/examples/main.go index aa8ee08e9..c7a5a2abe 100644 --- a/AwsEncryptionSDK/runtimes/go/examples/main.go +++ b/AwsEncryptionSDK/runtimes/go/examples/main.go @@ -22,8 +22,8 @@ import ( "github.com/aws/aws-encryption-sdk-dafny/releases/go/encryption-sdk/examples/keyring/multikeyring" "github.com/aws/aws-encryption-sdk-dafny/releases/go/encryption-sdk/examples/keyring/rawaeskeyring" "github.com/aws/aws-encryption-sdk-dafny/releases/go/encryption-sdk/examples/keyring/rawrsakeyring" - "github.com/aws/aws-encryption-sdk-dafny/releases/go/encryption-sdk/examples/multithreading" "github.com/aws/aws-encryption-sdk-dafny/releases/go/encryption-sdk/examples/misc" + "github.com/aws/aws-encryption-sdk-dafny/releases/go/encryption-sdk/examples/multithreading" "github.com/aws/aws-encryption-sdk-dafny/releases/go/encryption-sdk/examples/utils" )