Skip to content

Commit 4a8bf83

Browse files
enhance provider
1 parent 916b6e6 commit 4a8bf83

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

redisinsight/api/src/modules/database/entities/database.entity.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { CloudDatabaseDetailsEntity } from 'src/modules/cloud/database/entities/
1212
export enum HostingProvider {
1313
RE_CLUSTER = 'RE_CLUSTER',
1414
RE_CLOUD = 'RE_CLOUD',
15-
REDIS_MANAGED = 'REDIS_MANAGED',
15+
REDIS_STACK = 'REDIS_STACK',
16+
REDIS_ENTERPRISE = 'REDIS_ENTERPRISE',
1617
AZURE_CACHE = 'AZURE_CACHE',
1718
AZURE_CACHE_REDIS_ENTERPRISE = 'AZURE_CACHE_REDIS_ENTERPRISE',
1819
COMMUNITY_EDITION = 'COMMUNITY_EDITION',
@@ -26,6 +27,7 @@ export enum HostingProvider {
2627
KVROCKS = 'KVROCKS',
2728
REDICT = 'REDICT',
2829
UPSTASH = 'UPSTASH',
30+
UKNOWN_LOCALHOST = 'UKNOWN_LOCALHOST',
2931
UNKNOWN = 'UNKNOWN',
3032
}
3133

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { mockStandaloneRedisClient } from 'src/__mocks__';
33
import { getHostingProvider } from './hosting-provider-helper';
44

55
const getHostingProviderTests = [
6-
{ input: '127.0.0.1', output: HostingProvider.COMMUNITY_EDITION },
7-
{ input: '0.0.0.0', output: HostingProvider.COMMUNITY_EDITION },
8-
{ input: 'localhost', output: HostingProvider.COMMUNITY_EDITION },
9-
{ input: '172.18.0.2', output: HostingProvider.COMMUNITY_EDITION },
6+
{ input: '127.0.0.1', output: HostingProvider.UKNOWN_LOCALHOST },
7+
{ input: '0.0.0.0', output: HostingProvider.UKNOWN_LOCALHOST },
8+
{ input: 'localhost', output: HostingProvider.UKNOWN_LOCALHOST },
9+
{ input: '172.18.0.2', output: HostingProvider.UKNOWN_LOCALHOST },
1010
{ input: '176.87.56.244', output: HostingProvider.UNKNOWN },
1111
{ input: '192.12.56.244', output: HostingProvider.UNKNOWN },
1212
{ input: '255.255.56.244', output: HostingProvider.UNKNOWN },
@@ -32,6 +32,24 @@ const getHostingProviderTests = [
3232
{ input: 'contoso5.redis.cache.windows.net', output: HostingProvider.AZURE_CACHE },
3333
{ input: 'contoso5.redisenterprise.cache.azure.net', output: HostingProvider.AZURE_CACHE_REDIS_ENTERPRISE },
3434
{ input: 'demo-redis-provider.unknown.com', output: HostingProvider.UNKNOWN },
35+
{
36+
input: 'localhost',
37+
hello: [
38+
'server', 'redis',
39+
],
40+
info: '#Server\r\n'
41+
+ 'executable:/opt/redis/bin/redis-server',
42+
output: HostingProvider.COMMUNITY_EDITION,
43+
},
44+
{
45+
input: 'localhost',
46+
hello: [
47+
'server', 'redis',
48+
],
49+
info: '#Server\r\n'
50+
+ 'executable:/opt/redis-stack/bin/redis-server',
51+
output: HostingProvider.REDIS_STACK,
52+
},
3553
{
3654
input: 'localhost',
3755
hello: [
@@ -45,7 +63,7 @@ const getHostingProviderTests = [
4563
],
4664
info: '#Server\r\n'
4765
+ 'redis_version: 7.2.0',
48-
output: HostingProvider.REDIS_MANAGED,
66+
output: HostingProvider.REDIS_ENTERPRISE,
4967
},
5068
{
5169
input: 'localhost',

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const getHostingProvider = async (client: RedisClient, databaseHost: stri
3232
) as string[]).toLowerCase();
3333

3434
if (hello.includes('/enterprise-managed')) {
35-
return HostingProvider.REDIS_MANAGED;
35+
return HostingProvider.REDIS_ENTERPRISE;
3636
}
3737

3838
if (hello.includes('google')) {
@@ -83,17 +83,25 @@ export const getHostingProvider = async (client: RedisClient, databaseHost: stri
8383
if (info.includes('upstash_version')) {
8484
return HostingProvider.UPSTASH;
8585
}
86+
87+
if (info.includes('executable:/opt/redis/bin/redis-server')) {
88+
return HostingProvider.COMMUNITY_EDITION;
89+
}
90+
91+
if (info.includes('executable:/opt/redis-stack/bin/redis-server')) {
92+
return HostingProvider.REDIS_STACK;
93+
}
8694
} catch (e) {
8795
// ignore error
8896
}
8997

9098
if (host === '0.0.0.0' || host === 'localhost' || host === '127.0.0.1') {
91-
return HostingProvider.COMMUNITY_EDITION;
99+
return HostingProvider.UKNOWN_LOCALHOST;
92100
}
93101

94102
// todo: investigate weather we need this
95103
if (IP_ADDRESS_REGEX.test(host) && PRIVATE_IP_ADDRESS_REGEX.test(host)) {
96-
return HostingProvider.COMMUNITY_EDITION;
104+
return HostingProvider.UKNOWN_LOCALHOST;
97105
}
98106
} catch (e) {
99107
// ignore any error

0 commit comments

Comments
 (0)