Skip to content

Commit f141733

Browse files
authored
Merge pull request #2645 from RedisInsight/latest
Latest to main
2 parents bddfb99 + 9372bce commit f141733

File tree

28 files changed

+180
-81
lines changed

28 files changed

+180
-81
lines changed

redisinsight/api/config/default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default {
6161
tlsKey: process.env.SERVER_TLS_KEY,
6262
staticContent: !!process.env.SERVER_STATIC_CONTENT || false,
6363
buildType: process.env.BUILD_TYPE || 'ELECTRON',
64-
appVersion: process.env.APP_VERSION || '2.32.0',
64+
appVersion: process.env.APP_VERSION || '2.34.0',
6565
requestTimeout: parseInt(process.env.REQUEST_TIMEOUT, 10) || 25000,
6666
excludeRoutes: [],
6767
excludeAuthRoutes: [],

redisinsight/api/config/features-config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 2.34,
2+
"version": 2.3401,
33
"features": {
44
"insightsRecommendations": {
55
"flag": true,
@@ -28,6 +28,11 @@
2828
}
2929
],
3030
"data": {
31+
"filterFreePlan": [{
32+
"field": "name",
33+
"expression": "^(No HA?.)|(Cache?.)",
34+
"options": "i"
35+
}],
3136
"selectPlan": {
3237
"components": {
3338
"triggersAndFunctions": [

redisinsight/api/config/swagger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const SWAGGER_CONFIG: Omit<OpenAPIObject, 'paths'> = {
55
info: {
66
title: 'RedisInsight Backend API',
77
description: 'RedisInsight Backend API',
8-
version: '2.32.0',
8+
version: '2.34.0',
99
},
1010
tags: [],
1111
};

redisinsight/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redisinsight-api",
3-
"version": "2.32.0",
3+
"version": "2.34.0",
44
"description": "RedisInsight API",
55
"private": true,
66
"author": {

redisinsight/api/src/modules/cloud/auth/cloud-auth.analytics.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export class CloudAuthAnalytics extends TelemetryBaseService {
1515
}
1616

1717
sendCloudSignInFailed(exception: HttpException, flow?: CloudSsoFeatureStrategy, action?: string) {
18-
this.sendFailedEvent(TelemetryEvents.CloudSignInFailed, exception, { flow, action });
18+
this.sendFailedEvent(TelemetryEvents.CloudSignInFailed, exception, {
19+
flow,
20+
action,
21+
errorDescription: exception?.['options']?.['description'],
22+
});
1923
}
2024
}

redisinsight/api/src/modules/cloud/auth/cloud-auth.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ export class CloudAuthService {
3333

3434
static getAuthorizationServerRedirectError(query: { error_description: string }) {
3535
if (query?.error_description?.indexOf('properties are missing') > -1) {
36-
return new CloudOauthMissedRequiredDataException(query.error_description);
36+
return new CloudOauthMissedRequiredDataException(query.error_description, {
37+
description: query.error_description,
38+
});
3739
}
3840

39-
return new CloudOauthMisconfigurationException();
41+
return new CloudOauthMisconfigurationException(undefined, {
42+
description: query.error_description,
43+
});
4044
}
4145

4246
getAuthStrategy(strategy: CloudAuthIdpType): CloudAuthStrategy {

redisinsight/api/src/modules/cloud/auth/exceptions/cloud-oauth.unknown-authorization-request.exception.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class CloudOauthUnknownAuthorizationRequestException extends HttpExceptio
77
const response = {
88
message,
99
statusCode: HttpStatus.BAD_REQUEST,
10-
error: 'CloudOauthGithubEmailPermission',
10+
error: 'CloudOauthUnknownAuthorizationRequest',
1111
errorCode: CustomErrorCodes.CloudOauthUnknownAuthorizationRequest,
1212
};
1313

redisinsight/api/src/modules/cloud/common/providers/cloud.capi.provider.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { ICloudCapiCredentials } from 'src/modules/cloud/common/models';
22
import { CloudSubscriptionType } from 'src/modules/cloud/subscription/models';
3+
import config from 'src/utils/config';
34
import { CloudCapiProvider } from './cloud.capi.provider';
45

6+
const serverConfig = config.get('server');
7+
58
const getPrefixTests = [
69
{
710
input: undefined,
@@ -17,22 +20,24 @@ const getPrefixTests = [
1720
},
1821
];
1922

23+
const userAgent = `RedisInsight/${serverConfig.version}`;
24+
2025
const getHeadersTests = [
2126
{
2227
input: {},
23-
expected: { 'x-api-key': undefined, 'x-api-secret-key': undefined, 'User-Agent': 'RedisInsight/2.32.0' },
28+
expected: { 'x-api-key': undefined, 'x-api-secret-key': undefined, 'User-Agent': userAgent },
2429
},
2530
{
2631
input: { capiKey: 'key' },
27-
expected: { 'x-api-key': 'key', 'x-api-secret-key': undefined, 'User-Agent': 'RedisInsight/2.32.0' },
32+
expected: { 'x-api-key': 'key', 'x-api-secret-key': undefined, 'User-Agent': userAgent },
2833
},
2934
{
3035
input: { capiSecret: 'secret' },
31-
expected: { 'x-api-key': undefined, 'x-api-secret-key': 'secret', 'User-Agent': 'RedisInsight/2.32.0' },
36+
expected: { 'x-api-key': undefined, 'x-api-secret-key': 'secret', 'User-Agent': userAgent },
3237
},
3338
{
3439
input: { capiKey: 'key', capiSecret: 'secret' },
35-
expected: { 'x-api-key': 'key', 'x-api-secret-key': 'secret', 'User-Agent': 'RedisInsight/2.32.0' },
40+
expected: { 'x-api-key': 'key', 'x-api-secret-key': 'secret', 'User-Agent': userAgent },
3641
},
3742
];
3843

redisinsight/api/src/modules/cloud/subscription/cloud-subscription.api.service.spec.ts

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ import {
55
mockCloudSubscriptionApiProvider,
66
mockCloudSubscriptionCapiService,
77
mockCloudSubscriptionRegions,
8+
mockFeatureService,
89
mockSessionMetadata,
910
mockSubscriptionPlanResponse,
1011
MockType,
1112
} from 'src/__mocks__';
1213
import { CloudApiUnauthorizedException } from 'src/modules/cloud/common/exceptions';
1314
import { CloudCapiKeyService } from 'src/modules/cloud/capi-key/cloud-capi-key.service';
15+
import { FeatureService } from 'src/modules/feature/feature.service';
1416
import { CloudSubscriptionApiService } from './cloud-subscription.api.service';
15-
import { CloudUserApiService } from '../user/cloud-user.api.service';
1617
import { CloudSessionService } from '../session/cloud-session.service';
1718
import { CloudSubscriptionCapiService } from './cloud-subscription.capi.service';
1819
import { CloudSubscriptionApiProvider } from './providers/cloud-subscription.api.provider';
1920

2021
describe('CloudSubscriptionApiService', () => {
2122
let service: CloudSubscriptionApiService;
2223
let api: MockType<CloudSubscriptionApiProvider>;
23-
let sessionService: MockType<CloudSessionService>;
24-
let cloudUserApiService: MockType<CloudUserApiService>;
25-
let cloudSubscriptionCapiService: MockType<CloudSubscriptionCapiService>;
24+
let capi: MockType<CloudSubscriptionCapiService>;
25+
let featureService: MockType<FeatureService>;
2626

2727
beforeEach(async () => {
2828
const module: TestingModule = await Test.createTestingModule({
@@ -44,11 +44,17 @@ describe('CloudSubscriptionApiService', () => {
4444
provide: CloudCapiKeyService,
4545
useFactory: mockCloudCapiKeyService,
4646
},
47+
{
48+
provide: FeatureService,
49+
useFactory: mockFeatureService,
50+
},
4751
],
4852
}).compile();
4953

5054
service = module.get(CloudSubscriptionApiService);
5155
api = module.get(CloudSubscriptionApiProvider);
56+
capi = module.get(CloudSubscriptionCapiService);
57+
featureService = module.get(FeatureService);
5258
});
5359

5460
describe('getSubscriptionPlans', () => {
@@ -61,6 +67,55 @@ describe('CloudSubscriptionApiService', () => {
6167
CloudApiUnauthorizedException,
6268
);
6369
});
70+
71+
describe('filter', () => {
72+
beforeEach(() => {
73+
featureService.getByName.mockResolvedValueOnce({
74+
flag: true,
75+
data: {
76+
filterFreePlan: [{
77+
field: 'name',
78+
expression: '^(No HA?.)|(Cache?.)',
79+
options: 'i',
80+
}],
81+
},
82+
});
83+
});
84+
85+
it('get empty list due to filter', async () => {
86+
capi.getSubscriptionsPlans.mockResolvedValueOnce([
87+
{ name: 'some name', price: 0 },
88+
]);
89+
expect(await service.getSubscriptionPlans(mockSessionMetadata)).toEqual([]);
90+
});
91+
92+
it('filter only "no ha" and "cache" plans', async () => {
93+
capi.getSubscriptionsPlans.mockResolvedValueOnce([
94+
{ name: 'some name', price: 0 },
95+
{ name: 'no thing', price: 0 },
96+
{ name: 'No HA', price: 0 },
97+
{ name: 'No HA 30MB price:0', price: 0 },
98+
{ name: 'No HA 30MB price:1', price: 1 },
99+
{ name: 'no ha 30MB', price: 0 },
100+
{ name: 'no ha', price: 0 },
101+
{ name: 'Cache', price: 0 },
102+
{ name: 'Cache 30MB', price: 0 },
103+
{ name: 'cache', price: 0 },
104+
{ name: 'cache 30MB', price: 0 },
105+
{ name: '', price: 0 },
106+
]);
107+
expect(await service.getSubscriptionPlans(mockSessionMetadata)).toEqual([
108+
{ name: 'No HA', price: 0 },
109+
{ name: 'No HA 30MB price:0', price: 0 },
110+
{ name: 'no ha 30MB', price: 0 },
111+
{ name: 'no ha', price: 0 },
112+
{ name: 'Cache', price: 0 },
113+
{ name: 'Cache 30MB', price: 0 },
114+
{ name: 'cache', price: 0 },
115+
{ name: 'cache 30MB', price: 0 },
116+
]);
117+
});
118+
});
64119
});
65120

66121
describe('getCloudRegions', () => {

redisinsight/api/src/modules/cloud/subscription/cloud-subscription.api.service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { SessionMetadata } from 'src/common/models';
44
import { wrapHttpError } from 'src/common/utils';
55
import { CloudRequestUtm, ICloudApiCredentials } from 'src/modules/cloud/common/models';
66
import { CloudCapiKeyService } from 'src/modules/cloud/capi-key/cloud-capi-key.service';
7+
import { FeatureService } from 'src/modules/feature/feature.service';
8+
import { KnownFeatures } from 'src/modules/feature/constants';
79
import { CloudSubscriptionCapiService } from './cloud-subscription.capi.service';
810
import { CloudSubscriptionRegion, CloudSubscriptionType } from './models';
911
import { CloudSessionService } from '../session/cloud-session.service';
@@ -20,6 +22,7 @@ export class CloudSubscriptionApiService {
2022
private readonly sessionService: CloudSessionService,
2123
private readonly cloudCapiKeyService: CloudCapiKeyService,
2224
private readonly cloudSubscriptionCapiService: CloudSubscriptionCapiService,
25+
private readonly featureService: FeatureService,
2326
) {}
2427

2528
/**
@@ -42,9 +45,22 @@ export class CloudSubscriptionApiService {
4245
),
4346
]);
4447

48+
const cloudSsoFeature = await this.featureService.getByName(KnownFeatures.CloudSso);
49+
4550
const freePlans = filter(
4651
fixedPlans,
47-
({ price, name }) => price === 0 && name.startsWith('Cache'),
52+
(plan) => {
53+
if (plan.price !== 0) {
54+
return false;
55+
}
56+
57+
if (!cloudSsoFeature?.data?.filterFreePlan?.length) {
58+
return true;
59+
}
60+
61+
return !!((cloudSsoFeature?.data?.filterFreePlan).find((f) => f.expression
62+
&& (new RegExp(f.expression, f.options)).test(plan[f?.field])));
63+
},
4864
);
4965

5066
return freePlans.map((plan) => ({

0 commit comments

Comments
 (0)