-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #767 from SquirrelCorporation/654-featadd-custom-a…
…nsible-vault [FEAT] 654 featadd custom ansible vault
- Loading branch information
Showing
31 changed files
with
638 additions
and
52 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
136 changes: 136 additions & 0 deletions
136
client/src/pages/Admin/Settings/components/subcomponents/CustomVaultModal.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,136 @@ | ||
import { UserSecret } from '@/components/Icons/CustomIcons'; | ||
import { | ||
deleteAnsibleVault, | ||
postAnsibleVault, | ||
updateAnsibleVault, | ||
} from '@/services/rest/ansible'; | ||
import { DeleteOutlined } from '@ant-design/icons'; | ||
import { ModalForm, ProForm, ProFormText } from '@ant-design/pro-components'; | ||
import { Avatar, Button, message, Popconfirm } from 'antd'; | ||
import React, { FC, useState } from 'react'; | ||
import { API } from 'ssm-shared-lib'; | ||
|
||
type CustomVaultModalProps = { | ||
selectedRecord?: Partial<API.CustomVault>; | ||
modalOpened: boolean; | ||
setModalOpened: any; | ||
asyncFetch: () => Promise<void>; | ||
vaults: API.CustomVault[]; | ||
}; | ||
|
||
const PlaybooksLocalRepositoryModal: FC<CustomVaultModalProps> = ({ | ||
selectedRecord, | ||
modalOpened, | ||
setModalOpened, | ||
asyncFetch, | ||
vaults, | ||
}) => { | ||
const [loading, setLoading] = useState(false); | ||
|
||
const editionMode = selectedRecord | ||
? [ | ||
<Popconfirm | ||
key="delete" | ||
title="Are you sure to delete this Vault?" | ||
onConfirm={async () => { | ||
setLoading(true); | ||
if (selectedRecord && selectedRecord.vaultId) { | ||
await deleteAnsibleVault(selectedRecord.vaultId) | ||
.then(() => | ||
message.warning({ | ||
content: 'Vault deleted', | ||
duration: 5, | ||
}), | ||
) | ||
.finally(() => { | ||
setModalOpened(false); | ||
}); | ||
await asyncFetch(); | ||
} | ||
setLoading(false); | ||
}} | ||
> | ||
<Button icon={<DeleteOutlined />} danger loading={loading}> | ||
Delete | ||
</Button> | ||
</Popconfirm>, | ||
] | ||
: []; | ||
return ( | ||
<ModalForm<API.CustomVault> | ||
title={ | ||
<> | ||
<Avatar | ||
size={50} | ||
shape="square" | ||
style={{ | ||
marginRight: 4, | ||
backgroundColor: 'rgba(41,70,147,0.51)', | ||
}} | ||
src={<UserSecret />} | ||
/> | ||
{(selectedRecord && <>Edit vault {selectedRecord?.vaultId}</>) || ( | ||
<>Add a new vault</> | ||
)} | ||
</> | ||
} | ||
open={modalOpened} | ||
autoFocusFirstInput | ||
modalProps={{ | ||
destroyOnClose: true, | ||
onCancel: () => setModalOpened(false), | ||
}} | ||
onFinish={async (values) => { | ||
if (selectedRecord) { | ||
await updateAnsibleVault(values); | ||
setModalOpened(false); | ||
await asyncFetch(); | ||
} else { | ||
await postAnsibleVault(values); | ||
setModalOpened(false); | ||
await asyncFetch(); | ||
} | ||
}} | ||
submitter={{ | ||
searchConfig: { | ||
submitText: 'Save', | ||
}, | ||
render: (_, defaultDoms) => { | ||
return [...editionMode, ...defaultDoms]; | ||
}, | ||
}} | ||
> | ||
<ProForm.Group> | ||
<ProFormText | ||
width={'md'} | ||
name={'vaultId'} | ||
label={'Vault ID'} | ||
disabled={!!selectedRecord?.vaultId} | ||
initialValue={selectedRecord?.vaultId} | ||
rules={[ | ||
{ required: true }, | ||
{ | ||
validator(_, value) { | ||
if ( | ||
vaults.find((e) => e.vaultId === value) === undefined || | ||
selectedRecord?.vaultId === value | ||
) { | ||
return Promise.resolve(); | ||
} | ||
return Promise.reject('Vault ID already exists'); | ||
}, | ||
}, | ||
]} | ||
/> | ||
<ProFormText.Password | ||
width={'md'} | ||
name={'password'} | ||
label={'Password'} | ||
rules={[{ required: true }]} | ||
/> | ||
</ProForm.Group> | ||
</ModalForm> | ||
); | ||
}; | ||
|
||
export default PlaybooksLocalRepositoryModal; |
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
36 changes: 36 additions & 0 deletions
36
client/src/pages/Admin/Settings/components/subcomponents/forms/CustomVault.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,36 @@ | ||
import { getAnsibleVaults } from '@/services/rest/ansible'; | ||
import { ProFormSelect } from '@ant-design/pro-form'; | ||
import React from 'react'; | ||
import { API } from 'ssm-shared-lib'; | ||
|
||
type CustomVaultProps = { | ||
selectedRecord?: | ||
| Partial<API.GitPlaybooksRepository | API.LocalPlaybooksRepository> | ||
| undefined; | ||
}; | ||
|
||
const CustomVault: React.FC<CustomVaultProps> = ({ selectedRecord }) => { | ||
return ( | ||
<ProFormSelect | ||
width={'md'} | ||
tooltip={ | ||
'Vaults to be used by the playbooks. The vaults are defined in the Vaults section of this page.' | ||
} | ||
label={'Custom Vaults'} | ||
name={'vaults'} | ||
initialValue={selectedRecord?.vaults} | ||
request={async () => | ||
(await getAnsibleVaults())?.data?.map((e: API.AnsibleVault) => ({ | ||
label: e.vaultId, | ||
value: e._id, | ||
})) | ||
} | ||
fieldProps={{ | ||
mode: 'tags', | ||
}} | ||
placeholder={'Your custom vaults'} | ||
/> | ||
); | ||
}; | ||
|
||
export default CustomVault; |
Oops, something went wrong.