@@ -2,26 +2,39 @@ import { IP_ADDRESS_REGEX, PRIVATE_IP_ADDRESS_REGEX } from 'src/constants';
2
2
import { HostingProvider } from 'src/modules/database/entities/database.entity' ;
3
3
import { RedisClient } from 'src/modules/redis/client' ;
4
4
5
+ const PROVIDER_HOST_REGEX = {
6
+ RLCP : / \. r l r c p \. c o m $ / ,
7
+ REDISLABS : / \. r e d i s l a b s \. c o m $ / ,
8
+ REDISCLOUD : / \. r e d i s - c l o u d \. c o m $ / ,
9
+ CACHE_AMAZONAWS : / c a c h e \. a m a z o n a w s \. c o m $ / ,
10
+ CACHE_WINDOWS : / c a c h e \. w i n d o w s \. n e t $ / ,
11
+ RE_CACHE_AZURE : / r e d i s e n t e r p r i s e \. c a c h e \. a z u r e \. n e t $ / ,
12
+ } ;
13
+
5
14
// Because we do not bind potentially dangerous logic to this.
6
15
// We define a hosting provider for telemetry only.
7
16
export const getHostingProvider = async ( client : RedisClient , databaseHost : string ) : Promise < HostingProvider > => {
8
17
try {
9
18
const host = databaseHost . toLowerCase ( ) ;
10
19
11
20
// 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
+ ) {
13
26
return HostingProvider . RE_CLOUD ;
14
27
}
15
- if ( host . endsWith ( 'cache.amazonaws.com' ) ) {
28
+ if ( PROVIDER_HOST_REGEX . CACHE_AMAZONAWS . test ( host ) ) {
16
29
return HostingProvider . AWS_ELASTICACHE ;
17
30
}
18
31
if ( host . includes ( 'memorydb' ) ) {
19
32
return HostingProvider . AWS_MEMORYDB ;
20
33
}
21
- if ( host . endsWith ( 'cache.windows.net' ) ) {
34
+ if ( PROVIDER_HOST_REGEX . CACHE_WINDOWS . test ( host ) ) {
22
35
return HostingProvider . AZURE_CACHE ;
23
36
}
24
- if ( host . endsWith ( 'redisenterprise.cache.azure.net' ) ) {
37
+ if ( PROVIDER_HOST_REGEX . RE_CACHE_AZURE . test ( host ) ) {
25
38
return HostingProvider . AZURE_CACHE_REDIS_ENTERPRISE ;
26
39
}
27
40
0 commit comments