Skip to content

Commit 625917a

Browse files
committed
adop spring-cloud-azure-starter-storage-blob
1 parent 241a24a commit 625917a

File tree

5 files changed

+19
-80
lines changed

5 files changed

+19
-80
lines changed

server/pom.xml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717

1818
<dependencyManagement>
1919
<dependencies>
20-
<dependency>
21-
<groupId>com.azure</groupId>
22-
<artifactId>azure-sdk-bom</artifactId>
23-
<version>1.2.38</version>
24-
<type>pom</type>
25-
<scope>import</scope>
26-
</dependency>
2720
<dependency>
2821
<groupId>com.azure.spring</groupId>
2922
<artifactId>spring-cloud-azure-dependencies</artifactId>
@@ -70,12 +63,8 @@
7063
<scope>runtime</scope>
7164
</dependency>
7265
<dependency>
73-
<groupId>com.azure</groupId>
74-
<artifactId>azure-storage-blob</artifactId>
75-
</dependency>
76-
<dependency>
77-
<groupId>com.azure</groupId>
78-
<artifactId>azure-identity</artifactId>
66+
<groupId>com.azure.spring</groupId>
67+
<artifactId>spring-cloud-azure-starter-storage-blob</artifactId>
7968
</dependency>
8069
<dependency>
8170
<groupId>com.azure.spring</groupId>

server/src/main/java/io/github/mucsi96/postgresbackuptool/configuration/StorageConfiguration.java

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,11 @@
33
import java.time.ZoneOffset;
44
import java.time.format.DateTimeFormatter;
55

6-
import org.springframework.beans.factory.annotation.Value;
76
import org.springframework.context.annotation.Bean;
87
import org.springframework.context.annotation.Configuration;
9-
import org.springframework.context.annotation.Profile;
10-
11-
import com.azure.core.credential.TokenCredential;
12-
import com.azure.identity.ClientSecretCredentialBuilder;
13-
import com.azure.identity.WorkloadIdentityCredentialBuilder;
14-
import com.azure.storage.blob.BlobServiceClient;
15-
import com.azure.storage.blob.BlobServiceClientBuilder;
16-
17-
import lombok.extern.slf4j.Slf4j;
188

199
@Configuration
20-
@Slf4j
2110
public class StorageConfiguration {
22-
@Value("${blobstorage.accountUrl}")
23-
private String accountUrl;
24-
25-
@Profile("test")
26-
@Bean
27-
BlobServiceClient testBlobServiceClient(
28-
@Value("${blobstorage.connectionString}") String connectionString)
29-
throws Exception {
30-
31-
return new BlobServiceClientBuilder().connectionString(connectionString)
32-
.buildClient();
33-
}
34-
35-
@Profile("prod")
36-
@Bean
37-
BlobServiceClient prodBlobServiceClient(
38-
@Value("${blobstorage.clientId}") String clientId,
39-
@Value("${blobstorage.tenantId}") String tenantId) throws Exception {
40-
41-
TokenCredential tokenCredential = new WorkloadIdentityCredentialBuilder()
42-
.clientId(clientId)
43-
.tenantId(tenantId)
44-
.build();
45-
46-
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
47-
.endpoint(accountUrl).credential(tokenCredential).buildClient();
48-
49-
return blobServiceClient;
50-
}
51-
52-
@Profile("local")
53-
@Bean
54-
BlobServiceClient localBlobServiceClient(
55-
@Value("${blobstorage.clientId}") String clientId,
56-
@Value("${blobstorage.tenantId}") String tenantId,
57-
@Value("${blobstorage.clientSecret}") String clientSecret)
58-
throws Exception {
59-
60-
TokenCredential tokenCredential = new ClientSecretCredentialBuilder()
61-
.clientId(clientId)
62-
.tenantId(tenantId)
63-
.clientSecret(clientSecret)
64-
.build();
65-
66-
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
67-
.endpoint(accountUrl).credential(tokenCredential).buildClient();
68-
69-
return blobServiceClient;
70-
}
71-
7211
@Bean
7312
DateTimeFormatter backupDateTimeFormat() {
7413
return DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
management:
22
server:
33
port: 8282
4+
5+
spring:
6+
cloud:
7+
azure:
8+
storage:
9+
blob:
10+
credential:
11+
client-secret: ${api-client-secret}

server/src/main/resources/application-test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
blobstorage:
2-
connectionString: ${BLOBSTORAGE_CONNECTION_STRING:}
31
databasesConfigPath: ${DATABASES_CONFIG_PATH}
42
spring:
53
cloud:
@@ -9,6 +7,9 @@ spring:
97
property-sources: []
108
active-directory:
119
enabled: false
10+
storage:
11+
blob:
12+
connection-string: ${BLOBSTORAGE_CONNECTION_STRING}
1213
autoconfigure:
1314
exclude:
1415
- "org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration"

server/src/main/resources/application.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ spring:
1515
credential:
1616
client-id: ${api-client-id}
1717

18+
storage:
19+
blob:
20+
endpoint: ${storage-account-blob-url:}
21+
credential:
22+
client-id: ${api-client-id:}
23+
1824
blobstorage:
19-
clientId: ${api-client-id}
20-
tenantId: ${tenant-id}
21-
clientSecret: ${api-client-secret:}
22-
accountUrl: ${storage-account-blob-url:}
2325
containerName: ${storage-account-container-name:}
2426

2527
management:

0 commit comments

Comments
 (0)