-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathS3Config.java
More file actions
48 lines (42 loc) · 1.85 KB
/
Copy pathS3Config.java
File metadata and controls
48 lines (42 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.faforever.api.config;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3Configuration;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
import java.net.URI;
@Configuration
@RequiredArgsConstructor
public class S3Config {
private final FafApiProperties properties;
@Bean
public S3Client s3Client() {
return S3Client.builder()
.endpointOverride(URI.create(properties.getS3().getEndpoint()))
.region(Region.EU_CENTRAL_1) // region must be non-null but is ignored by some S3-compatible services
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(properties.getS3().getAccessKey(), properties.getS3().getSecretKey())
))
.serviceConfiguration(S3Configuration.builder()
.pathStyleAccessEnabled(true) // prevents putting the bucket name as subdomain
.build())
.build();
}
@Bean
public S3Presigner s3Presigner() {
return S3Presigner.builder()
.endpointOverride(URI.create(properties.getS3().getEndpoint()))
.region(Region.EU_CENTRAL_1) // region must be non-null but is ignored by some S3-compatible services
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(properties.getS3().getAccessKey(), properties.getS3().getSecretKey())
))
.serviceConfiguration(S3Configuration.builder()
.pathStyleAccessEnabled(true) // prevents putting the bucket name as subdomain
.build())
.build();
}
}