Skip to content

Commit 47d81f1

Browse files
committed
refactor: update BucketConf
1 parent 96e683c commit 47d81f1

File tree

2 files changed

+28
-46
lines changed

2 files changed

+28
-46
lines changed

src/main/java/com/example/arinfra/config/BucketConf.java

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,12 @@
2525
* <p><b>Required application properties:</b>
2626
*
2727
* <ul>
28-
* <li>{@code b2.key.id} - Application key ID for authentication
29-
* <li>{@code b2.application.key} - Application key secret for authentication
30-
* <li>{@code b2.bucket.name} - Target bucket name
31-
* <li>{@code b2.region} - Storage region (e.g., "us-west-001")
32-
* <li>{@code b2.endpoint.prefix} - Endpoint URL prefix (e.g., "<a href="">https://s3</a>.")
33-
* <li>{@code b2.endpoint.suffix} - Endpoint URL suffix (e.g., ".backblazeb2.com")
34-
* </ul>
35-
*
36-
* <p><b>Endpoint construction:</b>
37-
*
38-
* <ul>
39-
* <li>Production: {@code prefix + region + suffix} (e.g.,
40-
* "https://s3.us-west-001.backblazeb2.com")
41-
* <li>Local development: Uses prefix only if it contains "localhost" or "127.0.0.1"
28+
* <li>{@code cloud.storage.key.id} - Application key ID for authentication
29+
* <li>{@code cloud.storage.application.key} - Application key secret for authentication
30+
* <li>{@code cloud.storage.bucket.name} - Target bucket name
31+
* <li>{@code cloud.storage.region} - Storage region (e.g., "us-west-006")
32+
* <li>{@code cloud.storage.full-endpoint} - Endpoint URL prefix (e.g., "<a
33+
* href="">https://s3.us-west-006.backblaze.com</a>.")
4234
* </ul>
4335
*
4436
* <p>The configuration automatically cleans up resources on application shutdown via the {@link
@@ -70,30 +62,21 @@ public class BucketConf {
7062
* both an async transfer manager for file operations and a presigner for generating temporary
7163
* access URLs.
7264
*
73-
* <p><b>Endpoint resolution:</b> If the endpoint prefix contains "localhost" or "127.0.0.1" (for
74-
* local testing), uses the prefix as-is. Otherwise, constructs the full endpoint by concatenating
75-
* prefix + region + suffix.
76-
*
7765
* @param keyId the application key ID for B2 authentication
7866
* @param applicationKey the application key secret for B2 authentication
7967
* @param bucketName the target bucket name
8068
* @param regionString the storage region identifier
81-
* @param endpointPrefix the endpoint URL prefix (e.g., "<a href="">https://s3</a>.")
82-
* @param endpointSuffix the endpoint URL suffix (e.g., ".backblazeb2.com")
69+
* @param fullEndpoint the endpoint URL (e.g., ""<a
70+
* href="">https://s3.us-west-006.backblaze.com</a>.")
8371
*/
8472
@SneakyThrows
8573
public BucketConf(
86-
@Value("${b2.key.id}") String keyId,
87-
@Value("${b2.application.key}") String applicationKey,
88-
@Value("${b2.bucket.name}") String bucketName,
89-
@Value("${b2.region}") String regionString,
90-
@Value("${b2.endpoint.prefix}") String endpointPrefix,
91-
@Value("${b2.endpoint.suffix}") String endpointSuffix) {
74+
@Value("${cloud.storage.key.id}") String keyId,
75+
@Value("${cloud.storage.application.key}") String applicationKey,
76+
@Value("${cloud.storage.bucket.name}") String bucketName,
77+
@Value("${cloud.storage.region}") String regionString,
78+
@Value("${cloud.storage.full-endpoint}") String fullEndpoint) {
9279
this.bucketName = bucketName;
93-
String fullEndpoint =
94-
(endpointPrefix.contains("localhost") || endpointPrefix.contains("127.0.0.1"))
95-
? endpointPrefix
96-
: endpointPrefix + regionString + endpointSuffix;
9780
URI endpoint = URI.create(fullEndpoint);
9881

9982
Region region = Region.of(regionString);

src/test/java/com/example/arinfra/conf/BucketConf.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ private void createBucket() {
149149
* <p><b>Properties configured:</b>
150150
*
151151
* <ul>
152-
* <li>{@code b2.key.id} - LocalStack access key
153-
* <li>{@code b2.application.key} - LocalStack secret key
154-
* <li>{@code b2.bucket.name} - Test bucket name ("test-bucket")
155-
* <li>{@code b2.region} - LocalStack region (typically "us-east-1")
156-
* <li>{@code b2.endpoint.prefix} - Full LocalStack S3 endpoint URL
157-
* <li>{@code b2.endpoint.suffix} - Empty (prefix contains full URL for LocalStack)
158-
* <li>{@code b2.upload.part-size-mb} - Multipart upload part size (5 MB)
159-
* <li>{@code b2.upload.target-throughput-gbps} - Target upload throughput (10 Gbps)
152+
* <li>{@code cloud.storage.key.id} - LocalStack access key
153+
* <li>{@code cloud.storage.application.key} - LocalStack secret key
154+
* <li>{@code cloud.storage.bucket.name} - Test bucket name ("test-bucket")
155+
* <li>{@code cloud.storage.region} - LocalStack region (typically "us-east-1")
156+
* <li>{@code cloud.storage.endpoint.prefix} - Full LocalStack S3 endpoint URL
157+
* <li>{@code cloud.storage.endpoint.suffix} - Empty (prefix contains full URL for LocalStack)
158+
* <li>{@code cloud.storage.upload.part-size-mb} - Multipart upload part size (5 MB)
159+
* <li>{@code cloud.storage.upload.target-throughput-gbps} - Target upload throughput (10 Gbps)
160160
* </ul>
161161
*
162162
* <p>These properties are automatically injected into the Spring test context, allowing the
@@ -167,16 +167,15 @@ private void createBucket() {
167167
*/
168168
@SneakyThrows
169169
public void configureProperties(DynamicPropertyRegistry registry) {
170-
registry.add("b2.key.id", LOCALSTACK::getAccessKey);
171-
registry.add("b2.application.key", LOCALSTACK::getSecretKey);
172-
registry.add("b2.bucket.name", () -> TEST_BUCKET);
173-
registry.add("b2.region", LOCALSTACK::getRegion);
170+
registry.add("cloud.storage.key.id", LOCALSTACK::getAccessKey);
171+
registry.add("cloud.storage.application.key", LOCALSTACK::getSecretKey);
172+
registry.add("cloud.storage.bucket.name", () -> TEST_BUCKET);
173+
registry.add("cloud.storage.region", LOCALSTACK::getRegion);
174174

175175
registry.add(
176-
"b2.endpoint.prefix",
176+
"cloud.storage.full-endpoint",
177177
() -> LOCALSTACK.getEndpointOverride(LocalStackContainer.Service.S3).toString());
178-
registry.add("b2.endpoint.suffix", () -> "");
179-
registry.add("b2.upload.part-size-mb", () -> 5);
180-
registry.add("b2.upload.target-throughput-gbps", () -> 10.0);
178+
registry.add("cloud.storage.upload.part-size-mb", () -> 5);
179+
registry.add("cloud.storage.upload.target-throughput-gbps", () -> 10.0);
181180
}
182181
}

0 commit comments

Comments
 (0)