Skip to content

Commit df8772a

Browse files
authored
Merge pull request #3510 from RedisInsight/be/feature/RI-5839-enhance
enhance executable check
2 parents efef880 + c158340 commit df8772a

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export enum HostingProvider {
2727
KVROCKS = 'KVROCKS',
2828
REDICT = 'REDICT',
2929
UPSTASH = 'UPSTASH',
30-
UKNOWN_LOCALHOST = 'UKNOWN_LOCALHOST',
30+
UNKNOWN_LOCALHOST = 'UNKNOWN_LOCALHOST',
3131
UNKNOWN = 'UNKNOWN',
3232
}
3333

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

Lines changed: 24 additions & 15 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.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 },
6+
{ input: '127.0.0.1', output: HostingProvider.UNKNOWN_LOCALHOST },
7+
{ input: '0.0.0.0', output: HostingProvider.UNKNOWN_LOCALHOST },
8+
{ input: 'localhost', output: HostingProvider.UNKNOWN_LOCALHOST },
9+
{ input: '172.18.0.2', output: HostingProvider.UNKNOWN_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 },
@@ -37,7 +37,7 @@ const getHostingProviderTests = [
3737
hello: [
3838
'server', 'redis',
3939
],
40-
info: '#Server\r\n'
40+
info: '# Server\r\n'
4141
+ 'executable:/opt/redis/bin/redis-server',
4242
output: HostingProvider.REDIS_COMMUNITY_EDITION,
4343
},
@@ -46,7 +46,16 @@ const getHostingProviderTests = [
4646
hello: [
4747
'server', 'redis',
4848
],
49-
info: '#Server\r\n'
49+
info: '# Server\r\n'
50+
+ 'executable:/data/redis-server',
51+
output: HostingProvider.REDIS_COMMUNITY_EDITION,
52+
},
53+
{
54+
input: 'localhost',
55+
hello: [
56+
'server', 'redis',
57+
],
58+
info: '# Server\r\n'
5059
+ 'executable:/opt/redis-stack/bin/redis-server',
5160
output: HostingProvider.REDIS_STACK,
5261
},
@@ -61,7 +70,7 @@ const getHostingProviderTests = [
6170
],
6271
],
6372
],
64-
info: '#Server\r\n'
73+
info: '# Server\r\n'
6574
+ 'redis_version: 7.2.0',
6675
output: HostingProvider.REDIS_ENTERPRISE,
6776
},
@@ -80,49 +89,49 @@ const getHostingProviderTests = [
8089
},
8190
{
8291
input: 'localhost',
83-
info: '#Server\r\n'
92+
info: '# Server\r\n'
8493
+ 'server_name:valkey',
8594
output: HostingProvider.VALKEY,
8695
},
8796
{
8897
input: 'localhost',
89-
info: '#Server\r\n'
98+
info: '# Server\r\n'
9099
+ 'dragonfly_version:df-7.0.0',
91100
output: HostingProvider.DRAGONFLY,
92101
},
93102
{
94103
input: 'localhost',
95-
info: '#Server\r\n'
104+
info: '# Server\r\n'
96105
+ 'garnet_version:gr-7.0.0',
97106
output: HostingProvider.GARNET,
98107
},
99108
{
100109
input: 'localhost',
101-
info: '#Server\r\n'
110+
info: '# Server\r\n'
102111
+ 'kvrocks_version:kv-7.0.0',
103112
output: HostingProvider.KVROCKS,
104113
},
105114
{
106115
input: 'localhost',
107-
info: '#Server\r\n'
116+
info: '# Server\r\n'
108117
+ 'redict_version:rd-7.0.0',
109118
output: HostingProvider.REDICT,
110119
},
111120
{
112121
input: 'localhost',
113-
info: '#Server\r\n'
122+
info: '# Server\r\n'
114123
+ 'upstash_version:up-7.0.0',
115124
output: HostingProvider.UPSTASH,
116125
},
117126
{
118127
input: 'localhost',
119-
info: '#Server\r\n'
128+
info: '# Server\r\n'
120129
+ 'ElastiCache:sometinhg',
121130
output: HostingProvider.AWS_ELASTICACHE,
122131
},
123132
{
124133
input: 'localhost',
125-
info: '#Server\r\n'
134+
info: '# Server\r\n'
126135
+ 'MemoryDB:sometinhg',
127136
output: HostingProvider.AWS_MEMORYDB,
128137
},

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
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';
4+
import { convertRedisInfoReplyToObject } from 'src/utils/redis-reply-converter';
45

56
const PROVIDER_HOST_REGEX = {
67
RLCP: /\.rlrcp\.com$/,
@@ -97,24 +98,25 @@ export const getHostingProvider = async (client: RedisClient, databaseHost: stri
9798
return HostingProvider.UPSTASH;
9899
}
99100

100-
if (info.includes('executable:/opt/redis/bin/redis-server')) {
101-
return HostingProvider.REDIS_COMMUNITY_EDITION;
102-
}
101+
const infoObj = convertRedisInfoReplyToObject(info);
103102

104-
if (info.includes('executable:/opt/redis-stack/bin/redis-server')) {
105-
return HostingProvider.REDIS_STACK;
103+
if (infoObj.server.executable.includes('redis-server')) {
104+
if (infoObj.server.executable.includes('redis-stack')) {
105+
return HostingProvider.REDIS_STACK;
106+
}
107+
return HostingProvider.REDIS_COMMUNITY_EDITION;
106108
}
107109
} catch (e) {
108110
// ignore error
109111
}
110112

111113
if (host === '0.0.0.0' || host === 'localhost' || host === '127.0.0.1') {
112-
return HostingProvider.UKNOWN_LOCALHOST;
114+
return HostingProvider.UNKNOWN_LOCALHOST;
113115
}
114116

115117
// todo: investigate weather we need this
116118
if (IP_ADDRESS_REGEX.test(host) && PRIVATE_IP_ADDRESS_REGEX.test(host)) {
117-
return HostingProvider.UKNOWN_LOCALHOST;
119+
return HostingProvider.UNKNOWN_LOCALHOST;
118120
}
119121
} catch (e) {
120122
// ignore any error

redisinsight/api/test/api/database/constants.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
import { Joi } from '../../helpers/test';
22
import { caCertSchema, clientCertSchema } from '../certificate/constants';
33

4+
const providers = [
5+
'RE_CLUSTER',
6+
'RE_CLOUD',
7+
'REDIS_STACK',
8+
'REDIS_ENTERPRISE',
9+
'AZURE_CACHE',
10+
'AZURE_CACHE_REDIS_ENTERPRISE',
11+
'REDIS_COMMUNITY_EDITION',
12+
'AWS_ELASTICACHE',
13+
'AWS_MEMORYDB',
14+
'VALKEY',
15+
'MEMORYSTORE',
16+
'DRAGONFLY',
17+
'KEYDB',
18+
'GARNET',
19+
'KVROCKS',
20+
'REDICT',
21+
'UPSTASH',
22+
'UNKNOWN_LOCALHOST',
23+
'UNKNOWN',
24+
];
25+
426
export const databaseSchema = Joi.object().keys({
527
id: Joi.string().required(),
628
name: Joi.string().required(),
@@ -14,7 +36,7 @@ export const databaseSchema = Joi.object().keys({
1436
compressor: Joi.string().valid('NONE', 'LZ4', 'GZIP', 'ZSTD', 'SNAPPY').required(),
1537
nameFromProvider: Joi.string().allow(null),
1638
lastConnection: Joi.string().isoDate().allow(null),
17-
provider: Joi.string().valid('LOCALHOST', 'UNKNOWN', 'RE_CLOUD', 'RE_CLUSTER'),
39+
provider: Joi.string().valid(...providers),
1840
new: Joi.boolean().allow(null),
1941
tls: Joi.boolean().allow(null),
2042
tlsServername: Joi.string().allow(null),

0 commit comments

Comments
 (0)