Skip to content

Commit 862420e

Browse files
authored
chore: Fix nightly build (aside from verification) (#1029)
Makes the same changes around avoiding direct calls to instantiate parameterized datatypes in Java code as in aws/aws-cryptographic-material-providers-library#195, plus some CI configuration fixes. Dry runs of nightly builds: * [Library Java tests](https://github.com/aws/aws-database-encryption-sdk-dynamodb/actions/runs/9104958211) * [Java Examples](https://github.com/aws/aws-database-encryption-sdk-dynamodb/actions/runs/9106211948) * [test dotnet](https://github.com/aws/aws-database-encryption-sdk-dynamodb/actions/runs/9100864042) Will leave fixing the verification for a separate PR since this was already a fair bit of work :)
1 parent 6f2825e commit 862420e

File tree

9 files changed

+137
-49
lines changed

9 files changed

+137
-49
lines changed

.github/actions/polymorph_codegen/action.yml

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ runs:
116116
make -C submodules/MaterialProviders/AwsCryptographicMaterialProviders setup_prettier
117117
make -C submodules/MaterialProviders/ComAmazonawsKms setup_prettier
118118
make -C submodules/MaterialProviders/ComAmazonawsDynamodb setup_prettier
119+
make -C submodules/MaterialProviders/TestVectorsAwsCryptographicMaterialProviders setup_prettier
119120
120121
- name: Regenerate Java code using smithy-dafny
121122
# npx seems to be unavailable on Windows GHA runners,

.github/workflows/ci_examples_java.yml

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ jobs:
6060
# A && B || C is the closest thing to an if .. then ... else ... or ?: expression the GitHub Actions syntax supports.
6161
dafny-version: ${{ (github.event_name == 'schedule' || inputs.nightly) && 'nightly-latest' || '4.2.0' }}
6262

63+
- name: Regenerate code using smithy-dafny if necessary
64+
if: ${{ github.event_name == 'schedule' || inputs.nightly }}
65+
uses: ./.github/actions/polymorph_codegen
66+
with:
67+
dafny: ${{ env.DAFNY_VERSION }}
68+
library: DynamoDbEncryption
69+
diff-generated-code: false
70+
update-and-regenerate-mpl: true
71+
6372
- name: Build and locally deploy dependencies for examples
6473
shell: bash
6574
working-directory: ./DynamoDbEncryption

.github/workflows/ci_test_java.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
dafny-version: ${{ (github.event_name == 'schedule' || inputs.nightly) && 'nightly-latest' || '4.2.0' }}
5656

5757
- name: Regenerate code using smithy-dafny if necessary
58-
if: ${{ inputs.nightly }}
58+
if: ${{ github.event_name == 'schedule' || inputs.nightly }}
5959
uses: ./.github/actions/polymorph_codegen
6060
with:
6161
dafny: ${{ env.DAFNY_VERSION }}

.github/workflows/ci_test_net.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
dafny-version: ${{ (github.event_name == 'schedule' || inputs.nightly) && 'nightly-latest' || '4.2.0' }}
6161

6262
- name: Regenerate code using smithy-dafny if necessary
63-
if: ${{ inputs.nightly }}
63+
if: ${{ github.event_name == 'schedule' || inputs.nightly }}
6464
uses: ./.github/actions/polymorph_codegen
6565
with:
6666
dafny: ${{ env.DAFNY_VERSION }}

.github/workflows/ci_verification.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
dafny-version: ${{ (github.event_name == 'schedule' || inputs.nightly) && 'nightly-latest' || '4.6.0' }}
5454

5555
- name: Regenerate code using smithy-dafny if necessary
56-
if: ${{ inputs.nightly }}
56+
if: ${{ github.event_name == 'schedule' || inputs.nightly }}
5757
uses: ./.github/actions/polymorph_codegen
5858
with:
5959
dafny: ${{ env.DAFNY_VERSION }}

DynamoDbEncryption/dafny/DynamoDbItemEncryptor/src/InternalLegacyOverride.dfy

+37
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,43 @@ module {:extern "software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencry
2222

2323
predicate method {:extern} IsLegacyInput(input: Types.DecryptItemInput)
2424

25+
// The following functions are for the benefit of the extern implementation to call,
26+
// avoiding direct references to generic datatype constructors
27+
// since their calling pattern is different between different versions of Dafny
28+
// (i.e. after 4.2, explicit type descriptors are required).
29+
30+
static function method CreateBuildSuccess(value: Option<InternalLegacyOverride>): Result<Option<InternalLegacyOverride>, Types.Error> {
31+
Success(value)
32+
}
33+
34+
static function method CreateBuildFailure(error: Types.Error): Result<Option<InternalLegacyOverride>, Types.Error> {
35+
Failure(error)
36+
}
37+
38+
static function method CreateInternalLegacyOverrideSome(value: InternalLegacyOverride): Option<InternalLegacyOverride> {
39+
Some(value)
40+
}
41+
42+
static function method CreateInternalLegacyOverrideNone(): Option<InternalLegacyOverride> {
43+
None
44+
}
45+
46+
function method CreateEncryptItemSuccess(value: Types.EncryptItemOutput): Result<Types.EncryptItemOutput, Types.Error> {
47+
Success(value)
48+
}
49+
50+
function method CreateEncryptItemFailure(error: Types.Error): Result<Types.EncryptItemOutput, Types.Error> {
51+
Failure(error)
52+
}
53+
54+
function method CreateDecryptItemSuccess(value: Types.DecryptItemOutput): Result<Types.DecryptItemOutput, Types.Error> {
55+
Success(value)
56+
}
57+
58+
function method CreateDecryptItemFailure(error: Types.Error): Result<Types.DecryptItemOutput, Types.Error> {
59+
Failure(error)
60+
}
61+
2562
}
2663

2764
}

DynamoDbEncryption/runtimes/java/src/main/java/software/amazon/cryptography/dbencryptionsdk/dynamodb/itemencryptor/internaldafny/legacy/InternalLegacyOverride.java

+61-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
package software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.internaldafny.legacy;
22

3+
/**
4+
* This file does *NOT* import a lot of things.
5+
* This is because it is dealing with converting
6+
* between different versions of the same name.
7+
* The DynamoDbItemEncryptor module has Dafny and Java versions
8+
* of the same type.
9+
* This means that `EncryptItemOutput` for example
10+
* needs to be disambiguated between the Dafny version and the Java version.
11+
* In order to make it clearer at each call-site exactly what is happening
12+
* the full import is used.
13+
* IDEs tend to fight this so I'm sorry.
14+
*/
15+
16+
import StandardLibraryInternal.InternalResult;
317
import Wrappers_Compile.Option;
418
import Wrappers_Compile.Result;
519
import com.amazonaws.services.dynamodbv2.datamodeling.encryption.DynamoDBEncryptor;
@@ -16,22 +30,9 @@
1630
import software.amazon.cryptography.dbencryptionsdk.dynamodb.internaldafny.types.LegacyPolicy;
1731
import software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.ToNative;
1832
import software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.internaldafny.types.Error;
19-
/**
20-
* This file does *NOT* import a lot of things.
21-
* This is because it is dealing with converting
22-
* between different versions of the same name.
23-
* The DynamoDbItemEncryptor module has Dafny and Java versions
24-
* of the same type.
25-
* This means that `EncryptItemOutput` for example
26-
* needs to be disambiguated between the Dafny version and the Java version.
27-
* In order to make it clearer at each call-site exactly what is happening
28-
* the full import is used.
29-
* IDEs tend to fight this so I'm sorry.
30-
*/
31-
3233
import software.amazon.cryptography.dbencryptionsdk.structuredencryption.internaldafny.types.CryptoAction;
3334

34-
public class InternalLegacyOverride {
35+
public class InternalLegacyOverride extends _ExternBase_InternalLegacyOverride {
3536

3637
private DynamoDBEncryptor encryptor;
3738
private Map<String, Set<EncryptionFlags>> actions;
@@ -69,7 +70,7 @@ public static TypeDescriptor<InternalLegacyOverride> _typeDescriptor() {
6970
);
7071
}
7172

72-
public Boolean IsLegacyInput(
73+
public boolean IsLegacyInput(
7374
software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.internaldafny.types.DecryptItemInput input
7475
) {
7576
//= specification/dynamodb-encryption-client/decrypt-item.md#determining-legacy-items
@@ -94,7 +95,9 @@ > EncryptItem(
9495
) {
9596
// Precondition: Policy MUST allow the caller to encrypt.
9697
if (!_policy.is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT()) {
97-
return createFailure("Legacy Policy does not support encrypt.");
98+
return CreateEncryptItemFailure(
99+
createError("Legacy Policy does not support encrypt.")
100+
);
98101
}
99102

100103
try {
@@ -124,9 +127,9 @@ > EncryptItem(
124127
software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.ToDafny.EncryptItemOutput(
125128
nativeOutput
126129
);
127-
return Result.create_Success(dafnyOutput);
130+
return CreateEncryptItemSuccess(dafnyOutput);
128131
} catch (Exception ex) {
129-
return Result.create_Failure(Error.create_Opaque(ex));
132+
return CreateEncryptItemFailure(Error.create_Opaque(ex));
130133
}
131134
}
132135

@@ -146,7 +149,9 @@ > DecryptItem(
146149
!_policy.is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT() &&
147150
!_policy.is_FORBID__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT()
148151
) {
149-
return createFailure("Legacy Policy does not support decrypt.");
152+
return CreateDecryptItemFailure(
153+
createError("Legacy Policy does not support decrypt.")
154+
);
150155
}
151156
try {
152157
Map<
@@ -175,9 +180,9 @@ > DecryptItem(
175180
software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.ToDafny.DecryptItemOutput(
176181
nativeOutput
177182
);
178-
return Result.create_Success(dafnyOutput);
183+
return CreateDecryptItemSuccess(dafnyOutput);
179184
} catch (Exception ex) {
180-
return Result.create_Failure(Error.create_Opaque(ex));
185+
return CreateDecryptItemFailure(Error.create_Opaque(ex));
181186
}
182187
}
183188

@@ -186,7 +191,7 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
186191
) {
187192
// Check for early return (Postcondition): If there is no legacyOverride there is nothing to do.
188193
if (encryptorConfig.dtor_legacyOverride().is_None()) {
189-
return Result.create_Success(Option.create_None());
194+
return CreateBuildSuccess(CreateInternalLegacyOverrideNone());
190195
}
191196
final software.amazon.cryptography.dbencryptionsdk.dynamodb.internaldafny.types.LegacyOverride legacyOverride =
192197
encryptorConfig.dtor_legacyOverride().dtor_value();
@@ -198,43 +203,48 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
198203

199204
// Precondition: The encryptor MUST be a DynamoDBEncryptor
200205
if (!isDynamoDBEncryptor(maybeEncryptor)) {
201-
return createFailure("Legacy encryptor is not supported");
206+
return CreateBuildFailure(
207+
createError("Legacy encryptor is not supported")
208+
);
202209
}
203210
// Preconditions: MUST be able to create valid encryption context
204-
final Result<EncryptionContext, Error> maybeEncryptionContext =
211+
final InternalResult<EncryptionContext, Error> maybeEncryptionContext =
205212
legacyEncryptionContext(encryptorConfig);
206-
if (maybeEncryptionContext.is_Failure()) {
207-
return Result.create_Failure(maybeEncryptionContext.dtor_error());
213+
if (maybeEncryptionContext.isFailure()) {
214+
return CreateBuildFailure(maybeEncryptionContext.error());
208215
}
209216
// Precondition: All actions MUST be supported types
210-
final Result<Map<String, Set<EncryptionFlags>>, Error> maybeActions =
211-
legacyActions(legacyOverride.dtor_attributeActionsOnEncrypt());
212-
if (maybeActions.is_Failure()) {
213-
return Result.create_Failure(maybeEncryptionContext.dtor_error());
217+
final InternalResult<
218+
Map<String, Set<EncryptionFlags>>,
219+
Error
220+
> maybeActions = legacyActions(
221+
legacyOverride.dtor_attributeActionsOnEncrypt()
222+
);
223+
if (maybeActions.isFailure()) {
224+
return CreateBuildFailure(maybeEncryptionContext.error());
214225
}
215226

216227
final InternalLegacyOverride internalLegacyOverride =
217228
new InternalLegacyOverride(
218229
(DynamoDBEncryptor) maybeEncryptor,
219-
maybeActions.dtor_value(),
220-
maybeEncryptionContext.dtor_value(),
230+
maybeActions.value(),
231+
maybeEncryptionContext.value(),
221232
legacyOverride.dtor_policy()
222233
);
223234

224-
return Result.create_Success(Option.create_Some(internalLegacyOverride));
235+
return CreateBuildSuccess(
236+
CreateInternalLegacyOverrideSome(internalLegacyOverride)
237+
);
225238
}
226239

227240
// Everything below this point is an implementation detail
228241

229-
public static <T> Result<T, Error> createFailure(String message) {
242+
public static Error createError(String message) {
230243
final DafnySequence<Character> dafnyMessage =
231244
software.amazon.smithy.dafny.conversion.ToDafny.Simple.CharacterSequence(
232245
message
233246
);
234-
final Error dafnyEx = Error.create_DynamoDbItemEncryptorException(
235-
dafnyMessage
236-
);
237-
return Result.create_Failure(dafnyEx);
247+
return Error.create_DynamoDbItemEncryptorException(dafnyMessage);
238248
}
239249

240250
public static boolean isDynamoDBEncryptor(
@@ -253,7 +263,10 @@ public static DafnySequence<Character> ToDafnyString(String s) {
253263
);
254264
}
255265

256-
public static Result<EncryptionContext, Error> legacyEncryptionContext(
266+
public static InternalResult<
267+
EncryptionContext,
268+
Error
269+
> legacyEncryptionContext(
257270
software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.internaldafny.types.DynamoDbItemEncryptorConfig config
258271
) {
259272
try {
@@ -272,13 +285,16 @@ public static Result<EncryptionContext, Error> legacyEncryptionContext(
272285
.build()
273286
: encryptionContextBuilder.build();
274287

275-
return Result.create_Success(encryptionContext);
288+
return InternalResult.success(encryptionContext);
276289
} catch (Exception ex) {
277-
return Result.create_Failure(Error.create_Opaque(ex));
290+
return InternalResult.failure(Error.create_Opaque(ex));
278291
}
279292
}
280293

281-
public static Result<Map<String, Set<EncryptionFlags>>, Error> legacyActions(
294+
public static InternalResult<
295+
Map<String, Set<EncryptionFlags>>,
296+
Error
297+
> legacyActions(
282298
DafnyMap<
283299
? extends DafnySequence<? extends Character>,
284300
? extends CryptoAction
@@ -311,14 +327,14 @@ public static Result<Map<String, Set<EncryptionFlags>>, Error> legacyActions(
311327
}
312328
};
313329
attributeActionsOnEncrypt.forEach(buildLegacyActions);
314-
return Result.create_Success(legacyActions);
330+
return InternalResult.success(legacyActions);
315331
} catch (IllegalArgumentException ex) {
316332
final Error dafnyEx = Error.create_DynamoDbItemEncryptorException(
317333
ToDafnyString(ex.getMessage())
318334
);
319-
return Result.create_Failure(dafnyEx);
335+
return InternalResult.failure(dafnyEx);
320336
} catch (Exception ex) {
321-
return Result.create_Failure(Error.create_Opaque(ex));
337+
return InternalResult.failure(Error.create_Opaque(ex));
322338
}
323339
}
324340

DynamoDbEncryption/runtimes/net/DynamoDbEncryption.csproj

+25-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,35 @@
3131
<NoWarn>CS0105,CS0618</NoWarn>
3232
</PropertyGroup>
3333

34+
<PropertyGroup>
35+
<!-- This is somewhat brittle,
36+
but having the value in a properties file
37+
that can be shared is worth it.
38+
See: https://learn.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2022
39+
for more details on property functions
40+
41+
This takes a properties file (a=b)
42+
1. Loads the file
43+
2. Splits on `dafnyVersion=` and takes everything to the right of that
44+
e.g. the version + any trailing data
45+
3. Splits on newline and takes the second element.
46+
This SHOULD be the value of `dafnyVersion` and not contain any trailing data
47+
-->
48+
<projectProperties>
49+
$([System.IO.File]::ReadAllText('$(MSBuildProjectDirectory)/../../../project.properties'))
50+
</projectProperties>
51+
<dropBeforeDafnyVersionProperty>
52+
$([System.Text.RegularExpressions.Regex]::Split("$(projectProperties)", "dafnyVersion=")[1])
53+
</dropBeforeDafnyVersionProperty>
54+
<DafnyVersion>
55+
$([System.Text.RegularExpressions.Regex]::Split("$(dropBeforeDafnyVersionProperty)", "\n")[1])
56+
</DafnyVersion>
57+
</PropertyGroup>
3458

3559
<ItemGroup>
3660
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.303.14"/>
3761
<PackageReference Include="AWSSDK.Core" Version="3.7.304.7"/>
38-
<PackageReference Include="DafnyRuntime" Version="4.2.0" />
62+
<PackageReference Include="DafnyRuntime" Version="$(DafnyVersion)" />
3963
<ProjectReference Include="../../../submodules/MaterialProviders/AwsCryptographicMaterialProviders/runtimes/net/MPL.csproj"/>
4064
<!--
4165
System.Collections.Immutable can be removed once dafny.msbuild is updated with

project.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
projectJavaVersion=3.5.0-SNAPSHOT
22
mplDependencyJavaVersion=1.4.0
3+
dafnyVersion=4.2.0
34
dafnyRuntimeJavaVersion=4.2.0
45
smithyDafnyJavaConversionVersion=0.1

0 commit comments

Comments
 (0)