From 72f896071ef819d44ce492a5ac43ac8bf67a0ae8 Mon Sep 17 00:00:00 2001
From: sfi2022 <109145215+sfi2022@users.noreply.github.com>
Date: Mon, 25 Nov 2024 15:22:19 +0100
Subject: [PATCH 1/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20S3CredentialProvider?=
=?UTF-8?q?=20and=20EnvironmentReader=20as=20bean=20refactored.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
RELEASENOTES.md | 4 ++
mobidam-eai-commons-lib/pom.xml | 26 ++++++---
.../eai/common/config/EnvironmentReader.java | 5 +-
.../eai/common/s3/S3CredentialProvider.java | 7 ++-
.../mobidam/eai/S3CredentialProviderTest.java | 55 ++++++++++---------
mobidam-eai-commons-starter/pom.xml | 11 ++--
...cketCredentialConfigAutoConfiguration.java | 11 +++-
pom.xml | 30 ++++++----
8 files changed, 94 insertions(+), 55 deletions(-)
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index 7615373..dfe5208 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -1,4 +1,8 @@
# Release-Notes
+## Sprint 20 (12.11.2024 - 03.13.2024)
+- Maven groupid an LHM Standard angepasst.
+- S3CredentialProvider und EnvironmentReader als Bean.
+
## Sprint 18 (1.10.2024 - 22.10.2024)
### Hinzugefügt
- S3 Bucket Authorisierung.
diff --git a/mobidam-eai-commons-lib/pom.xml b/mobidam-eai-commons-lib/pom.xml
index 82f04d6..9bd5996 100644
--- a/mobidam-eai-commons-lib/pom.xml
+++ b/mobidam-eai-commons-lib/pom.xml
@@ -23,17 +23,16 @@
THE SOFTWARE.
-->
-
+
4.0.0
- de.muenchen.mobidam
+ de.muenchen.oss.mobidam
mobidam-eai-commons
- 1.0.0-SNAPSHOT
+ 0.0.2-SNAPSHOT
mobidam-eai-commons-lib
- 1.0.0-SNAPSHOT
+ 0.0.2-SNAPSHOT
mobidam-eai-commons-lib
Contains independent, reusable code that does not require direct Spring Boot integration.
@@ -44,6 +43,19 @@
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+ org.springframework
+ spring-core
+
jakarta.validation
jakarta.validation-api
@@ -73,10 +85,10 @@
junit-jupiter
test
-
+
org.mockito
mockito-core
test
-
+
\ No newline at end of file
diff --git a/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/config/EnvironmentReader.java b/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/config/EnvironmentReader.java
index d0b4f1d..9453cdc 100644
--- a/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/config/EnvironmentReader.java
+++ b/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/config/EnvironmentReader.java
@@ -22,9 +22,12 @@
*/
package de.muenchen.mobidam.eai.common.config;
+import lombok.AllArgsConstructor;
+
+@AllArgsConstructor
public class EnvironmentReader {
- public static String getEnvironmentVariable(final String key) {
+ public String getEnvironmentVariable(final String key) {
return System.getenv().get(key);
}
}
diff --git a/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/s3/S3CredentialProvider.java b/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/s3/S3CredentialProvider.java
index a974523..6586595 100644
--- a/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/s3/S3CredentialProvider.java
+++ b/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/s3/S3CredentialProvider.java
@@ -34,12 +34,14 @@
import org.apache.camel.Processor;
import org.apache.camel.tooling.model.Strings;
import org.apache.http.HttpStatus;
+import org.springframework.stereotype.Component;
/**
* This class provides the credentials for S3 buckets.
* It takes the configured environment variables from the properties, reads their content
* and provides them as message headers.
*/
+@Component
@RequiredArgsConstructor
public class S3CredentialProvider implements Processor {
@@ -47,13 +49,14 @@ public class S3CredentialProvider implements Processor {
@NonNull
private final S3BucketCredentialConfig properties;
+ private final EnvironmentReader environmentReader;
@Override
public void process(Exchange exchange) throws Exception {
String bucketName = verifyBucket(exchange);
S3BucketCredentialConfig.BucketCredentialConfig credentials = verifyCredentials(bucketName, exchange);
- String accessKey = EnvironmentReader.getEnvironmentVariable(credentials.getAccessKeyEnvVar());
- String secretKey = EnvironmentReader.getEnvironmentVariable(credentials.getSecretKeyEnvVar());
+ String accessKey = environmentReader.getEnvironmentVariable(credentials.getAccessKeyEnvVar());
+ String secretKey = environmentReader.getEnvironmentVariable(credentials.getSecretKeyEnvVar());
if (Strings.isNullOrEmpty(accessKey) || Strings.isNullOrEmpty(secretKey)) {
exchange.getMessage()
.setBody(ErrorResponseBuilder.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Bucket not configured: " + bucketName));
diff --git a/mobidam-eai-commons-lib/src/test/java/de/muenchen/mobidam/eai/S3CredentialProviderTest.java b/mobidam-eai-commons-lib/src/test/java/de/muenchen/mobidam/eai/S3CredentialProviderTest.java
index a2dbfad..ac50c24 100644
--- a/mobidam-eai-commons-lib/src/test/java/de/muenchen/mobidam/eai/S3CredentialProviderTest.java
+++ b/mobidam-eai-commons-lib/src/test/java/de/muenchen/mobidam/eai/S3CredentialProviderTest.java
@@ -27,47 +27,49 @@
import de.muenchen.mobidam.eai.common.config.S3BucketCredentialConfig;
import de.muenchen.mobidam.eai.common.exception.MobidamException;
import de.muenchen.mobidam.eai.common.s3.S3CredentialProvider;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.DefaultExchange;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
import org.mockito.Mockito;
-import java.util.HashMap;
-import java.util.Map;
-
public class S3CredentialProviderTest {
+ private EnvironmentReader environmentReader;
+ private S3BucketCredentialConfig properties;
private S3CredentialProvider s3CredentialProvider;
private final CamelContext camelContext = new DefaultCamelContext();
+ @BeforeEach
+ void setup() {
+ environmentReader = Mockito.mock(EnvironmentReader.class);
+ properties = Mockito.mock(S3BucketCredentialConfig.class);
+ s3CredentialProvider = new S3CredentialProvider(properties, environmentReader);
+ }
+
@Test
public void test_processWithValidConfiguration() throws Exception {
+ // Given
+ String bucketName = "x-itmkm82k";
+ String envVar = "FOO";
+ String value = "BAR";
- try (MockedStatic environmentReader = Mockito.mockStatic(EnvironmentReader.class)) {
-
- // Given
- String bucketName = "x-itmkm82k";
- String envVar = "FOO";
- String value = "BAR";
-
- configureEnvironment(bucketName, envVar, value);
-
- Exchange exchange = new DefaultExchange(camelContext);
- exchange.getMessage().setHeader(CommonConstants.HEADER_BUCKET_NAME, bucketName);
+ configureEnvironment(bucketName, envVar, value);
- environmentReader.when(() -> EnvironmentReader.getEnvironmentVariable(envVar)).thenReturn(value);
+ Exchange exchange = new DefaultExchange(camelContext);
+ exchange.getMessage().setHeader(CommonConstants.HEADER_BUCKET_NAME, bucketName);
- // When
- s3CredentialProvider.process(exchange);
+ // When
+ s3CredentialProvider.process(exchange);
- // Then
- Assertions.assertEquals(value, exchange.getMessage().getHeader(CommonConstants.HEADER_ACCESS_KEY));
- Assertions.assertEquals(value, exchange.getMessage().getHeader(CommonConstants.HEADER_SECRET_KEY));
- }
+ // Then
+ Assertions.assertEquals(value, exchange.getMessage().getHeader(CommonConstants.HEADER_ACCESS_KEY));
+ Assertions.assertEquals(value, exchange.getMessage().getHeader(CommonConstants.HEADER_SECRET_KEY));
}
@Test
@@ -77,7 +79,8 @@ public void test_processWithMissingEnvVars() {
String envVar = "FOO";
String value = "BAR";
- configureEnvironment(bucketName, envVar, value);
+ Mockito.when(environmentReader.getEnvironmentVariable(Mockito.anyString())).thenReturn(null);
+
Exchange exchange = new DefaultExchange(camelContext);
exchange.getMessage().setHeader(CommonConstants.HEADER_BUCKET_NAME, bucketName);
@@ -96,6 +99,7 @@ public void test_processWithMissingBucketConfiguration() {
String value = "BAR";
configureEnvironment(bucketName, envVar, value);
+
Exchange exchange = new DefaultExchange(camelContext);
exchange.getMessage().setHeader(CommonConstants.HEADER_BUCKET_NAME, "invalid_bucket");
@@ -114,6 +118,7 @@ public void test_processWithMissingBucketName() {
String value = "BAR";
configureEnvironment(bucketName, envVar, value);
+
Exchange exchange = new DefaultExchange(camelContext);
// Then
@@ -124,9 +129,7 @@ public void test_processWithMissingBucketName() {
}
private void configureEnvironment(String bucketName, String envVar, String value) {
- S3BucketCredentialConfig properties = Mockito.mock(S3BucketCredentialConfig.class);
- s3CredentialProvider = new S3CredentialProvider(properties);
-
+ Mockito.when(environmentReader.getEnvironmentVariable(envVar)).thenReturn(value);
S3BucketCredentialConfig.BucketCredentialConfig envVars = new S3BucketCredentialConfig.BucketCredentialConfig();
envVars.setAccessKeyEnvVar(envVar);
envVars.setSecretKeyEnvVar(envVar);
diff --git a/mobidam-eai-commons-starter/pom.xml b/mobidam-eai-commons-starter/pom.xml
index eb5e01f..0bc9ba1 100644
--- a/mobidam-eai-commons-starter/pom.xml
+++ b/mobidam-eai-commons-starter/pom.xml
@@ -23,17 +23,16 @@
THE SOFTWARE.
-->
-
+
4.0.0
- de.muenchen.mobidam
+ de.muenchen.oss.mobidam
mobidam-eai-commons
- 1.0.0-SNAPSHOT
+ 0.0.2-SNAPSHOT
mobidam-eai-commons-starter
- 1.0.0-SNAPSHOT
+ 0.0.2-SNAPSHOT
mobidam-eai-commons-starter
Spring boot configuration and starter features.
@@ -53,7 +52,7 @@
${camel.version}
- de.muenchen.mobidam
+ de.muenchen.oss.mobidam
mobidam-eai-commons-lib
${project.version}
diff --git a/mobidam-eai-commons-starter/src/main/java/de/muenchen/mobidam/eai/integration/configuration/S3BucketCredentialConfigAutoConfiguration.java b/mobidam-eai-commons-starter/src/main/java/de/muenchen/mobidam/eai/integration/configuration/S3BucketCredentialConfigAutoConfiguration.java
index 3619aa2..dd7fce0 100644
--- a/mobidam-eai-commons-starter/src/main/java/de/muenchen/mobidam/eai/integration/configuration/S3BucketCredentialConfigAutoConfiguration.java
+++ b/mobidam-eai-commons-starter/src/main/java/de/muenchen/mobidam/eai/integration/configuration/S3BucketCredentialConfigAutoConfiguration.java
@@ -22,6 +22,7 @@
*/
package de.muenchen.mobidam.eai.integration.configuration;
+import de.muenchen.mobidam.eai.common.config.EnvironmentReader;
import de.muenchen.mobidam.eai.common.config.S3BucketCredentialConfig;
import de.muenchen.mobidam.eai.common.s3.S3CredentialProvider;
import org.apache.camel.component.aws2.s3.AWS2S3Component;
@@ -41,10 +42,16 @@ public S3BucketCredentialConfig s3BucketCredentialConfig() {
return new S3BucketCredentialConfig();
}
+ @Bean
+ @ConditionalOnMissingBean
+ public EnvironmentReader environmentReader() {
+ return new EnvironmentReader();
+ }
+
@Bean
@ConditionalOnClass(AWS2S3Component.class)
@ConditionalOnMissingBean
- public S3CredentialProvider s3CredentialProvider(S3BucketCredentialConfig properties) {
- return new S3CredentialProvider(properties);
+ public S3CredentialProvider s3CredentialProvider(S3BucketCredentialConfig properties, EnvironmentReader environmentReader) {
+ return new S3CredentialProvider(properties, environmentReader);
}
}
diff --git a/pom.xml b/pom.xml
index 60513d1..7d8735d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,13 +23,12 @@
THE SOFTWARE.
-->
-
+
4.0.0
- de.muenchen.mobidam
+ de.muenchen.oss.mobidam
mobidam-eai-commons
- 1.0.0-SNAPSHOT
+ 0.0.2-SNAPSHOT
pom
mobidam-eai-commons
@@ -52,14 +51,15 @@
sfi2022
Landeshauptstadt München
https://github.com/sfi2022
+ mobidam_devs
- https://github.com/it-at-m/mobidam-eai-commons-starter
- scm:git:https://github.com/it-at-m/mobidam-eai-commons-starter.git
- https://github.com/it-at-m/mobidam-eai-commons-starter.git
- 0.0.1
+ ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
+ scm:git:${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git
+ scm:git:${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git
+ head
@@ -71,6 +71,8 @@
3.3.4
+ 3.0.0-M5
+
false
@@ -204,12 +206,12 @@
**/src/main/java/**/*.java
**/src/test/java/**/*.java
-
+
itm-java-codeformat/java_codestyle_formatter.xml
-
-
+
+
@@ -278,6 +280,7 @@
org.springframework.boot
spring-boot-maven-plugin
+ ${spring.boot.version}
@@ -287,6 +290,11 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
From e2cecc1834cf525db10ffa65120876b15699bb14 Mon Sep 17 00:00:00 2001
From: sfi2022 <109145215+sfi2022@users.noreply.github.com>
Date: Mon, 25 Nov 2024 16:15:52 +0100
Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=94=A7=20Update=20pipeline=20configur?=
=?UTF-8?q?ation.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.github/workflows/build-common.yml | 3 ---
1 file changed, 3 deletions(-)
diff --git a/.github/workflows/build-common.yml b/.github/workflows/build-common.yml
index ae90c46..0c22f2c 100644
--- a/.github/workflows/build-common.yml
+++ b/.github/workflows/build-common.yml
@@ -5,9 +5,6 @@ on:
branches-ignore:
- 'sprint'
- 'main'
- paths:
- - '${{ github.workspace }}/**'
- - '.github/workflows/**'
pull_request:
types: [ opened, reopened ]
From aaa6e348b829e8cbdbea90b1a5f6cebe7c5d3c63 Mon Sep 17 00:00:00 2001
From: sfi2022 <109145215+sfi2022@users.noreply.github.com>
Date: Wed, 27 Nov 2024 10:18:00 +0100
Subject: [PATCH 3/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Spring=20removed=20fro?=
=?UTF-8?q?m=20lib.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
mobidam-eai-commons-lib/pom.xml | 13 -------------
.../mobidam/eai/common/s3/S3CredentialProvider.java | 2 --
2 files changed, 15 deletions(-)
diff --git a/mobidam-eai-commons-lib/pom.xml b/mobidam-eai-commons-lib/pom.xml
index 9bd5996..b0f6ba5 100644
--- a/mobidam-eai-commons-lib/pom.xml
+++ b/mobidam-eai-commons-lib/pom.xml
@@ -43,19 +43,6 @@
-
- org.springframework.boot
- spring-boot-starter
-
-
- org.springframework.boot
- spring-boot-configuration-processor
- true
-
-
- org.springframework
- spring-core
-
jakarta.validation
jakarta.validation-api
diff --git a/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/s3/S3CredentialProvider.java b/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/s3/S3CredentialProvider.java
index 6586595..219201b 100644
--- a/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/s3/S3CredentialProvider.java
+++ b/mobidam-eai-commons-lib/src/main/java/de/muenchen/mobidam/eai/common/s3/S3CredentialProvider.java
@@ -34,14 +34,12 @@
import org.apache.camel.Processor;
import org.apache.camel.tooling.model.Strings;
import org.apache.http.HttpStatus;
-import org.springframework.stereotype.Component;
/**
* This class provides the credentials for S3 buckets.
* It takes the configured environment variables from the properties, reads their content
* and provides them as message headers.
*/
-@Component
@RequiredArgsConstructor
public class S3CredentialProvider implements Processor {
From c155936bbe953b1625ba812ba6ec50412edfe8e1 Mon Sep 17 00:00:00 2001
From: sfi2022 <109145215+sfi2022@users.noreply.github.com>
Date: Wed, 27 Nov 2024 13:13:48 +0100
Subject: [PATCH 4/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=2013th=20month=20correct?=
=?UTF-8?q?ed.=20Properties=20renamed.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
RELEASENOTES.md | 2 +-
.../de/muenchen/mobidam/eai/S3CredentialProviderTest.java | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index dfe5208..531b14f 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -1,5 +1,5 @@
# Release-Notes
-## Sprint 20 (12.11.2024 - 03.13.2024)
+## Sprint 20 (12.11.2024 - 03.12.2024)
- Maven groupid an LHM Standard angepasst.
- S3CredentialProvider und EnvironmentReader als Bean.
diff --git a/mobidam-eai-commons-lib/src/test/java/de/muenchen/mobidam/eai/S3CredentialProviderTest.java b/mobidam-eai-commons-lib/src/test/java/de/muenchen/mobidam/eai/S3CredentialProviderTest.java
index ac50c24..fc28f31 100644
--- a/mobidam-eai-commons-lib/src/test/java/de/muenchen/mobidam/eai/S3CredentialProviderTest.java
+++ b/mobidam-eai-commons-lib/src/test/java/de/muenchen/mobidam/eai/S3CredentialProviderTest.java
@@ -41,15 +41,15 @@
public class S3CredentialProviderTest {
private EnvironmentReader environmentReader;
- private S3BucketCredentialConfig properties;
+ private S3BucketCredentialConfig s3CredentialProperties;
private S3CredentialProvider s3CredentialProvider;
private final CamelContext camelContext = new DefaultCamelContext();
@BeforeEach
void setup() {
environmentReader = Mockito.mock(EnvironmentReader.class);
- properties = Mockito.mock(S3BucketCredentialConfig.class);
- s3CredentialProvider = new S3CredentialProvider(properties, environmentReader);
+ s3CredentialProperties = Mockito.mock(S3BucketCredentialConfig.class);
+ s3CredentialProvider = new S3CredentialProvider(s3CredentialProperties, environmentReader);
}
@Test
@@ -135,6 +135,6 @@ private void configureEnvironment(String bucketName, String envVar, String value
envVars.setSecretKeyEnvVar(envVar);
Map map = new HashMap<>();
map.put(bucketName, envVars);
- Mockito.when(properties.getBucketCredentialConfigs()).thenReturn(map);
+ Mockito.when(s3CredentialProperties.getBucketCredentialConfigs()).thenReturn(map);
}
}