Skip to content

Commit 6b10fe4

Browse files
committed
Refactor S3 image store URL construction to handle endpoint and bucket name more effectively
1 parent 546eee4 commit 6b10fe4

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
131131
dm.put(ApiConstants.S3_USE_TCP_KEEPALIVE, getUseTCPKeepAlive().toString());
132132
}
133133

134-
String url = "s3://" + getEndPoint().replaceFirst("^https?://", "") + "/" + getBucketName();
135134
try{
136-
ImageStore result = _storageService.discoverImageStore(null, url, "S3", zoneId, dm);
135+
ImageStore result = _storageService.discoverImageStore(null, null, "S3", zoneId, dm);
137136
ImageStoreResponse storeResponse;
138137
if (result != null) {
139138
storeResponse = _responseGenerator.createImageStoreResponse(result);

plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import javax.inject.Inject;
2424

25+
import org.apache.commons.lang3.StringUtils;
2526
import org.apache.logging.log4j.Logger;
2627
import org.apache.logging.log4j.LogManager;
2728

@@ -80,7 +81,16 @@ public DataStore initialize(Map<String, Object> dsInfos) {
8081
DataStoreRole role = (DataStoreRole)dsInfos.get("role");
8182
Map<String, String> details = (Map<String, String>)dsInfos.get("details");
8283

83-
logger.info("Trying to add a S3 store with endpoint: " + details.get(ApiConstants.S3_END_POINT));
84+
String endPoint = details.get(ApiConstants.S3_END_POINT);
85+
String bucketName = details.get(ApiConstants.S3_BUCKET_NAME);
86+
logger.info("Trying to add a S3 store with endpoint: " + endPoint);
87+
88+
if (StringUtils.isEmpty(url) && StringUtils.isNotEmpty(endPoint) && StringUtils.isNotEmpty(bucketName)) {
89+
url = "s3://" + endPoint.replaceFirst("^https?://", "") + "/" + bucketName;
90+
}
91+
if (StringUtils.isEmpty(name) && StringUtils.isNotEmpty(url)) {
92+
name = url;
93+
}
8494

8595
Map<String, Object> imageStoreParameters = new HashMap();
8696
imageStoreParameters.put("name", name);

0 commit comments

Comments
 (0)