-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for Noobaa external postgres
Signed-off-by: vbadrina <[email protected]>
- Loading branch information
Showing
12 changed files
with
757 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
273 changes: 273 additions & 0 deletions
273
...ystem-steps/backing-storage-step/noobaa-external-postgres/postgres-connection-details.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,273 @@ | ||
import * as React from 'react'; | ||
import { UploadFile } from '@odf/shared/file-handling'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { | ||
FormGroup, | ||
Checkbox, | ||
TextInput, | ||
Form, | ||
GridItem, | ||
Grid, | ||
Text, | ||
TextVariants, | ||
Stack, | ||
Tooltip, | ||
Button, | ||
InputGroup, | ||
} from '@patternfly/react-core'; | ||
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons'; | ||
import { WizardDispatch, WizardState } from '../../../reducer'; | ||
import '../backing-storage-step.scss'; | ||
|
||
export const PostgresConnectionDetails: React.FC<PostgresConnectionDetails> = ({ | ||
dispatch, | ||
username, | ||
password, | ||
serverName, | ||
port, | ||
databaseName, | ||
tlsEnabled, | ||
allowSelfSignedCerts, | ||
enableClientSideCerts, | ||
}) => { | ||
const { t } = useCustomTranslation(); | ||
const [showPassword, setShowPassword] = React.useState(false); | ||
const processKeys = React.useCallback( | ||
() => (keyFiles: File[]) => { | ||
if (keyFiles.some((file) => file.name.startsWith('private'))) { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/keys/setPrivateKey', | ||
payload: keyFiles.find((file) => file.name.startsWith('private')), | ||
}); | ||
} else { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/keys/setPrivateKey', | ||
payload: null, | ||
}); | ||
} | ||
|
||
if (keyFiles.some((file) => file.name.startsWith('public'))) { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/keys/setPublicKey', | ||
payload: keyFiles.find((file) => file.name.startsWith('public')), | ||
}); | ||
} else { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/keys/setPublicKey', | ||
payload: null, | ||
}); | ||
} | ||
}, | ||
[dispatch] | ||
); | ||
|
||
return ( | ||
<Form> | ||
<Text component={TextVariants.h4}>Connection details</Text> | ||
<Grid hasGutter md={12}> | ||
<GridItem md={8} span={2}> | ||
<FormGroup label={t('Username')} fieldId="username-tls" isRequired> | ||
<TextInput | ||
id="username-input" | ||
type="text" | ||
value={username} | ||
onChange={(newUsername: string) => { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/setUsername', | ||
payload: newUsername, | ||
}); | ||
}} | ||
isRequired | ||
/> | ||
</FormGroup> | ||
</GridItem> | ||
<GridItem md={8} span={2}> | ||
<FormGroup label={t('Password')} fieldId="password-tls" isRequired> | ||
<InputGroup> | ||
<TextInput | ||
id="password-input" | ||
type={showPassword ? 'text' : 'password'} | ||
value={password} | ||
onChange={(newPassword: string) => { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/setPassword', | ||
payload: newPassword, | ||
}); | ||
}} | ||
isRequired | ||
/> | ||
<Tooltip | ||
content={ | ||
showPassword | ||
? t('plugin__odf-console~Hide password') | ||
: t('plugin__odf-console~Show password') | ||
} | ||
> | ||
<Button | ||
variant="control" | ||
onClick={() => setShowPassword(!showPassword)} | ||
> | ||
{showPassword ? <EyeSlashIcon /> : <EyeIcon />} | ||
</Button> | ||
</Tooltip> | ||
</InputGroup> | ||
</FormGroup> | ||
</GridItem> | ||
<GridItem md={6} span={10}> | ||
<FormGroup label={t('Server')} fieldId="server-tls" isRequired> | ||
<TextInput | ||
id="server-input" | ||
type="text" | ||
value={serverName} | ||
onChange={(newServer: string) => { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/setServerName', | ||
payload: newServer, | ||
}); | ||
}} | ||
isRequired | ||
/> | ||
</FormGroup> | ||
</GridItem> | ||
<GridItem md={6} span={2}> | ||
<FormGroup label={t('Port')} fieldId="port-tls" isRequired> | ||
<TextInput | ||
id="port-input" | ||
type="number" | ||
value={port} | ||
onChange={(newPort: string) => { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/setPort', | ||
payload: newPort, | ||
}); | ||
}} | ||
isRequired | ||
/> | ||
</FormGroup> | ||
</GridItem> | ||
<GridItem md={8} span={2}> | ||
<FormGroup | ||
label={t('Database name')} | ||
fieldId="database-tls" | ||
isRequired | ||
> | ||
<TextInput | ||
id="database-input" | ||
type="text" | ||
value={databaseName} | ||
onChange={(newDatabase: string) => { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/setDatabaseName', | ||
payload: newDatabase, | ||
}); | ||
}} | ||
isRequired | ||
/> | ||
</FormGroup> | ||
</GridItem> | ||
</Grid> | ||
<FormGroup fieldId="enable-tls"> | ||
<Checkbox | ||
id="enable-tls" | ||
label={t('Enable TLS/SSL')} | ||
description={t( | ||
'Enable this for encrytion on flight with the Postgres server' | ||
)} | ||
isChecked={tlsEnabled} | ||
onChange={() => { | ||
const isTLSEnabled = !tlsEnabled; | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/enableTLS', | ||
payload: !tlsEnabled, | ||
}); | ||
|
||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/allowSelfSignedCerts', | ||
payload: | ||
!isTLSEnabled && allowSelfSignedCerts | ||
? false | ||
: allowSelfSignedCerts, | ||
}); | ||
|
||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/enableClientSideCerts', | ||
payload: | ||
!isTLSEnabled && enableClientSideCerts | ||
? false | ||
: enableClientSideCerts, | ||
}); | ||
}} | ||
className="odf-backing-store__radio--margin-bottom" | ||
/> | ||
{tlsEnabled && ( | ||
<Stack className="odf-backing-store__ssl" hasGutter> | ||
<Checkbox | ||
id="allow-self-signed-certs" | ||
label={t('Allow self-signed certificates')} | ||
description={t( | ||
'Adding this option will allow the postgres server to use a self-signed certificates.' | ||
)} | ||
isChecked={allowSelfSignedCerts} | ||
onChange={() => | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/allowSelfSignedCerts', | ||
payload: !allowSelfSignedCerts, | ||
}) | ||
} | ||
/> | ||
<Checkbox | ||
id="enable-client-side-certs" | ||
label={t('Enable client-side certificates')} | ||
description={t( | ||
'Select this option to upload and use your client side certificates' | ||
)} | ||
isChecked={enableClientSideCerts} | ||
onChange={() => { | ||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/enableClientSideCerts', | ||
payload: !enableClientSideCerts, | ||
}); | ||
|
||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/keys/setPrivateKey', | ||
payload: null, | ||
}); | ||
|
||
dispatch({ | ||
type: 'backingStorage/externalPostgres/tls/keys/setPublicKey', | ||
payload: null, | ||
}); | ||
}} | ||
/> | ||
</Stack> | ||
)} | ||
{enableClientSideCerts && ( | ||
<UploadFile | ||
acceptedFiles=".pem, .key, .crt" | ||
infoText={t('Accepted file types: .pem, .crt, .key')} | ||
titleText={t( | ||
'Files should be named private and public followed by compatible extensions' | ||
)} | ||
onFileUpload={processKeys} | ||
uploadLimit={2} | ||
compatibleFileFilter={(file) => | ||
file.name.startsWith('private') || file.name.startsWith('public') | ||
} | ||
/> | ||
)} | ||
</FormGroup> | ||
</Form> | ||
); | ||
}; | ||
|
||
type PostgresConnectionDetails = { | ||
dispatch: WizardDispatch; | ||
username: WizardState['backingStorage']['externalPostgres']['username']; | ||
password: WizardState['backingStorage']['externalPostgres']['password']; | ||
serverName: WizardState['backingStorage']['externalPostgres']['serverName']; | ||
port: WizardState['backingStorage']['externalPostgres']['port']; | ||
databaseName: WizardState['backingStorage']['externalPostgres']['databaseName']; | ||
tlsEnabled: WizardState['backingStorage']['externalPostgres']['tls']['enabled']; | ||
allowSelfSignedCerts: WizardState['backingStorage']['externalPostgres']['tls']['allowSelfSignedCerts']; | ||
enableClientSideCerts: WizardState['backingStorage']['externalPostgres']['tls']['enableClientSideCerts']; | ||
}; |
Oops, something went wrong.