From e7190d26dfe5a8e81b59dc007cf8d42c26fad819 Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Wed, 13 Sep 2023 16:04:18 +0000
Subject: [PATCH 01/10] Update dependency
org.springframework.boot:spring-boot-dependencies to v3
---
cryptoshred-micrometer/pom.xml | 2 +-
cryptoshred-spring-boot-autoconfigure/pom.xml | 2 +-
cryptoshred-spring-cloud-aws/pom.xml | 2 +-
pom.xml | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/cryptoshred-micrometer/pom.xml b/cryptoshred-micrometer/pom.xml
index 824dae6f..7e54e8c4 100644
--- a/cryptoshred-micrometer/pom.xml
+++ b/cryptoshred-micrometer/pom.xml
@@ -13,7 +13,7 @@
cryptoshred-micrometer
- 2.7.15
+ 3.1.3
diff --git a/cryptoshred-spring-boot-autoconfigure/pom.xml b/cryptoshred-spring-boot-autoconfigure/pom.xml
index 7de03cec..62a11fbd 100644
--- a/cryptoshred-spring-boot-autoconfigure/pom.xml
+++ b/cryptoshred-spring-boot-autoconfigure/pom.xml
@@ -13,7 +13,7 @@
cryptoshred-spring-boot-autoconfiguration
- 2.7.15
+ 3.1.3
diff --git a/cryptoshred-spring-cloud-aws/pom.xml b/cryptoshred-spring-cloud-aws/pom.xml
index 51bf2482..97b16417 100644
--- a/cryptoshred-spring-cloud-aws/pom.xml
+++ b/cryptoshred-spring-cloud-aws/pom.xml
@@ -13,7 +13,7 @@
cryptoshred-spring-cloud-aws
- 2.7.15
+ 3.1.3
diff --git a/pom.xml b/pom.xml
index 9362fb42..56b95b92 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,7 +52,7 @@
1.18.6
2.15.2
1.7.36
- 2.7.15
+ 3.1.3
${basedir}/src/etc
2.39.0
From cfa2bb99e16c8e68fefdc3b1735a3b386189e525 Mon Sep 17 00:00:00 2001
From: Benjamin Otto
Date: Wed, 13 Sep 2023 18:28:57 +0200
Subject: [PATCH 02/10] use aws sdk v2
---
cryptoshred-cloud-aws/pom.xml | 6 +-
.../cloud/aws/CreateCryptoKeyRequest.java | 29 +++++----
.../aws/DynamoDBCryptoKeyRepository.java | 15 +++--
.../cloud/aws/GetCryptoKeyRequest.java | 15 +++--
.../cryptoshred/cloud/aws/Utils.java | 15 +++--
...oDBCryptoKeyRepositoryIntegrationTest.java | 63 +++++++++---------
.../aws/DynamoDBCryptoKeyRepositoryTest.java | 65 +++++++++----------
.../cloud/aws/GetCryptoKeyRequestTest.java | 10 +--
.../cryptoshred/cloud/aws/UtilsTest.java | 22 ++++---
pom.xml | 4 +-
10 files changed, 124 insertions(+), 120 deletions(-)
diff --git a/cryptoshred-cloud-aws/pom.xml b/cryptoshred-cloud-aws/pom.xml
index 85fdbeb3..043f42c5 100644
--- a/cryptoshred-cloud-aws/pom.xml
+++ b/cryptoshred-cloud-aws/pom.xml
@@ -20,9 +20,9 @@
- com.amazonaws
- aws-java-sdk-dynamodb
- 1.12.549
+ software.amazon.awssdk
+ dynamodb
+ 2.20.145
diff --git a/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/CreateCryptoKeyRequest.java b/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/CreateCryptoKeyRequest.java
index 0cfb321a..dd8f655b 100644
--- a/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/CreateCryptoKeyRequest.java
+++ b/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/CreateCryptoKeyRequest.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2020 PRISMA European Capacity Platform GmbH
+ * Copyright © 2020-2023 PRISMA European Capacity Platform GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,16 +15,16 @@
*/
package eu.prismacapacity.cryptoshred.cloud.aws;
-import com.amazonaws.services.dynamodbv2.model.AttributeValue;
-import com.amazonaws.services.dynamodbv2.model.ReturnValue;
-import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest;
import eu.prismacapacity.cryptoshred.core.CryptoAlgorithm;
import eu.prismacapacity.cryptoshred.core.CryptoSubjectId;
import eu.prismacapacity.cryptoshred.core.keys.CryptoKey;
import eu.prismacapacity.cryptoshred.core.keys.CryptoKeySize;
-import java.nio.ByteBuffer;
import lombok.NonNull;
import lombok.Value;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+import software.amazon.awssdk.services.dynamodb.model.ReturnValue;
+import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest;
@Value(staticConstructor = "of")
class CreateCryptoKeyRequest {
@@ -39,14 +39,15 @@ class CreateCryptoKeyRequest {
@NonNull private final String tableName;
UpdateItemRequest toDynamoRequest() {
- return new UpdateItemRequest()
- .withTableName(tableName)
- .withKey(Utils.subjectIdToKeyAttributeMap(subjectId))
- .withConditionExpression("attribute_not_exists(#k)")
- .withUpdateExpression("SET #k = :v")
- .withExpressionAttributeNames(Maps.of("#k", Utils.generateKeyPropertyName(algorithm, size)))
- .withReturnValues(ReturnValue.ALL_NEW)
- .withExpressionAttributeValues(
- Maps.of(":v", new AttributeValue().withB(ByteBuffer.wrap(key.getBytes()))));
+ return UpdateItemRequest.builder()
+ .tableName(tableName)
+ .key(Utils.subjectIdToKeyAttributeMap(subjectId))
+ .conditionExpression("attribute_not_exists(#k)")
+ .updateExpression("SET #k = :v")
+ .expressionAttributeNames(Maps.of("#k", Utils.generateKeyPropertyName(algorithm, size)))
+ .returnValues(ReturnValue.ALL_NEW)
+ .expressionAttributeValues(
+ Maps.of(":v", AttributeValue.fromB(SdkBytes.fromByteArray(key.getBytes()))))
+ .build();
}
}
diff --git a/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepository.java b/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepository.java
index 485fb706..d56c1e21 100644
--- a/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepository.java
+++ b/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepository.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2020 PRISMA European Capacity Platform GmbH
+ * Copyright © 2020-2023 PRISMA European Capacity Platform GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,8 +15,8 @@
*/
package eu.prismacapacity.cryptoshred.cloud.aws;
-import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
-import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
+import java.util.Optional;
+
import eu.prismacapacity.cryptoshred.core.CryptoAlgorithm;
import eu.prismacapacity.cryptoshred.core.CryptoEngine;
import eu.prismacapacity.cryptoshred.core.CryptoSubjectId;
@@ -25,10 +25,11 @@
import eu.prismacapacity.cryptoshred.core.keys.CryptoKeyRepository;
import eu.prismacapacity.cryptoshred.core.keys.CryptoKeySize;
import eu.prismacapacity.cryptoshred.core.metrics.CryptoMetrics;
-import java.util.Optional;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.val;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+import software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException;
/**
* CryptoKeyRepository implementation based on AWS DynamoDB. Supports multiple keys (algorithm +
@@ -40,7 +41,7 @@
public class DynamoDBCryptoKeyRepository implements CryptoKeyRepository {
@NonNull private final CryptoEngine engine;
- @NonNull private final AmazonDynamoDB dynamoDB;
+ @NonNull private final DynamoDbClient dynamoDB;
@NonNull private final CryptoMetrics metrics;
@@ -55,7 +56,7 @@ public Optional findKeyFor(
val getRequest = GetCryptoKeyRequest.of(subjectId, algorithm, size, tableName);
- val item = metrics.timedFindKey(() -> dynamoDB.getItem(getRequest.toDynamoRequest()).getItem());
+ val item = metrics.timedFindKey(() -> dynamoDB.getItem(getRequest.toDynamoRequest()).item());
if (item == null) {
return Optional.empty();
@@ -83,7 +84,7 @@ protected CryptoKey createCryptoKey(
val result =
metrics.timedCreateKey(() -> dynamoDB.updateItem(createRequest.toDynamoRequest()));
- val resultKey = Utils.extractCryptoKeyFromItem(algorithm, size, result.getAttributes());
+ val resultKey = Utils.extractCryptoKeyFromItem(algorithm, size, result.attributes());
if (!resultKey.isPresent()) {
// should never ever happen because that would indicate a broken DynamoDB API
diff --git a/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/GetCryptoKeyRequest.java b/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/GetCryptoKeyRequest.java
index 4f9dc2c8..c496b07e 100644
--- a/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/GetCryptoKeyRequest.java
+++ b/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/GetCryptoKeyRequest.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2020 PRISMA European Capacity Platform GmbH
+ * Copyright © 2020-2023 PRISMA European Capacity Platform GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,12 @@
*/
package eu.prismacapacity.cryptoshred.cloud.aws;
-import com.amazonaws.services.dynamodbv2.model.GetItemRequest;
import eu.prismacapacity.cryptoshred.core.CryptoAlgorithm;
import eu.prismacapacity.cryptoshred.core.CryptoSubjectId;
import eu.prismacapacity.cryptoshred.core.keys.CryptoKeySize;
import lombok.NonNull;
import lombok.Value;
+import software.amazon.awssdk.services.dynamodb.model.GetItemRequest;
@Value(staticConstructor = "of")
class GetCryptoKeyRequest {
@@ -33,10 +33,11 @@ class GetCryptoKeyRequest {
@NonNull private final String tableName;
GetItemRequest toDynamoRequest() {
- return new GetItemRequest()
- .withTableName(tableName)
- .withKey(Utils.subjectIdToKeyAttributeMap(subjectId))
- .withConsistentRead(true)
- .withProjectionExpression(Utils.generateKeyPropertyName(algorithm, size));
+ return GetItemRequest.builder()
+ .tableName(tableName)
+ .key(Utils.subjectIdToKeyAttributeMap(subjectId))
+ .consistentRead(true)
+ .projectionExpression(Utils.generateKeyPropertyName(algorithm, size))
+ .build();
}
}
diff --git a/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/Utils.java b/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/Utils.java
index f45fa34a..75ded562 100644
--- a/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/Utils.java
+++ b/cryptoshred-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/cloud/aws/Utils.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2020 PRISMA European Capacity Platform GmbH
+ * Copyright © 2020-2023 PRISMA European Capacity Platform GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,18 +15,19 @@
*/
package eu.prismacapacity.cryptoshred.cloud.aws;
-import com.amazonaws.services.dynamodbv2.model.AttributeValue;
+import java.util.Map;
+import java.util.Optional;
+
import eu.prismacapacity.cryptoshred.core.CryptoAlgorithm;
import eu.prismacapacity.cryptoshred.core.CryptoSubjectId;
import eu.prismacapacity.cryptoshred.core.keys.CryptoKey;
import eu.prismacapacity.cryptoshred.core.keys.CryptoKeySize;
-import java.util.Map;
-import java.util.Optional;
import lombok.val;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
class Utils {
static Map subjectIdToKeyAttributeMap(CryptoSubjectId subjectId) {
- return Maps.of("subjectId", new AttributeValue(subjectId.getId().toString()));
+ return Maps.of("subjectId", AttributeValue.fromS(subjectId.getId().toString()));
}
static String generateKeyPropertyName(CryptoAlgorithm algorithm, CryptoKeySize size) {
@@ -42,12 +43,12 @@ static Optional extractCryptoKeyFromItem(
return Optional.empty();
}
- val bytes = keyAttributeValue.getB();
+ val bytes = keyAttributeValue.b();
if (bytes == null) {
return Optional.empty();
}
- return Optional.of(CryptoKey.fromBytes(bytes.array()));
+ return Optional.of(CryptoKey.fromBytes(bytes.asByteArray()));
}
}
diff --git a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryIntegrationTest.java b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryIntegrationTest.java
index f4cc33bf..842b32eb 100644
--- a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryIntegrationTest.java
+++ b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryIntegrationTest.java
@@ -18,7 +18,6 @@
import static org.junit.Assert.*;
import java.net.URI;
-import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.UUID;
@@ -28,13 +27,6 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
-import com.amazonaws.client.builder.AwsClientBuilder;
-import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
-import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
-import com.amazonaws.services.dynamodbv2.model.*;
-import com.amazonaws.waiters.WaiterParameters;
-
import eu.prismacapacity.cryptoshred.cloud.aws.utils.TestIntegration;
import eu.prismacapacity.cryptoshred.core.*;
import eu.prismacapacity.cryptoshred.core.keys.CryptoKey;
@@ -42,6 +34,10 @@
import eu.prismacapacity.cryptoshred.core.metrics.CryptoMetrics;
import lombok.NonNull;
import lombok.val;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+import software.amazon.awssdk.services.dynamodb.model.*;
@Testcontainers
class DynamoDBCryptoKeyRepositoryIntegrationTest {
@@ -59,20 +55,25 @@ public static void setUp() {
val client = getClient();
client.createTable(
- new CreateTableRequest()
- .withTableName(TABLE_NAME)
- .withKeySchema(
- new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName("subjectId"))
- .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L))
- .withAttributeDefinitions(
- new AttributeDefinition()
- .withAttributeName("subjectId")
- .withAttributeType(ScalarAttributeType.S)));
-
- val describeTable = new DescribeTableRequest().withTableName(TABLE_NAME);
- val waitParams = new WaiterParameters().withRequest(describeTable);
-
- client.waiters().tableExists().run(waitParams);
+ CreateTableRequest.builder()
+ .tableName(TABLE_NAME)
+ .keySchema(
+ KeySchemaElement.builder().keyType(KeyType.HASH).attributeName("subjectId").build())
+ .provisionedThroughput(
+ ProvisionedThroughput.builder()
+ .readCapacityUnits(10L)
+ .writeCapacityUnits(10L)
+ .build())
+ .attributeDefinitions(
+ AttributeDefinition.builder()
+ .attributeName("subjectId")
+ .attributeType(ScalarAttributeType.S)
+ .build())
+ .build());
+
+ val describeTable = DescribeTableRequest.builder().tableName(TABLE_NAME).build();
+
+ client.waiter().waitUntilTableExists(describeTable);
}
@TestIntegration
@@ -171,7 +172,7 @@ class RaceConditionCryptoKeyRepository extends DynamoDBCryptoKeyRepository {
public RaceConditionCryptoKeyRepository(
@NonNull CryptoEngine engine,
- @NonNull AmazonDynamoDB dynamoDB,
+ @NonNull DynamoDbClient dynamoDB,
@NonNull CryptoMetrics metrics,
@NonNull String tableName,
CryptoKey key) {
@@ -194,24 +195,22 @@ private void addExampleKey(
val client = getClient();
val item = new HashMap();
- item.put("subjectId", new AttributeValue(subjectId.getId().toString()));
+ item.put("subjectId", AttributeValue.fromS(subjectId.getId().toString()));
item.put(
Utils.generateKeyPropertyName(algorithm, size),
- new AttributeValue().withB(ByteBuffer.wrap(key.getBytes())));
+ AttributeValue.fromB(SdkBytes.fromByteArray(key.getBytes())));
- val request = new PutItemRequest().withTableName(TABLE_NAME).withItem(item);
+ val request = PutItemRequest.builder().tableName(TABLE_NAME).item(item).build();
client.putItem(request);
}
- private static AmazonDynamoDB getClient() {
+ private static DynamoDbClient getClient() {
final URI endpointOverride =
localstack.getEndpointOverride(LocalStackContainer.Service.DYNAMODB);
- return AmazonDynamoDBClientBuilder.standard()
- .withEndpointConfiguration(
- new AwsClientBuilder.EndpointConfiguration(
- endpointOverride.toString(), localstack.getRegion()))
- .withCredentials(new DefaultAWSCredentialsProviderChain())
+ return DynamoDbClient.builder()
+ .endpointOverride(endpointOverride)
+ .region(Region.US_EAST_1)
.build();
}
}
diff --git a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryTest.java b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryTest.java
index 1f84469b..97071b59 100644
--- a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryTest.java
+++ b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2020 PRISMA European Capacity Platform GmbH
+ * Copyright © 2020-2023 PRISMA European Capacity Platform GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,13 +19,15 @@
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
-import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
-import com.amazonaws.services.dynamodbv2.model.AttributeValue;
-import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
-import com.amazonaws.services.dynamodbv2.model.GetItemRequest;
-import com.amazonaws.services.dynamodbv2.model.GetItemResult;
-import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest;
-import com.amazonaws.services.dynamodbv2.model.UpdateItemResult;
+import java.util.HashMap;
+import java.util.UUID;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
import eu.prismacapacity.cryptoshred.core.CryptoAlgorithm;
import eu.prismacapacity.cryptoshred.core.CryptoEngine;
import eu.prismacapacity.cryptoshred.core.CryptoSubjectId;
@@ -33,21 +35,16 @@
import eu.prismacapacity.cryptoshred.core.keys.CryptoKeySize;
import eu.prismacapacity.cryptoshred.core.metrics.CryptoMetrics;
import eu.prismacapacity.cryptoshred.core.metrics.MetricsCallable;
-import java.nio.ByteBuffer;
-import java.util.HashMap;
-import java.util.UUID;
import lombok.val;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+import software.amazon.awssdk.services.dynamodb.model.*;
@ExtendWith(MockitoExtension.class)
class DynamoDBCryptoKeyRepositoryTest {
@Mock CryptoEngine engine;
- @Mock AmazonDynamoDB dynamoDB;
+ @Mock DynamoDbClient dynamoDB;
@Mock(answer = Answers.CALLS_REAL_METHODS)
DummyMetrics metrics;
@@ -86,14 +83,14 @@ void testFindKeyForValidItem() {
{
put(
Utils.generateKeyPropertyName(algorithm, size),
- new AttributeValue().withB(ByteBuffer.wrap(key.getBytes())));
+ AttributeValue.fromB(SdkBytes.fromByteArray(key.getBytes())));
}
};
- val responseMock = mock(GetItemResult.class);
+ val responseMock = mock(GetItemResponse.class);
when(dynamoDB.getItem(any(GetItemRequest.class))).thenReturn(responseMock);
- when(responseMock.getItem()).thenReturn(item);
+ when(responseMock.item()).thenReturn(item);
val result = uut.findKeyFor(subjectId, algorithm, size);
@@ -109,10 +106,10 @@ void testFindKeyForValidItem() {
void testFindKeyForIfAbsent() {
val uut = new DynamoDBCryptoKeyRepository(engine, dynamoDB, metrics, TABLE_NAME);
- val responseMock = mock(GetItemResult.class);
+ val responseMock = mock(GetItemResponse.class);
when(dynamoDB.getItem(any(GetItemRequest.class))).thenReturn(responseMock);
- when(responseMock.getItem()).thenReturn(null);
+ // when(responseMock.isPrimitive()).thenReturn(null);
val result = uut.findKeyFor(subjectId, algorithm, size);
@@ -125,14 +122,14 @@ void testFindKeyForIfAbsent() {
void testGetOrCreateKeyForAlreadyExistingKey() {
val uut = new DynamoDBCryptoKeyRepository(engine, dynamoDB, metrics, TABLE_NAME);
- val responseMock = mock(GetItemResult.class);
+ val responseMock = mock(GetItemResponse.class);
val item =
Maps.of(
Utils.generateKeyPropertyName(algorithm, size),
- new AttributeValue().withB(ByteBuffer.wrap(key.getBytes())));
+ AttributeValue.fromB(SdkBytes.fromByteArray(key.getBytes())));
when(dynamoDB.getItem(any(GetItemRequest.class))).thenReturn(responseMock);
- when(responseMock.getItem()).thenReturn(item);
+ when(responseMock.item()).thenReturn(item);
val resultKey = uut.getOrCreateKeyFor(subjectId, algorithm, size);
@@ -150,15 +147,15 @@ void testGetOrCreateKeyForNewKey() {
val item =
Maps.of(
Utils.generateKeyPropertyName(algorithm, size),
- new AttributeValue().withB(ByteBuffer.wrap(key.getBytes())));
+ AttributeValue.fromB(SdkBytes.fromByteArray(key.getBytes())));
- val getResponseMock = mock(GetItemResult.class);
+ val getResponseMock = mock(GetItemResponse.class);
when(dynamoDB.getItem(any(GetItemRequest.class))).thenReturn(getResponseMock);
- when(getResponseMock.getItem()).thenReturn(null);
+ when(getResponseMock.item()).thenReturn(null);
- val updateResponseMock = mock(UpdateItemResult.class);
+ val updateResponseMock = mock(UpdateItemResponse.class);
when(dynamoDB.updateItem(any(UpdateItemRequest.class))).thenReturn(updateResponseMock);
- when(updateResponseMock.getAttributes()).thenReturn(item);
+ when(updateResponseMock.attributes()).thenReturn(item);
when(engine.generateKey(algorithm, size)).thenReturn(key);
@@ -181,22 +178,22 @@ void testGetOrCreateKeyForRaceConditionBetweenMultipleClients() {
when(engine.generateKey(algorithm, size)).thenReturn(key);
- val getResponseMock = mock(GetItemResult.class);
+ val getResponseMock = mock(GetItemResponse.class);
when(dynamoDB.getItem(any(GetItemRequest.class))).thenReturn(getResponseMock);
val item =
new HashMap() {
{
put(
Utils.generateKeyPropertyName(algorithm, size),
- new AttributeValue().withB(ByteBuffer.wrap(key.getBytes())));
+ AttributeValue.fromB(SdkBytes.fromByteArray(key.getBytes())));
}
};
// noinspection unchecked
- when(getResponseMock.getItem()).thenReturn(null, item);
+ when(getResponseMock.item()).thenReturn(null, item);
when(dynamoDB.updateItem(any(UpdateItemRequest.class)))
- .thenThrow(new ConditionalCheckFailedException("foo"));
+ .thenThrow(ConditionalCheckFailedException.builder().message("foo").build());
val resultKey = uut.getOrCreateKeyFor(subjectId, algorithm, size);
diff --git a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/GetCryptoKeyRequestTest.java b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/GetCryptoKeyRequestTest.java
index 0128fb6a..4c01b97f 100644
--- a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/GetCryptoKeyRequestTest.java
+++ b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/GetCryptoKeyRequestTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2020 PRISMA European Capacity Platform GmbH
+ * Copyright © 2020-2023 PRISMA European Capacity Platform GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,12 +17,14 @@
import static org.junit.Assert.*;
+import java.util.UUID;
+
+import org.junit.jupiter.api.Test;
+
import eu.prismacapacity.cryptoshred.core.CryptoAlgorithm;
import eu.prismacapacity.cryptoshred.core.CryptoSubjectId;
import eu.prismacapacity.cryptoshred.core.keys.CryptoKeySize;
-import java.util.UUID;
import lombok.val;
-import org.junit.jupiter.api.Test;
class GetCryptoKeyRequestTest {
CryptoSubjectId subjectId = CryptoSubjectId.of(UUID.randomUUID());
@@ -35,6 +37,6 @@ void toDynamoRequest() {
val dynamoRequest = request.toDynamoRequest();
- assertTrue(dynamoRequest.getConsistentRead());
+ assertTrue(dynamoRequest.consistentRead());
}
}
diff --git a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/UtilsTest.java b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/UtilsTest.java
index 966bc794..df59f270 100644
--- a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/UtilsTest.java
+++ b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/UtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2020 PRISMA European Capacity Platform GmbH
+ * Copyright © 2020-2023 PRISMA European Capacity Platform GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,17 +15,19 @@
*/
package eu.prismacapacity.cryptoshred.cloud.aws;
-import com.amazonaws.services.dynamodbv2.model.AttributeValue;
-import eu.prismacapacity.cryptoshred.core.CryptoAlgorithm;
-import eu.prismacapacity.cryptoshred.core.CryptoSubjectId;
-import eu.prismacapacity.cryptoshred.core.keys.CryptoKeySize;
-import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.UUID;
-import lombok.val;
+
import org.junit.Assert;
import org.junit.jupiter.api.Test;
+import eu.prismacapacity.cryptoshred.core.CryptoAlgorithm;
+import eu.prismacapacity.cryptoshred.core.CryptoSubjectId;
+import eu.prismacapacity.cryptoshred.core.keys.CryptoKeySize;
+import lombok.val;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
class UtilsTest {
@Test
@@ -34,7 +36,7 @@ void subjectIdToKeyAttributeMap() {
val attributeMap = Utils.subjectIdToKeyAttributeMap(subjectId);
- Assert.assertEquals(attributeMap.get("subjectId").getS(), subjectId.getId().toString());
+ Assert.assertEquals(attributeMap.get("subjectId").s(), subjectId.getId().toString());
Assert.assertEquals(attributeMap.size(), 1);
}
@@ -59,7 +61,7 @@ void testExtractCryptoKeyFromItemForValidItem() {
val item =
new HashMap() {
{
- put(propertyName, new AttributeValue().withB(ByteBuffer.wrap(bytes)));
+ put(propertyName, AttributeValue.fromB(SdkBytes.fromByteArray(bytes)));
}
};
@@ -78,7 +80,7 @@ void testExtractCryptoKeyFromItemForInvalidAttributeType() {
val item =
new HashMap() {
{
- put(propertyName, new AttributeValue().withS("foo"));
+ put(propertyName, AttributeValue.fromS("foo"));
}
};
diff --git a/pom.xml b/pom.xml
index 56b95b92..47361da1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,8 +44,8 @@
UTF-8
- 1.8
- 1.8
+ 17
+ 17
3.3.9
1.6
1.6.8
From 07ed4689100570c342ec836896f57dcd5dda8730 Mon Sep 17 00:00:00 2001
From: Benjamin Otto
Date: Wed, 13 Sep 2023 18:31:24 +0200
Subject: [PATCH 03/10] update jdk
---
.github/kts/build.main.kts | 2 +-
.github/workflows/build.yaml | 64 +++++++++++++++++-------------------
2 files changed, 32 insertions(+), 34 deletions(-)
diff --git a/.github/kts/build.main.kts b/.github/kts/build.main.kts
index 2c0bfd85..288e1e17 100755
--- a/.github/kts/build.main.kts
+++ b/.github/kts/build.main.kts
@@ -48,7 +48,7 @@ public val workflowBuild: Workflow = workflow(
name = "Set up JDK",
action = SetupJavaV3(
distribution = SetupJavaV3.Distribution.Corretto,
- javaVersion = "11",
+ javaVersion = "17",
),
)
run(
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index de1e336e..6bf575c3 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -1,39 +1,37 @@
-# This file was generated using Kotlin DSL (.github/kts/build.main.kts).
+# This file was generated using Kotlin DSL (.github/kts/.github/kts/build.main.kts).
# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file.
-# Generated with https://github.com/krzema12/github-actions-kotlin-dsl
+# Generated with https://github.com/krzema12/github-workflows-kt
name: Java CI
-
on:
- push:
-
+ push: {}
jobs:
- "build":
- runs-on: "ubuntu-latest"
+ build:
+ runs-on: ubuntu-latest
steps:
- - id: step-0
- name: Checkout
- uses: actions/checkout@v3
- with:
- fetch-depth: 0
- - id: step-1
- name: Cache
- uses: actions/cache@v3
- with:
- path: ~/.m2/repository
- key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
- restore-keys: ${{ runner.os }}-maven-
- - id: step-2
- name: Set up JDK
- uses: actions/setup-java@v3
- with:
- java-version: 11
- distribution: corretto
- - id: step-3
- name: Build with Maven
- run: mvn -B install --file pom.xml
- - id: step-4
- name: CodecovAction
- uses: codecov/codecov-action@v3
- with:
- token: ${{ secrets.CODECOV_TOKEN }}
+ - id: step-0
+ name: Checkout
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
+ - id: step-1
+ name: Cache
+ uses: actions/cache@v3
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: ${{ runner.os }}-maven-
+ - id: step-2
+ name: Set up JDK
+ uses: actions/setup-java@v3
+ with:
+ java-version: 17
+ distribution: corretto
+ - id: step-3
+ name: Build with Maven
+ run: mvn -B install --file pom.xml
+ - id: step-4
+ name: CodecovAction
+ uses: codecov/codecov-action@v3
+ with:
+ token: ${{ secrets.CODECOV_TOKEN }}
From 4c0147ae8178573ae7dec3b0748f9a218d269d84 Mon Sep 17 00:00:00 2001
From: Benjamin Otto
Date: Wed, 13 Sep 2023 18:53:28 +0200
Subject: [PATCH 04/10] revert compiler source/target setting
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 47361da1..56b95b92 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,8 +44,8 @@
UTF-8
- 17
- 17
+ 1.8
+ 1.8
3.3.9
1.6
1.6.8
From df23d7e7944942d1fa85843f99a9693b58c222ae Mon Sep 17 00:00:00 2001
From: Benjamin Otto
Date: Tue, 19 Sep 2023 11:16:55 +0200
Subject: [PATCH 05/10] use localstack region
---
.../cloud/aws/DynamoDBCryptoKeyRepositoryIntegrationTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryIntegrationTest.java b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryIntegrationTest.java
index 842b32eb..a0758529 100644
--- a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryIntegrationTest.java
+++ b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/DynamoDBCryptoKeyRepositoryIntegrationTest.java
@@ -210,7 +210,7 @@ private static DynamoDbClient getClient() {
localstack.getEndpointOverride(LocalStackContainer.Service.DYNAMODB);
return DynamoDbClient.builder()
.endpointOverride(endpointOverride)
- .region(Region.US_EAST_1)
+ .region(Region.of(localstack.getRegion()))
.build();
}
}
From 9ce9bfddb435dfa2935c2fb3f25dfeff2c61ca23 Mon Sep 17 00:00:00 2001
From: Benjamin Otto
Date: Tue, 19 Sep 2023 12:13:13 +0200
Subject: [PATCH 06/10] update google format
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 56b95b92..464c4f9c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -222,7 +222,7 @@
- 1.8
+ 1.17.0
From bc0bc1cf4dd8393856cc317798a5768b885a0d1a Mon Sep 17 00:00:00 2001
From: Benjamin Otto
Date: Tue, 19 Sep 2023 12:33:54 +0200
Subject: [PATCH 07/10] fix test after aws sdkv2
---
.../java/eu/prismacapacity/cryptoshred/cloud/aws/UtilsTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/UtilsTest.java b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/UtilsTest.java
index df59f270..e2e85362 100644
--- a/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/UtilsTest.java
+++ b/cryptoshred-cloud-aws/src/test/java/eu/prismacapacity/cryptoshred/cloud/aws/UtilsTest.java
@@ -68,7 +68,7 @@ void testExtractCryptoKeyFromItemForValidItem() {
val key = Utils.extractCryptoKeyFromItem(algorithm, size, item);
Assert.assertTrue(key.isPresent());
- Assert.assertEquals(key.get().getBytes(), bytes);
+ Assert.assertArrayEquals(key.get().getBytes(), bytes);
}
@Test
From 551fdd911bd146375d8ff078d271392a1bb85604 Mon Sep 17 00:00:00 2001
From: Benjamin Otto
Date: Tue, 19 Sep 2023 12:38:02 +0200
Subject: [PATCH 08/10] fix build
---
.../AWSDynamoDBKeyRepositoryConfiguration.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/cryptoshred-spring-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/spring/cloud/aws/AWSDynamoDBKeyRepositoryConfiguration.java b/cryptoshred-spring-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/spring/cloud/aws/AWSDynamoDBKeyRepositoryConfiguration.java
index 3e4135a1..cfbbb0c5 100644
--- a/cryptoshred-spring-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/spring/cloud/aws/AWSDynamoDBKeyRepositoryConfiguration.java
+++ b/cryptoshred-spring-cloud-aws/src/main/java/eu/prismacapacity/cryptoshred/spring/cloud/aws/AWSDynamoDBKeyRepositoryConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2020 PRISMA European Capacity Platform GmbH
+ * Copyright © 2020-2023 PRISMA European Capacity Platform GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,23 +15,24 @@
*/
package eu.prismacapacity.cryptoshred.spring.cloud.aws;
-import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
import eu.prismacapacity.cryptoshred.cloud.aws.DynamoDBCryptoKeyRepository;
import eu.prismacapacity.cryptoshred.core.CryptoEngine;
import eu.prismacapacity.cryptoshred.core.keys.CryptoKeyRepository;
import eu.prismacapacity.cryptoshred.core.metrics.CryptoMetrics;
import lombok.NonNull;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
@Configuration
public class AWSDynamoDBKeyRepositoryConfiguration {
@Bean
public CryptoKeyRepository cryptoKeyRepository(
@NonNull CryptoEngine engine,
- @NonNull AmazonDynamoDB dynamoDB,
+ @NonNull DynamoDbClient dynamoDB,
@Autowired(required = false) CryptoMetrics metrics,
@Value("${cryptoshred.cloud.aws.dynamo.tablename:#{null}}") String tableName) {
From 8d09a0ca7abd7c18bc96d43bf3c409d56bc3c5c3 Mon Sep 17 00:00:00 2001
From: Benjamin Otto
Date: Tue, 19 Sep 2023 13:08:39 +0200
Subject: [PATCH 09/10] major version snapshot
---
cryptoshred-cloud-aws/pom.xml | 2 +-
cryptoshred-core/pom.xml | 2 +-
cryptoshred-micrometer/pom.xml | 2 +-
cryptoshred-spring-boot-autoconfigure/pom.xml | 2 +-
cryptoshred-spring-cloud-aws/pom.xml | 2 +-
cryptoshred-spring-micrometer/pom.xml | 4 ++--
pom.xml | 2 +-
7 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/cryptoshred-cloud-aws/pom.xml b/cryptoshred-cloud-aws/pom.xml
index 043f42c5..972dda8d 100644
--- a/cryptoshred-cloud-aws/pom.xml
+++ b/cryptoshred-cloud-aws/pom.xml
@@ -5,7 +5,7 @@
cryptoshred
eu.prismacapacity
- 1.1.15-SNAPSHOT
+ 2.0.0-SNAPSHOT
../pom.xml
4.0.0
diff --git a/cryptoshred-core/pom.xml b/cryptoshred-core/pom.xml
index 90f914a9..4d58ef85 100644
--- a/cryptoshred-core/pom.xml
+++ b/cryptoshred-core/pom.xml
@@ -7,7 +7,7 @@
eu.prismacapacity
cryptoshred
- 1.1.15-SNAPSHOT
+ 2.0.0-SNAPSHOT
../pom.xml
diff --git a/cryptoshred-micrometer/pom.xml b/cryptoshred-micrometer/pom.xml
index 7e54e8c4..31ae9658 100644
--- a/cryptoshred-micrometer/pom.xml
+++ b/cryptoshred-micrometer/pom.xml
@@ -7,7 +7,7 @@
eu.prismacapacity
cryptoshred
- 1.1.15-SNAPSHOT
+ 2.0.0-SNAPSHOT
../pom.xml
diff --git a/cryptoshred-spring-boot-autoconfigure/pom.xml b/cryptoshred-spring-boot-autoconfigure/pom.xml
index 62a11fbd..28b0f319 100644
--- a/cryptoshred-spring-boot-autoconfigure/pom.xml
+++ b/cryptoshred-spring-boot-autoconfigure/pom.xml
@@ -7,7 +7,7 @@
eu.prismacapacity
cryptoshred
- 1.1.15-SNAPSHOT
+ 2.0.0-SNAPSHOT
../pom.xml
diff --git a/cryptoshred-spring-cloud-aws/pom.xml b/cryptoshred-spring-cloud-aws/pom.xml
index 97b16417..9c984954 100644
--- a/cryptoshred-spring-cloud-aws/pom.xml
+++ b/cryptoshred-spring-cloud-aws/pom.xml
@@ -7,7 +7,7 @@
eu.prismacapacity
cryptoshred
- 1.1.15-SNAPSHOT
+ 2.0.0-SNAPSHOT
../pom.xml
diff --git a/cryptoshred-spring-micrometer/pom.xml b/cryptoshred-spring-micrometer/pom.xml
index a3176e58..b0b30df0 100644
--- a/cryptoshred-spring-micrometer/pom.xml
+++ b/cryptoshred-spring-micrometer/pom.xml
@@ -7,7 +7,7 @@
eu.prismacapacity
cryptoshred
- 1.1.15-SNAPSHOT
+ 2.0.0-SNAPSHOT
../pom.xml
@@ -38,7 +38,7 @@
eu.prismacapacity
cryptoshred-micrometer
- 1.1.15-SNAPSHOT
+ ${project.version}
diff --git a/pom.xml b/pom.xml
index 464c4f9c..cb69fcd3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
0.2.9
cryptoshred
- 1.1.15-SNAPSHOT
+ 2.0.0-SNAPSHOT
pom
cryptoshredding lib
TODO
From 61327ab65981043cb5c3c658bba1bb946e493015 Mon Sep 17 00:00:00 2001
From: Benjamin Otto
Date: Tue, 26 Sep 2023 16:18:49 +0200
Subject: [PATCH 10/10] add hint about compatibility
---
README.md | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 57cd906e..7cd46bb9 100644
--- a/README.md
+++ b/README.md
@@ -101,5 +101,9 @@ assertEquals("Peter",p2.name.get());
// of course you should rather use p2.name.orElse("unknown") or something rather than get, but you know all that from using Optional...
```
+### Spring Boot Compatibility
-
+| Library version | Spring Boot version |
+|-----------------|---------------------|
+| 1.x.x | 2.7+ |
+| 2.x.x | 3.1+ |
\ No newline at end of file