b0c1 commented on code in PR #2915:
URL: https://github.com/apache/fineract/pull/2915#discussion_r1092161378


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/s3/AmazonS3Config.java:
##########
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.s3;
+
+import java.net.URI;
+import 
org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
+import 
org.apache.fineract.infrastructure.dataqueries.service.ReadReportingService;
+import 
org.apache.fineract.infrastructure.dataqueries.service.export.S3DatatableReportExportServiceImpl;
+import org.apache.poi.util.StringUtil;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.regions.providers.AwsRegionProvider;
+import software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.S3ClientBuilder;
+
+@Configuration
+public class AmazonS3Config {
+
+    @Bean
+    public DefaultCredentialsProvider awsCredentialsProvider() {
+        return DefaultCredentialsProvider.create();
+    }
+
+    @Bean
+    public AwsRegionProvider awsRegionProvider() {
+        return DefaultAwsRegionProviderChain.builder().build();
+    }
+
+    @Bean("s3Client")
+    @Profile("!test")
+    @Conditional(AmazonS3ConfigCondition.class)
+    public S3Client s3Client(DefaultCredentialsProvider 
awsCredentialsProvider, AwsRegionProvider awsRegionProvider) {
+        return 
S3Client.builder().credentialsProvider(awsCredentialsProvider).region(awsRegionProvider.getRegion()).build();
+    }
+
+    @Bean("s3Client")
+    @Profile("test")
+    @Conditional(AmazonS3ConfigCondition.class)
+    public S3Client s3ClientTest(DefaultCredentialsProvider 
awsCredentialsProvider, AwsRegionProvider awsRegionProvider) {
+        S3ClientBuilder builder = S3Client.builder();
+        String env = System.getenv().getOrDefault("AWS_ENDPOINT_URL", "");
+        if (StringUtil.isNotBlank(env)) {
+            builder.endpointOverride(URI.create(env)).forcePathStyle(true);
+        }
+        return 
builder.credentialsProvider(awsCredentialsProvider).region(awsRegionProvider.getRegion()).build();
+    }
+
+    @Bean
+    @ConditionalOnBean(S3Client.class)
+    public S3DatatableReportExportServiceImpl 
s3DatatableReportExportServiceImpl(ReadReportingService reportServiceImpl,

Review Comment:
   It should. Initialization moved to a different Configuration but `S3Client` 
must be available (or not) in the BeanFactory, because of this `@Component` 
will not work with `@ConditionOnBean` annotation



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to