Просмотр исходного кода

Use password for OCI `private_key_passphrase`

Renders the OCI's `private_key_passphrase` field as a password input in
endpoint new / edit modal and as a password value in endpoint details
page.
Also adds the ability to specify custom password field names in the
`EndpointStore` file.
If the password field names must be configurable, the array should be
moved in the config file.
Sergiu Miclea 8 лет назад
Родитель
Сommit
d4a06afac0

+ 2 - 1
src/components/organisms/Endpoint/Endpoint.jsx

@@ -30,7 +30,7 @@ import LoadingButton from '../../molecules/LoadingButton'
 import type { Endpoint as EndpointType } from '../../../types/Endpoint'
 import type { Endpoint as EndpointType } from '../../../types/Endpoint'
 import type { Field } from '../../../types/Field'
 import type { Field } from '../../../types/Field'
 import notificationStore from '../../../stores/NotificationStore'
 import notificationStore from '../../../stores/NotificationStore'
-import endpointStore from '../../../stores/EndpointStore'
+import endpointStore, { passwordFields } from '../../../stores/EndpointStore'
 import providerStore from '../../../stores/ProviderStore'
 import providerStore from '../../../stores/ProviderStore'
 import ObjectUtils from '../../../utils/ObjectUtils'
 import ObjectUtils from '../../../utils/ObjectUtils'
 import Palette from '../../styleUtils/Palette'
 import Palette from '../../styleUtils/Palette'
@@ -387,6 +387,7 @@ class Endpoint extends React.Component<Props, State> {
           validating: this.state.validating,
           validating: this.state.validating,
           disabled: this.state.validating,
           disabled: this.state.validating,
           cancelButtonText: this.props.cancelButtonText,
           cancelButtonText: this.props.cancelButtonText,
+          passwordFields,
           getFieldValue: field => this.getFieldValue(field),
           getFieldValue: field => this.getFieldValue(field),
           highlightRequired: () => this.highlightRequired(),
           highlightRequired: () => this.highlightRequired(),
           handleFieldChange: (field, value) => { if (field) this.handleFieldsChange([{ field, value }]) },
           handleFieldChange: (field, value) => { if (field) this.handleFieldsChange([{ field, value }]) },

+ 2 - 1
src/components/organisms/EndpointDetailsContent/EndpointDetailsContent.jsx

@@ -88,6 +88,7 @@ type Props = {
   onDeleteClick: () => void,
   onDeleteClick: () => void,
   onValidateClick: () => void,
   onValidateClick: () => void,
   onEditClick: () => void,
   onEditClick: () => void,
+  passwordFields?: string[],
 }
 }
 @observer
 @observer
 class EndpointDetailsContent extends React.Component<Props> {
 class EndpointDetailsContent extends React.Component<Props> {
@@ -137,7 +138,7 @@ class EndpointDetailsContent extends React.Component<Props> {
 
 
       let valueClass = null
       let valueClass = null
 
 
-      if (key === 'password') {
+      if (this.props.passwordFields && this.props.passwordFields.find(fn => fn === key)) {
         valueClass = <PasswordValue value={value} data-test-id="edContent-connPassword" />
         valueClass = <PasswordValue value={value} data-test-id="edContent-connPassword" />
       } else {
       } else {
         valueClass = this.renderValue(value, `connValue-${key}`)
         valueClass = this.renderValue(value, `connValue-${key}`)

+ 1 - 1
src/components/organisms/EndpointDetailsContent/test.jsx

@@ -62,7 +62,7 @@ describe('EndpointDetailsContent Component', () => {
   })
   })
 
 
   it('renders simple connection info', () => {
   it('renders simple connection info', () => {
-    let wrapper = wrap({ item, connectionInfo })
+    let wrapper = wrap({ item, connectionInfo, passwordFields: ['password'] })
     expect(wrapper.find('connValue-username').prop('value')).toBe(connectionInfo.username)
     expect(wrapper.find('connValue-username').prop('value')).toBe(connectionInfo.username)
     expect(wrapper.find('connPassword').prop('value')).toBe(connectionInfo.password)
     expect(wrapper.find('connPassword').prop('value')).toBe(connectionInfo.password)
     expect(wrapper.find('connValue-details').prop('value')).toBe(connectionInfo.details)
     expect(wrapper.find('connValue-details').prop('value')).toBe(connectionInfo.details)

+ 2 - 1
src/components/pages/EndpointDetailsPage/EndpointDetailsPage.jsx

@@ -27,7 +27,7 @@ import Modal from '../../molecules/Modal'
 import EndpointValidation from '../../organisms/EndpointValidation'
 import EndpointValidation from '../../organisms/EndpointValidation'
 import Endpoint from '../../organisms/Endpoint'
 import Endpoint from '../../organisms/Endpoint'
 
 
-import endpointStore from '../../../stores/EndpointStore'
+import endpointStore, { passwordFields } from '../../../stores/EndpointStore'
 import migrationStore from '../../../stores/MigrationStore'
 import migrationStore from '../../../stores/MigrationStore'
 import replicaStore from '../../../stores/ReplicaStore'
 import replicaStore from '../../../stores/ReplicaStore'
 import userStore from '../../../stores/UserStore'
 import userStore from '../../../stores/UserStore'
@@ -201,6 +201,7 @@ class EndpointDetailsPage extends React.Component<Props, State> {
           />}
           />}
           contentComponent={<EndpointDetailsContent
           contentComponent={<EndpointDetailsContent
             item={endpoint}
             item={endpoint}
+            passwordFields={passwordFields}
             usage={this.state.endpointUsage}
             usage={this.state.endpointUsage}
             loading={endpointStore.connectionInfoLoading || endpointStore.loading}
             loading={endpointStore.connectionInfoLoading || endpointStore.loading}
             connectionInfo={endpointStore.connectionInfo}
             connectionInfo={endpointStore.connectionInfo}

+ 3 - 1
src/plugins/endpoint/default/ContentPlugin.jsx

@@ -52,6 +52,7 @@ type Props = {
   cancelButtonText: string,
   cancelButtonText: string,
   validating: boolean,
   validating: boolean,
   onRef: (contentPlugin: any) => void,
   onRef: (contentPlugin: any) => void,
+  passwordFields?: string[],
 }
 }
 class ContentPlugin extends React.Component<Props> {
 class ContentPlugin extends React.Component<Props> {
   componentDidMount() {
   componentDidMount() {
@@ -79,12 +80,13 @@ class ContentPlugin extends React.Component<Props> {
     let lastField
     let lastField
     let i = 0
     let i = 0
     this.props.connectionInfoSchema.forEach((field, schemaIndex) => {
     this.props.connectionInfoSchema.forEach((field, schemaIndex) => {
+      let isPassword = this.props.passwordFields && this.props.passwordFields.find(fn => fn === field.name)
       const currentField = (
       const currentField = (
         <FieldStyled
         <FieldStyled
           {...field}
           {...field}
           large
           large
           disabled={this.props.disabled}
           disabled={this.props.disabled}
-          password={field.name === 'password'}
+          password={isPassword}
           highlight={this.props.invalidFields.findIndex(fn => fn === field.name) > -1}
           highlight={this.props.invalidFields.findIndex(fn => fn === field.name) > -1}
           value={this.props.getFieldValue(field)}
           value={this.props.getFieldValue(field)}
           onChange={value => { this.props.handleFieldChange(field, value) }}
           onChange={value => { this.props.handleFieldChange(field, value) }}

+ 2 - 0
src/stores/EndpointStore.js

@@ -17,6 +17,8 @@ import { observable, action } from 'mobx'
 import type { Endpoint, Validation } from '../types/Endpoint'
 import type { Endpoint, Validation } from '../types/Endpoint'
 import EndpointSource from '../sources/EndpointSource'
 import EndpointSource from '../sources/EndpointSource'
 
 
+export const passwordFields = ['password', 'private_key_passphrase']
+
 const updateEndpoint = (endpoint, endpoints) => endpoints.map(e => {
 const updateEndpoint = (endpoint, endpoints) => endpoints.map(e => {
   if (e.id === endpoint.id) {
   if (e.id === endpoint.id) {
     return { ...endpoint }
     return { ...endpoint }