diff --git a/extensions/common/aws/aws-s3-core/build.gradle.kts b/extensions/common/aws/aws-s3-core/build.gradle.kts index ba0632cc..e48ea3af 100644 --- a/extensions/common/aws/aws-s3-core/build.gradle.kts +++ b/extensions/common/aws/aws-s3-core/build.gradle.kts @@ -18,12 +18,14 @@ plugins { dependencies { api(libs.edc.spi.transfer) + api(libs.edc.spi.validation) api(libs.failsafe.core) - api(libs.aws.iam) api(libs.aws.s3) api(libs.aws.sts) + + testImplementation(libs.edc.junit) } diff --git a/extensions/common/aws/aws-s3-core/src/main/java/org/eclipse/edc/aws/s3/S3DataAddressValidatorExtension.java b/extensions/common/aws/aws-s3-core/src/main/java/org/eclipse/edc/aws/s3/S3DataAddressValidatorExtension.java new file mode 100644 index 00000000..3cfb53af --- /dev/null +++ b/extensions/common/aws/aws-s3-core/src/main/java/org/eclipse/edc/aws/s3/S3DataAddressValidatorExtension.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation + * + */ + +package org.eclipse.edc.aws.s3; + +import org.eclipse.edc.aws.s3.validation.S3DataAddressValidator; +import org.eclipse.edc.runtime.metamodel.annotation.Extension; +import org.eclipse.edc.runtime.metamodel.annotation.Inject; +import org.eclipse.edc.spi.system.ServiceExtension; +import org.eclipse.edc.spi.system.ServiceExtensionContext; +import org.eclipse.edc.validator.spi.DataAddressValidatorRegistry; + +import static org.eclipse.edc.aws.s3.S3DataAddressValidatorExtension.NAME; + +@Extension(NAME) +public class S3DataAddressValidatorExtension implements ServiceExtension { + public static final String NAME = "DataAddress S3 Validator"; + + @Inject + private DataAddressValidatorRegistry validatorRegistry; + + @Override + public String name() { + return NAME; + } + + @Override + public void initialize(ServiceExtensionContext context) { + var validator = new S3DataAddressValidator(); + validatorRegistry.registerDestinationValidator(S3BucketSchema.TYPE, validator); + validatorRegistry.registerSourceValidator(S3BucketSchema.TYPE, validator); + } +} diff --git a/extensions/common/aws/aws-s3-core/src/main/java/org/eclipse/edc/aws/s3/validation/S3DataAddressCredentialsValidator.java b/extensions/common/aws/aws-s3-core/src/main/java/org/eclipse/edc/aws/s3/validation/S3DataAddressCredentialsValidator.java new file mode 100644 index 00000000..1082e3f0 --- /dev/null +++ b/extensions/common/aws/aws-s3-core/src/main/java/org/eclipse/edc/aws/s3/validation/S3DataAddressCredentialsValidator.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation + * + */ + +package org.eclipse.edc.aws.s3.validation; + +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.validator.spi.ValidationResult; +import org.eclipse.edc.validator.spi.Validator; + +import java.util.Objects; +import java.util.stream.Stream; + +import static org.eclipse.edc.aws.s3.S3BucketSchema.ACCESS_KEY_ID; +import static org.eclipse.edc.aws.s3.S3BucketSchema.SECRET_ACCESS_KEY; +import static org.eclipse.edc.validator.spi.Violation.violation; + +/** + * Validator for AmazonS3 DataAddress type when credentials are in the data address (Optional) + */ +public class S3DataAddressCredentialsValidator implements Validator { + @Override + public ValidationResult validate(DataAddress dataAddress) { + var violations = Stream.of(ACCESS_KEY_ID, SECRET_ACCESS_KEY) + .map(it -> { + var value = dataAddress.getStringProperty(it); + if (value == null || value.isBlank()) { + return violation("'%s' is a mandatory attribute".formatted(it), it, value); + } + return null; + }) + .filter(Objects::nonNull) + .toList(); + + if (violations.isEmpty()) { + return ValidationResult.success(); + } + + return ValidationResult.failure(violations); + } +} diff --git a/extensions/common/aws/aws-s3-core/src/main/java/org/eclipse/edc/aws/s3/validation/S3DataAddressValidator.java b/extensions/common/aws/aws-s3-core/src/main/java/org/eclipse/edc/aws/s3/validation/S3DataAddressValidator.java new file mode 100644 index 00000000..56aec311 --- /dev/null +++ b/extensions/common/aws/aws-s3-core/src/main/java/org/eclipse/edc/aws/s3/validation/S3DataAddressValidator.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation + * + */ + +package org.eclipse.edc.aws.s3.validation; + +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.validator.spi.ValidationResult; +import org.eclipse.edc.validator.spi.Validator; + +import java.util.Objects; +import java.util.stream.Stream; + +import static org.eclipse.edc.aws.s3.S3BucketSchema.BUCKET_NAME; +import static org.eclipse.edc.aws.s3.S3BucketSchema.REGION; +import static org.eclipse.edc.validator.spi.Violation.violation; + +/** + * Validator for AmazonS3 DataAddress type + */ +public class S3DataAddressValidator implements Validator { + + @Override + public ValidationResult validate(DataAddress dataAddress) { + var violations = Stream.of(BUCKET_NAME, REGION) + .map(it -> { + var value = dataAddress.getStringProperty(it); + if (value == null || value.isBlank()) { + return violation("'%s' is a mandatory attribute".formatted(it), it, value); + } + return null; + }) + .filter(Objects::nonNull) + .toList(); + + if (violations.isEmpty()) { + return ValidationResult.success(); + } + + return ValidationResult.failure(violations); + } + +} diff --git a/extensions/common/aws/aws-s3-core/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension b/extensions/common/aws/aws-s3-core/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension index e63d7277..5bea16c6 100644 --- a/extensions/common/aws/aws-s3-core/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension +++ b/extensions/common/aws/aws-s3-core/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension @@ -13,4 +13,4 @@ # org.eclipse.edc.aws.s3.S3CoreExtension - +org.eclipse.edc.aws.s3.S3DataAddressValidatorExtension diff --git a/extensions/common/aws/aws-s3-core/src/test/java/org/eclipse/edc/aws/s3/S3DataAddressValidatorExtensionTest.java b/extensions/common/aws/aws-s3-core/src/test/java/org/eclipse/edc/aws/s3/S3DataAddressValidatorExtensionTest.java new file mode 100644 index 00000000..a79dee47 --- /dev/null +++ b/extensions/common/aws/aws-s3-core/src/test/java/org/eclipse/edc/aws/s3/S3DataAddressValidatorExtensionTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation + * + */ + +package org.eclipse.edc.aws.s3; + + +import org.eclipse.edc.aws.s3.validation.S3DataAddressValidator; +import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; +import org.eclipse.edc.spi.system.ServiceExtensionContext; +import org.eclipse.edc.validator.spi.DataAddressValidatorRegistry; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +@ExtendWith(DependencyInjectionExtension.class) +public class S3DataAddressValidatorExtensionTest { + + private final DataAddressValidatorRegistry registry = mock(); + + @BeforeEach + void setup(ServiceExtensionContext context) { + context.registerService(DataAddressValidatorRegistry.class, registry); + } + + @Test + void initialize(S3DataAddressValidatorExtension extension, ServiceExtensionContext context) { + extension.initialize(context); + + assertThat(extension.name()).isEqualTo(S3DataAddressValidatorExtension.NAME); + + verify(registry).registerDestinationValidator(eq(S3BucketSchema.TYPE), isA(S3DataAddressValidator.class)); + verify(registry).registerSourceValidator(eq(S3BucketSchema.TYPE), isA(S3DataAddressValidator.class)); + } +} diff --git a/extensions/common/aws/aws-s3-core/src/test/java/org/eclipse/edc/aws/s3/validation/S3DataAddressCredentialsValidatorTest.java b/extensions/common/aws/aws-s3-core/src/test/java/org/eclipse/edc/aws/s3/validation/S3DataAddressCredentialsValidatorTest.java new file mode 100644 index 00000000..6712f21d --- /dev/null +++ b/extensions/common/aws/aws-s3-core/src/test/java/org/eclipse/edc/aws/s3/validation/S3DataAddressCredentialsValidatorTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation + * + */ + +package org.eclipse.edc.aws.s3.validation; + +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.validator.spi.ValidationFailure; +import org.eclipse.edc.validator.spi.Violation; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.aws.s3.S3BucketSchema.ACCESS_KEY_ID; +import static org.eclipse.edc.aws.s3.S3BucketSchema.SECRET_ACCESS_KEY; +import static org.eclipse.edc.aws.s3.S3BucketSchema.TYPE; +import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; + +public class S3DataAddressCredentialsValidatorTest { + + private final S3DataAddressCredentialsValidator validator = new S3DataAddressCredentialsValidator(); + + @Test + void shouldPass_whenDataAddressIsValid() { + var dataAddress = DataAddress.Builder.newInstance() + .type(TYPE) + .property(ACCESS_KEY_ID, "ak") + .property(SECRET_ACCESS_KEY, "sk") + .build(); + + var result = validator.validate(dataAddress); + + assertThat(result).isSucceeded(); + } + + @Test + void shouldFail_whenRequiredFieldsAreMissing() { + var dataAddress = DataAddress.Builder.newInstance() + .type(TYPE) + .build(); + + var result = validator.validate(dataAddress); + + assertThat(result).isFailed() + .extracting(ValidationFailure::getViolations) + .satisfies(violations -> assertThat(violations) + .extracting(Violation::path) + .containsExactlyInAnyOrder(ACCESS_KEY_ID, SECRET_ACCESS_KEY)); + } +} diff --git a/extensions/common/aws/aws-s3-core/src/test/java/org/eclipse/edc/aws/s3/validation/S3DataAddressValidatorTest.java b/extensions/common/aws/aws-s3-core/src/test/java/org/eclipse/edc/aws/s3/validation/S3DataAddressValidatorTest.java new file mode 100644 index 00000000..34e60b1c --- /dev/null +++ b/extensions/common/aws/aws-s3-core/src/test/java/org/eclipse/edc/aws/s3/validation/S3DataAddressValidatorTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation + * + */ + +package org.eclipse.edc.aws.s3.validation; + +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.validator.spi.ValidationFailure; +import org.eclipse.edc.validator.spi.Violation; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.aws.s3.S3BucketSchema.BUCKET_NAME; +import static org.eclipse.edc.aws.s3.S3BucketSchema.REGION; +import static org.eclipse.edc.aws.s3.S3BucketSchema.TYPE; +import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; + +public class S3DataAddressValidatorTest { + + private final S3DataAddressValidator validator = new S3DataAddressValidator(); + + @Test + void shouldPass_whenDataAddressIsValid() { + var dataAddress = DataAddress.Builder.newInstance() + .type(TYPE) + .property(BUCKET_NAME, "bucketName") + .property(REGION, "region") + .build(); + + var result = validator.validate(dataAddress); + + assertThat(result).isSucceeded(); + } + + @Test + void shouldFail_whenRequiredFieldsAreMissing() { + var dataAddress = DataAddress.Builder.newInstance() + .type(TYPE) + .build(); + + var result = validator.validate(dataAddress); + + + assertThat(result).isFailed() + .extracting(ValidationFailure::getViolations) + .satisfies(violations -> assertThat(violations) + .extracting(Violation::path) + .containsExactlyInAnyOrder(BUCKET_NAME, REGION)); + } +} diff --git a/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/S3DataSinkFactory.java b/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/S3DataSinkFactory.java index def13666..7ba01213 100644 --- a/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/S3DataSinkFactory.java +++ b/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/S3DataSinkFactory.java @@ -20,11 +20,10 @@ import org.eclipse.edc.aws.s3.AwsTemporarySecretToken; import org.eclipse.edc.aws.s3.S3BucketSchema; import org.eclipse.edc.aws.s3.S3ClientRequest; -import org.eclipse.edc.connector.dataplane.aws.s3.validation.S3DataAddressCredentialsValidationRule; -import org.eclipse.edc.connector.dataplane.aws.s3.validation.S3DataAddressValidationRule; +import org.eclipse.edc.aws.s3.validation.S3DataAddressCredentialsValidator; +import org.eclipse.edc.aws.s3.validation.S3DataAddressValidator; import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSink; import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSinkFactory; -import org.eclipse.edc.connector.dataplane.util.validation.ValidationRule; import org.eclipse.edc.spi.EdcException; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.result.Result; @@ -32,6 +31,8 @@ import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.transfer.DataFlowRequest; +import org.eclipse.edc.validator.spi.ValidationResult; +import org.eclipse.edc.validator.spi.Validator; import org.jetbrains.annotations.NotNull; import software.amazon.awssdk.services.s3.S3Client; @@ -45,8 +46,8 @@ public class S3DataSinkFactory implements DataSinkFactory { - private final ValidationRule validation = new S3DataAddressValidationRule(); - private final ValidationRule credentialsValidation = new S3DataAddressCredentialsValidationRule(); + private final Validator validation = new S3DataAddressValidator(); + private final Validator credentialsValidation = new S3DataAddressCredentialsValidator(); private final AwsClientProvider clientProvider; private final ExecutorService executorService; private final Monitor monitor; @@ -68,13 +69,6 @@ public boolean canHandle(DataFlowRequest request) { return S3BucketSchema.TYPE.equals(request.getDestinationDataAddress().getType()); } - @Override - public @NotNull Result validateRequest(DataFlowRequest request) { - var destination = request.getDestinationDataAddress(); - - return validation.apply(destination).map(it -> null); - } - @Override public DataSink createSink(DataFlowRequest request) { var validationResult = validateRequest(request); @@ -96,6 +90,13 @@ public DataSink createSink(DataFlowRequest request) { .build(); } + @Override + public @NotNull Result validateRequest(DataFlowRequest request) { + var destination = request.getDestinationDataAddress(); + + return validation.validate(destination).flatMap(ValidationResult::toResult); + } + private S3Client createS3Client(DataAddress destination) { String endpointOverride = destination.getStringProperty(ENDPOINT_OVERRIDE); @@ -105,7 +106,7 @@ private S3Client createS3Client(DataAddress destination) { if (secret != null) { var secretToken = typeManager.readValue(secret, AwsTemporarySecretToken.class); client = clientProvider.s3Client(S3ClientRequest.from(destination.getStringProperty(REGION), endpointOverride, secretToken)); - } else if (credentialsValidation.apply(destination).succeeded()) { + } else if (credentialsValidation.validate(destination).succeeded()) { var secretToken = new AwsSecretToken(destination.getStringProperty(ACCESS_KEY_ID), destination.getStringProperty(SECRET_ACCESS_KEY)); client = clientProvider.s3Client(S3ClientRequest.from(destination.getStringProperty(REGION), endpointOverride, secretToken)); diff --git a/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/S3DataSourceFactory.java b/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/S3DataSourceFactory.java index 12d80f93..161d1fd2 100644 --- a/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/S3DataSourceFactory.java +++ b/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/S3DataSourceFactory.java @@ -19,17 +19,18 @@ import org.eclipse.edc.aws.s3.AwsSecretToken; import org.eclipse.edc.aws.s3.S3BucketSchema; import org.eclipse.edc.aws.s3.S3ClientRequest; -import org.eclipse.edc.connector.dataplane.aws.s3.validation.S3DataAddressCredentialsValidationRule; -import org.eclipse.edc.connector.dataplane.aws.s3.validation.S3DataAddressValidationRule; +import org.eclipse.edc.aws.s3.validation.S3DataAddressCredentialsValidator; +import org.eclipse.edc.aws.s3.validation.S3DataAddressValidator; import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSource; import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSourceFactory; -import org.eclipse.edc.connector.dataplane.util.validation.ValidationRule; import org.eclipse.edc.spi.EdcException; import org.eclipse.edc.spi.result.Result; import org.eclipse.edc.spi.security.Vault; import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.transfer.DataFlowRequest; +import org.eclipse.edc.validator.spi.ValidationResult; +import org.eclipse.edc.validator.spi.Validator; import org.jetbrains.annotations.NotNull; import software.amazon.awssdk.services.s3.S3Client; @@ -42,8 +43,8 @@ public class S3DataSourceFactory implements DataSourceFactory { - private final ValidationRule validation = new S3DataAddressValidationRule(); - private final ValidationRule credentialsValidation = new S3DataAddressCredentialsValidationRule(); + private final Validator validation = new S3DataAddressValidator(); + private final Validator credentialsValidation = new S3DataAddressCredentialsValidator(); private final AwsClientProvider clientProvider; private final Vault vault; private final TypeManager typeManager; @@ -59,13 +60,6 @@ public boolean canHandle(DataFlowRequest request) { return S3BucketSchema.TYPE.equals(request.getSourceDataAddress().getType()); } - @Override - public @NotNull Result validateRequest(DataFlowRequest request) { - var source = request.getSourceDataAddress(); - - return validation.apply(source).map(it -> null); - } - @Override public DataSource createSource(DataFlowRequest request) { var validationResult = validateRequest(request); @@ -83,6 +77,13 @@ public DataSource createSource(DataFlowRequest request) { .build(); } + @Override + public @NotNull Result validateRequest(DataFlowRequest request) { + var source = request.getSourceDataAddress(); + + return validation.validate(source).flatMap(ValidationResult::toResult); + } + private S3Client getS3Client(DataAddress address) { String endpointOverride = address.getStringProperty(ENDPOINT_OVERRIDE); @@ -92,7 +93,7 @@ private S3Client getS3Client(DataAddress address) { if (secret != null) { var secretToken = typeManager.readValue(secret, AwsSecretToken.class); client = clientProvider.s3Client(S3ClientRequest.from(address.getStringProperty(REGION), endpointOverride, secretToken)); - } else if (credentialsValidation.apply(address).succeeded()) { + } else if (credentialsValidation.validate(address).succeeded()) { var secretToken = new AwsSecretToken(address.getStringProperty(ACCESS_KEY_ID), address.getStringProperty(SECRET_ACCESS_KEY)); client = clientProvider.s3Client(S3ClientRequest.from(address.getStringProperty(REGION), endpointOverride, secretToken)); } else { diff --git a/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/validation/S3DataAddressCredentialsValidationRule.java b/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/validation/S3DataAddressCredentialsValidationRule.java deleted file mode 100644 index 47c19ff0..00000000 --- a/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/validation/S3DataAddressCredentialsValidationRule.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation - * - */ - -package org.eclipse.edc.connector.dataplane.aws.s3.validation; - -import org.eclipse.edc.connector.dataplane.util.validation.CompositeValidationRule; -import org.eclipse.edc.connector.dataplane.util.validation.EmptyValueValidationRule; -import org.eclipse.edc.connector.dataplane.util.validation.ValidationRule; -import org.eclipse.edc.spi.result.Result; -import org.eclipse.edc.spi.types.domain.DataAddress; - -import java.util.List; - -import static org.eclipse.edc.aws.s3.S3BucketSchema.ACCESS_KEY_ID; -import static org.eclipse.edc.aws.s3.S3BucketSchema.SECRET_ACCESS_KEY; - -public class S3DataAddressCredentialsValidationRule implements ValidationRule { - - @Override - public Result apply(DataAddress dataAddress) { - var composite = new CompositeValidationRule<>( - List.of( - new EmptyValueValidationRule(ACCESS_KEY_ID), - new EmptyValueValidationRule(SECRET_ACCESS_KEY) - ) - ); - - return composite.apply(dataAddress); - } -} diff --git a/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/validation/S3DataAddressValidationRule.java b/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/validation/S3DataAddressValidationRule.java deleted file mode 100644 index 4f14b937..00000000 --- a/extensions/data-plane/data-plane-aws-s3/src/main/java/org/eclipse/edc/connector/dataplane/aws/s3/validation/S3DataAddressValidationRule.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation - * - */ - -package org.eclipse.edc.connector.dataplane.aws.s3.validation; - -import org.eclipse.edc.connector.dataplane.util.validation.CompositeValidationRule; -import org.eclipse.edc.connector.dataplane.util.validation.EmptyValueValidationRule; -import org.eclipse.edc.connector.dataplane.util.validation.ValidationRule; -import org.eclipse.edc.spi.result.Result; -import org.eclipse.edc.spi.types.domain.DataAddress; - -import java.util.List; - -import static org.eclipse.edc.aws.s3.S3BucketSchema.BUCKET_NAME; -import static org.eclipse.edc.aws.s3.S3BucketSchema.REGION; - -public class S3DataAddressValidationRule implements ValidationRule { - - @Override - public Result apply(DataAddress dataAddress) { - var composite = new CompositeValidationRule<>( - List.of( - new EmptyValueValidationRule(BUCKET_NAME), - new EmptyValueValidationRule(REGION) - ) - ); - - return composite.apply(dataAddress); - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 08e2cb40..ceeba76c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -55,12 +55,13 @@ edc-ih-spi-store = { module = "org.eclipse.edc:identity-hub-store-spi", version. edc-dsp = { module = "org.eclipse.edc:dsp", version.ref = "edc" } edc-junit = { module = "org.eclipse.edc:junit", version.ref = "edc" } edc-provision-http = { module = "org.eclipse.edc:provision-http", version.ref = "edc" } -edc-rs-spi-store= { module = "org.eclipse.edc:registration-service-store-spi", version.ref = "edc" } +edc-rs-spi-store = { module = "org.eclipse.edc:registration-service-store-spi", version.ref = "edc" } edc-spi-catalog = { module = "org.eclipse.edc:catalog-spi", version.ref = "edc" } edc-spi-contract = { module = "org.eclipse.edc:contract-spi", version.ref = "edc" } edc-spi-policy = { module = "org.eclipse.edc:policy-spi", version.ref = "edc" } edc-spi-core = { module = "org.eclipse.edc:core-spi", version.ref = "edc" } edc-spi-transfer = { module = "org.eclipse.edc:transfer-spi", version.ref = "edc" } +edc-spi-validation = { module = "org.eclipse.edc:validator-spi", version.ref = "edc" } edc-spi-web = { module = "org.eclipse.edc:web-spi", version.ref = "edc" } edc-spi-jsonld = { module = "org.eclipse.edc:json-ld-spi", version.ref = "edc" } edc-spi-dataplane = { module = "org.eclipse.edc:data-plane-spi", version.ref = "edc" }