Skip to content

Commit c3a8f23

Browse files
#RI-5190 - hide sentinel password
1 parent 0d944e8 commit c3a8f23

File tree

9 files changed

+59
-17
lines changed

9 files changed

+59
-17
lines changed

redisinsight/api/src/modules/database/dto/database.response.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ApiPropertyOptional, OmitType } from '@nestjs/swagger';
22
import { Database } from 'src/modules/database/models/database';
3-
import { SshOptionsResponse } from 'src/modules/ssh/dto/ssh-options.response.';
3+
import { SshOptionsResponse } from 'src/modules/ssh/dto/ssh-options.response';
4+
import { SentinelMasterResponse } from 'src/modules/redis-sentinel/dto/sentinel.master.response.dto';
45
import { Expose, Type } from 'class-transformer';
56
import { HiddenField } from 'src/common/decorators/hidden-field.decorator';
67

7-
export class DatabaseResponse extends OmitType(Database, ['password', 'sshOptions'] as const) {
8+
export class DatabaseResponse extends OmitType(Database, ['password', 'sshOptions', 'sentinelMaster'] as const) {
89
@ApiPropertyOptional({
910
description: 'The database password flag (true if password was set)',
1011
type: Boolean,
@@ -20,4 +21,12 @@ export class DatabaseResponse extends OmitType(Database, ['password', 'sshOption
2021
@Expose()
2122
@Type(() => SshOptionsResponse)
2223
sshOptions?: SshOptionsResponse;
24+
25+
@ApiPropertyOptional({
26+
description: 'Sentinel master',
27+
type: SentinelMasterResponse,
28+
})
29+
@Expose()
30+
@Type(() => SentinelMasterResponse)
31+
sentinelMaster?: SentinelMasterResponse;
2332
}

redisinsight/api/src/modules/database/dto/update.database.dto.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import {
66
IsInt, IsNotEmpty, IsNotEmptyObject, IsOptional, Max, Min, ValidateNested, ValidateIf, IsString, MaxLength,
77
} from 'class-validator';
88
import { UpdateSshOptionsDto } from 'src/modules/ssh/dto/update.ssh-options.dto';
9+
import { UpdateSentinelMasterDto } from 'src/modules/redis-sentinel/dto/update.sentinel.master.dto';
910
import { CreateDatabaseDto } from 'src/modules/database/dto/create.database.dto';
1011

1112
export class UpdateDatabaseDto extends PartialType(OmitType(CreateDatabaseDto, [
12-
'sshOptions', 'timeout',
13+
'sshOptions', 'timeout', 'sentinelMaster',
1314
] as const)) {
1415
@ValidateIf((object, value) => value !== undefined)
1516
@IsString({ always: true })
@@ -45,4 +46,14 @@ export class UpdateDatabaseDto extends PartialType(OmitType(CreateDatabaseDto, [
4546
@Max(1_000_000_000)
4647
@IsInt({ always: true })
4748
timeout?: number;
49+
50+
@ApiPropertyOptional({
51+
description: 'Updated sentinel master fields',
52+
})
53+
@Expose()
54+
@IsOptional()
55+
@IsNotEmptyObject()
56+
@Type(() => UpdateSentinelMasterDto)
57+
@ValidateNested()
58+
sentinelMaster?: UpdateSentinelMasterDto;
4859
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ApiPropertyOptional, OmitType } from '@nestjs/swagger';
2+
import { SentinelMaster } from 'src/modules/redis-sentinel/models/sentinel-master';
3+
import { Expose } from 'class-transformer';
4+
import { HiddenField } from 'src/common/decorators/hidden-field.decorator';
5+
6+
export class SentinelMasterResponse extends OmitType(SentinelMaster, ['password'] as const) {
7+
@ApiPropertyOptional({
8+
description:
9+
'The password for your Redis Sentinel master. '
10+
+ 'If your master doesn’t require a password, leave this field empty.',
11+
type: Boolean,
12+
})
13+
@Expose()
14+
@HiddenField(true)
15+
password?: boolean;
16+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { PickType } from '@nestjs/swagger';
2+
import { SentinelMaster } from 'src/modules/redis-sentinel/models/sentinel-master';
3+
4+
export class UpdateSentinelMasterDto extends PickType(SentinelMaster, ['username', 'password'] as const) {}
File renamed without changes.

redisinsight/ui/src/pages/home/components/form/DatabaseForm.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
validatePortNumber,
2424
validateTimeoutNumber,
2525
} from 'uiSrc/utils'
26-
import { DbConnectionInfo, IPasswordType } from 'uiSrc/pages/home/interfaces'
26+
import { DbConnectionInfo } from 'uiSrc/pages/home/interfaces'
2727

2828
interface IShowFields {
2929
alias: boolean
@@ -39,7 +39,6 @@ export interface Props {
3939
onHostNamePaste: (content: string) => boolean
4040
showFields: IShowFields
4141
autoFocus?: boolean
42-
passwordType?: IPasswordType
4342
}
4443

4544
const DatabaseForm = (props: Props) => {
@@ -50,7 +49,6 @@ const DatabaseForm = (props: Props) => {
5049
onHostNamePaste,
5150
autoFocus = false,
5251
showFields,
53-
passwordType = IPasswordType.Password,
5452
} = props
5553

5654
const { server } = useSelector(appInfoSelector)
@@ -185,7 +183,7 @@ const DatabaseForm = (props: Props) => {
185183
<EuiFlexItem className={flexItemClassName}>
186184
<EuiFormRow label="Password">
187185
<EuiFieldPassword
188-
type={passwordType}
186+
type="password"
189187
name="password"
190188
id="password"
191189
data-testid="password"

redisinsight/ui/src/pages/home/components/form/sentinel/SentinelMasterDatabase.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import {
1111
import { FormikProps } from 'formik'
1212

1313
import { Nullable } from 'uiSrc/utils'
14+
import { SECURITY_FIELD } from 'uiSrc/constants'
1415
import { DbConnectionInfo } from 'uiSrc/pages/home/interfaces'
16+
1517
import styles from '../../styles.module.scss'
1618

1719
export interface Props {
@@ -53,16 +55,24 @@ const SentinelMasterDatabase = (props: Props) => {
5355
<EuiFlexItem className={flexItemClassName}>
5456
<EuiFormRow label="Password">
5557
<EuiFieldPassword
56-
type="dual"
58+
type="password"
5759
name="sentinelMasterPassword"
5860
id="sentinelMasterPassword"
5961
data-testid="sentinel-master-password"
6062
fullWidth
6163
className="passwordField"
6264
maxLength={200}
6365
placeholder="Enter Password"
64-
value={formik.values.sentinelMasterPassword ?? ''}
66+
value={formik.values.sentinelMasterPassword === true ? SECURITY_FIELD : formik.values.sentinelMasterPassword ?? ''}
6567
onChange={formik.handleChange}
68+
onFocus={() => {
69+
if (formik.values.sentinelMasterPassword === true) {
70+
formik.setFieldValue(
71+
'sentinelMasterPassword',
72+
'',
73+
)
74+
}
75+
}}
6676
dualToggleProps={{ color: 'text' }}
6777
autoComplete="new-password"
6878
/>

redisinsight/ui/src/pages/home/components/sentinel-connection/sentinel-connection-form/SentinelConnectionForm.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
fieldDisplayNames,
1818
} from 'uiSrc/pages/home/constants'
1919
import { getFormErrors, getSubmitButtonContent } from 'uiSrc/pages/home/utils'
20-
import { DbConnectionInfo, ISubmitButton, IPasswordType } from 'uiSrc/pages/home/interfaces'
20+
import { DbConnectionInfo, ISubmitButton } from 'uiSrc/pages/home/interfaces'
2121
import {
2222
MessageSentinel,
2323
TlsDetails,
@@ -171,7 +171,6 @@ const SentinelConnectionForm = (props: Props) => {
171171
formik={formik}
172172
flexItemClassName={flexItemClassName}
173173
flexGroupClassName={flexGroupClassName}
174-
passwordType={IPasswordType.dual}
175174
showFields={{ host: true, port: true, alias: false, timeout: false }}
176175
onHostNamePaste={onHostNamePaste}
177176
/>

redisinsight/ui/src/pages/home/interfaces/form.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface DbConnectionInfo extends Instance {
2323
showCompressor?: boolean
2424
sni?: boolean
2525
sentinelMasterUsername?: string
26-
sentinelMasterPassword?: string
26+
sentinelMasterPassword?: string | true
2727
sentinelMasterName?: string
2828
ssh?: boolean
2929
sshPassType?: string
@@ -40,8 +40,3 @@ export interface ISubmitButton {
4040
text?: string
4141
submitIsDisabled?: boolean
4242
}
43-
44-
export enum IPasswordType {
45-
Password = 'password',
46-
Dual = 'dual',
47-
}

0 commit comments

Comments
 (0)