Skip to content

Commit 97fe96b

Browse files
enhance providers
1 parent 55593e3 commit 97fe96b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

redisinsight/api/src/utils/hosting-provider-helper.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,39 @@ import { IP_ADDRESS_REGEX, PRIVATE_IP_ADDRESS_REGEX } from 'src/constants';
22
import { HostingProvider } from 'src/modules/database/entities/database.entity';
33
import { RedisClient } from 'src/modules/redis/client';
44

5+
const PROVIDER_HOST_REGEX = {
6+
RLCP: /\.rlrcp\.com$/,
7+
REDISLABS: /\.redislabs\.com$/,
8+
REDISCLOUD: /\.redis-cloud\.com$/,
9+
CACHE_AMAZONAWS: /cache\.amazonaws\.com$/,
10+
CACHE_WINDOWS: /cache\.windows\.net$/,
11+
RE_CACHE_AZURE: /redisenterprise\.cache\.azure\.net$/,
12+
};
13+
514
// Because we do not bind potentially dangerous logic to this.
615
// We define a hosting provider for telemetry only.
716
export const getHostingProvider = async (client: RedisClient, databaseHost: string): Promise<HostingProvider> => {
817
try {
918
const host = databaseHost.toLowerCase();
1019

1120
// Tries to detect the hosting provider from the hostname.
12-
if (host.endsWith('rlrcp.com') || host.endsWith('redislabs.com') || host.endsWith('redis-cloud.com')) {
21+
if (
22+
PROVIDER_HOST_REGEX.RLCP.test(host)
23+
|| PROVIDER_HOST_REGEX.REDISLABS.test(host)
24+
|| PROVIDER_HOST_REGEX.REDISCLOUD.test(host)
25+
) {
1326
return HostingProvider.RE_CLOUD;
1427
}
15-
if (host.endsWith('cache.amazonaws.com')) {
28+
if (PROVIDER_HOST_REGEX.CACHE_AMAZONAWS.test(host)) {
1629
return HostingProvider.AWS_ELASTICACHE;
1730
}
1831
if (host.includes('memorydb')) {
1932
return HostingProvider.AWS_MEMORYDB;
2033
}
21-
if (host.endsWith('cache.windows.net')) {
34+
if (PROVIDER_HOST_REGEX.CACHE_WINDOWS.test(host)) {
2235
return HostingProvider.AZURE_CACHE;
2336
}
24-
if (host.endsWith('redisenterprise.cache.azure.net')) {
37+
if (PROVIDER_HOST_REGEX.RE_CACHE_AZURE.test(host)) {
2538
return HostingProvider.AZURE_CACHE_REDIS_ENTERPRISE;
2639
}
2740

0 commit comments

Comments
 (0)