Skip to content

Commit

Permalink
feat: [TKC-1454] disable secret management (#1021)
Browse files Browse the repository at this point in the history
* feat: disable secret management

* refactor: card form disabled
  • Loading branch information
topliceanurazvan authored Feb 26, 2024
1 parent 73bbec2 commit 5c89bc1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {Branch, Path, Repository, SecretFormItem} from '@molecules';

import {useValidateRepositoryMutation} from '@services/repository';

import {useClusterDetailsPick} from '@store/clusterDetails';

import {StyledFormSpace} from '../TestConfigurationForm.styled';
import {Props} from '../utils';

Expand All @@ -16,17 +18,26 @@ const GitFormFields: React.FC<Partial<Props>> = props => {

const [validateRepository] = useValidateRepositoryMutation();

const {disableSecretCreation} = useClusterDetailsPick('disableSecretCreation');

useValidateRepository(getFieldValue, setValidationState, validateRepository);

return (
<StyledFormSpace size={24} direction="vertical">
<Repository message={validationState.message} status={validationState.uri} />
<SecretFormItem message={validationState.message} status={validationState.token} name="token" label="Git Token" />
<SecretFormItem
message={validationState.message}
status={validationState.token}
name="token"
label="Git Token"
disabled={disableSecretCreation}
/>
<SecretFormItem
message={validationState.message}
status={validationState.username}
name="username"
label="Git Username"
disabled={disableSecretCreation}
/>
<Branch message={validationState.message} status={validationState.branch} />
<Path testType={executorType} message={validationState.message} status={validationState.path} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {Path, Repository, Revision, SecretFormItem} from '@molecules';

import {useValidateRepositoryMutation} from '@services/repository';

import {useClusterDetailsPick} from '@store/clusterDetails';

import {StyledFormSpace} from '../TestConfigurationForm.styled';
import {Props} from '../utils';

Expand All @@ -24,6 +26,8 @@ const SourceEdit: React.FC<Partial<Props>> = props => {
message: '',
});

const {disableSecretCreation} = useClusterDetailsPick('disableSecretCreation');

const [validateRepository] = useValidateRepositoryMutation();

useValidateRepository(getFieldValue, setValidationState, validateRepository);
Expand All @@ -38,7 +42,7 @@ const SourceEdit: React.FC<Partial<Props>> = props => {
setIsClearedValue={setIsClearedToken}
message={validationState.message}
status={validationState.token}
disabled={disabled}
disabled={disabled || disableSecretCreation}
/>
<SecretFormItem
name="username"
Expand All @@ -47,7 +51,7 @@ const SourceEdit: React.FC<Partial<Props>> = props => {
setIsClearedValue={setIsClearedUsername}
message={validationState.message}
status={validationState.username}
disabled={disabled}
disabled={disabled || disableSecretCreation}
/>
<Revision
message={validationState.message}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {Permissions, usePermission} from '@permissions/base';

import {useUpdateSourceMutation} from '@services/sources';

import {useClusterDetailsPick} from '@store/clusterDetails';
import {useSourcesPick} from '@store/sources';

import {displayDefaultNotificationFlow} from '@utils/notification';
Expand All @@ -28,6 +29,7 @@ const Authentication: React.FC = () => {
const [form] = Form.useForm<AuthenticationFormValues>();

const {current} = useSourcesPick('current');
const {disableSecretCreation} = useClusterDetailsPick('disableSecretCreation');

const [updateSource] = useUpdateSourceMutation();

Expand Down Expand Up @@ -77,20 +79,20 @@ const Authentication: React.FC = () => {
spacing={24}
form={form}
initialValues={defaults}
disabled={!mayEdit}
disabled={!mayEdit || disableSecretCreation}
wasTouched={Boolean((tokenSecret && isClearedToken) || (usernameSecret && isClearedUsername))}
onConfirm={onFinish}
onCancel={onCancel}
>
<SecretFormItem
name="username"
label="Git username"
label="Git Username"
isClearedValue={isClearedUsername}
setIsClearedValue={setIsClearedUsername}
/>
<SecretFormItem
name="token"
label="Git token"
label="Git Token"
isClearedValue={isClearedToken}
setIsClearedValue={setIsClearedToken}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type AddSourceFormValues = {
};

const AddSourceModal: React.FC = () => {
const {namespace} = useClusterDetailsPick('namespace');
const {disableSecretCreation, namespace} = useClusterDetailsPick('disableSecretCreation', 'namespace');
const [form] = Form.useForm<AddSourceFormValues>();
const openDetails = useDashboardNavigate((name: string) => `/sources/${name}`);
const {close} = useModal();
Expand Down Expand Up @@ -94,13 +94,14 @@ const AddSourceModal: React.FC = () => {
<Form.Item label="Git repository URL" required name="uri" rules={[required]}>
<Input placeholder="e.g.: https://github.com/myCompany/myRepo.git" />
</Form.Item>
<Form.Item label="Git username" name="username">
<Input placeholder="e.g.: my-user-name" />
<Form.Item label="Git Username" name="username">
<Input placeholder="e.g.: my-user-name" disabled={disableSecretCreation} />
</Form.Item>
<Form.Item label="Git token" name="token">
<Form.Item label="Git Token" name="token">
<AntdInput.Password
placeholder="e.g.: some-token"
iconRender={visible => (visible ? <EyeOutlined /> : <EyeInvisibleOutlined />)}
disabled={disableSecretCreation}
/>
</Form.Item>
<Form.Item
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/services/apiEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ApiDetails {
namespace: string;
version: string;
url: string;
disableSecretCreation?: boolean;
}

interface ApiEndpointConfig {
Expand Down

0 comments on commit 5c89bc1

Please sign in to comment.