Skip to content

Commit 6e9e253

Browse files
committed
chore: add a mapping from storage type to storage service, update tests
1 parent 07082be commit 6e9e253

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

server/src/main/java/org/eclipse/openvsx/storage/CdnServiceConfig.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
********************************************************************************/
1010
package org.eclipse.openvsx.storage;
1111

12+
import com.google.common.collect.ImmutableMap;
1213
import org.springframework.boot.context.properties.ConfigurationProperties;
1314
import org.springframework.context.annotation.Configuration;
1415

@@ -36,6 +37,12 @@
3637
@Configuration
3738
@ConfigurationProperties("ovsx.storage.cdn")
3839
public class CdnServiceConfig {
40+
private static final Map<String, String> STORAGE_TYPE_TO_SERVICE = ImmutableMap.of(
41+
"aws", "aws",
42+
"azure-blob", "azure",
43+
"google-cloud", "gcp"
44+
);
45+
3946
private boolean enabled;
4047
private Map<String, String> services = new HashMap<>();
4148

@@ -56,6 +63,11 @@ public void setServices(Map<String, String> services) {
5663
}
5764

5865
public @Nullable String getCdnFrontUrl(String storageType) {
59-
return enabled ? services.get(storageType) : null;
66+
if (enabled) {
67+
String serviceName = STORAGE_TYPE_TO_SERVICE.get(storageType);
68+
return serviceName != null ? services.get(serviceName) : null;
69+
} else {
70+
return null;
71+
}
6072
}
6173
}

server/src/test/java/org/eclipse/openvsx/storage/StorageUtilServiceTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
@ContextConfiguration(classes = StorageUtilServiceTest.TestConfig.class)
4343
public class StorageUtilServiceTest {
4444

45+
@Autowired
46+
CdnServiceConfig cdnServiceConfig;
47+
4548
@Autowired
4649
AzureBlobStorageService azureStorage;
4750

@@ -50,12 +53,18 @@ public class StorageUtilServiceTest {
5053

5154
@Test
5255
public void testCdnEnabled() {
56+
cdnServiceConfig.setEnabled(true);
57+
5358
// Test a file resource for which a cdn prefix is enabled
5459
var extension = mockExtension();
5560
var extensionVersion = mockExtensionVersion(extension, 1, "1.0.0", "universal");
56-
var resource = mockFileResource(1, extensionVersion, "README.md", README, FileResource.STORAGE_AWS);
61+
var resourceAws = mockFileResource(1, extensionVersion, "README.md", README, FileResource.STORAGE_AWS);
62+
var resourceAzure = mockFileResource(1, extensionVersion, "README.md", README, FileResource.STORAGE_AZURE);
63+
64+
assertEquals("https://test.cloudfront.com/aws/redhat/vscode-yaml/1.0.0/README.md", storageUtilService.getLocation(resourceAws).toString());
65+
assertEquals("https://test.cloudfront.com/azure/redhat/vscode-yaml/1.0.0/README.md", storageUtilService.getLocation(resourceAzure).toString());
5766

58-
assertEquals("https://test.cloudfront.com/redhat/vscode-yaml/1.0.0/README.md", storageUtilService.getLocation(resource).toString());
67+
cdnServiceConfig.setEnabled(false);
5968
}
6069

6170
@Test
@@ -134,9 +143,10 @@ static class TestConfig {
134143
@Bean
135144
public CdnServiceConfig cdnServiceConfiguration() {
136145
var config = new CdnServiceConfig();
137-
config.setEnabled(true);
146+
config.setEnabled(false);
138147
var services = new HashMap<String, String>();
139-
services.put("aws", "https://test.cloudfront.com");
148+
services.put("aws", "https://test.cloudfront.com/aws");
149+
services.put("azure", "https://test.cloudfront.com/azure");
140150
config.setServices(services);
141151
return config;
142152
}

0 commit comments

Comments
 (0)