Skip to content

Commit f4cdeeb

Browse files
committed
feat: add authentication type radio button
1 parent 96ade6f commit f4cdeeb

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

src/components/dockerRegistry/Docker.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
RegistryIcon,
5454
ComponentSizeType,
5555
PasswordField,
56+
OtherRegistryAuthenticationType,
5657
} from '@devtron-labs/devtron-fe-common-lib'
5758
import Tippy from '@tippyjs/react'
5859
import { useHistory, useParams, useRouteMatch } from 'react-router-dom'
@@ -100,6 +101,7 @@ import { VALIDATION_STATUS, ValidateForm } from '../common/ValidateForm/Validate
100101
const RegistryHelmPushCheckbox = importComponentFromFELibrary('RegistryHelmPushCheckbox')
101102
const RemoteConnectionRadio = importComponentFromFELibrary('RemoteConnectionRadio')
102103
const getRemoteConnectionConfig = importComponentFromFELibrary('getRemoteConnectionConfig', noop, 'function')
104+
const AuthenticationTypeRadio = importComponentFromFELibrary('AuthenticationTypeRadio', null, 'function')
103105

104106
enum CERTTYPE {
105107
SECURE = 'secure',
@@ -259,6 +261,7 @@ const CollapsedList = ({
259261
repositoryList = [],
260262
disabledFields = [],
261263
ociRegistryConfig,
264+
credentialsType,
262265
...rest
263266
}) => {
264267
const [collapsed, toggleCollapse] = useState(true)
@@ -338,6 +341,7 @@ const CollapsedList = ({
338341
isPublic,
339342
disabledFields,
340343
ociRegistryConfig,
344+
credentialsType,
341345
}}
342346
/>
343347
)}
@@ -377,6 +381,7 @@ const DockerForm = ({
377381
: {
378382
CONTAINER: OCIRegistryConfigConstants.PULL_PUSH,
379383
},
384+
credentialsType: authCredentialsType,
380385
...rest
381386
}) => {
382387
const re = PATTERNS.APP_NAME
@@ -539,6 +544,9 @@ const DockerForm = ({
539544
const [registryStorageType, setRegistryStorageType] = useState<string>(
540545
isPublic ? RegistryStorageType.OCI_PUBLIC : RegistryStorageType.OCI_PRIVATE,
541546
)
547+
const [authenticationType, setAuthenticationType] = useState<OtherRegistryAuthenticationType>(
548+
id ? authCredentialsType : OtherRegistryAuthenticationType.USERNAME_PASSWORD,
549+
)
542550

543551
const InitialValueOfIsContainerStore: boolean =
544552
ociRegistryConfig?.CONTAINER === OCIRegistryConfigConstants.PULL_PUSH
@@ -712,6 +720,11 @@ const DockerForm = ({
712720
}
713721
}
714722

723+
const handleChangeOtherRegistryAuthType = (e) => {
724+
const updatedAuthType = e.target.value as OtherRegistryAuthenticationType
725+
setAuthenticationType(updatedAuthType)
726+
}
727+
715728
function fetchAWSRegion(): string {
716729
const pattern =
717730
registryStorageType === RegistryStorageType.OCI_PUBLIC
@@ -839,6 +852,9 @@ const DockerForm = ({
839852
customState.remoteConnectionConfig.connectionMethod.value,
840853
sshConnectionType,
841854
),
855+
...(AuthenticationTypeRadio && selectedDockerRegistryType.value === RegistryType.OTHER
856+
? { credentialsType: authenticationType }
857+
: {}),
842858
}
843859
}
844860

@@ -1003,6 +1019,7 @@ const DockerForm = ({
10031019
let error = false
10041020
if (
10051021
registryStorageType === RegistryStorageType.OCI_PRIVATE &&
1022+
authenticationType === OtherRegistryAuthenticationType.USERNAME_PASSWORD &&
10061023
(!customState.username.value || !(customState.password.value || id))
10071024
) {
10081025
setCustomState((st) => ({
@@ -1605,13 +1622,25 @@ const DockerForm = ({
16051622
</>
16061623
)
16071624
}
1625+
1626+
const isUserNamePasswordRequired =
1627+
selectedDockerRegistryType.value === RegistryType.OTHER
1628+
? authenticationType === OtherRegistryAuthenticationType.USERNAME_PASSWORD
1629+
: true
1630+
16081631
return (
16091632
<>
1633+
{AuthenticationTypeRadio && selectedDockerRegistryType.value === RegistryType.OTHER && (
1634+
<AuthenticationTypeRadio
1635+
authenticationType={authenticationType}
1636+
handleChangeOtherRegistryAuthType={handleChangeOtherRegistryAuthType}
1637+
/>
1638+
)}
16101639
<div className={`${isGCROrGCP ? '' : 'form__row--two-third'}`}>
16111640
<div className="form__row">
16121641
<CustomInput
16131642
name="username"
1614-
required
1643+
required={isUserNamePasswordRequired}
16151644
value={customState.username.value || selectedDockerRegistryType.id.defaultValue}
16161645
error={customState.username.error}
16171646
onChange={customHandleChange}
@@ -1632,7 +1661,7 @@ const DockerForm = ({
16321661
<PasswordField
16331662
shouldShowDefaultPlaceholderOnBlur={!!id}
16341663
name="password"
1635-
required
1664+
required={isUserNamePasswordRequired}
16361665
value={customState.password.value}
16371666
error={customState.password.error}
16381667
onChange={customHandleChange}

src/components/dockerRegistry/service.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { post, put, get, trash } from '@devtron-labs/devtron-fe-common-lib'
1818
import { Routes } from '../../config'
1919

20+
// Dead code
2021
export function getDockerRegistryConfig(id: string): Promise<any> {
2122
const URL = `${Routes.DOCKER_REGISTRY_CONFIG}/${id}`
2223
return get(URL)

src/config/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
ToastManager,
2222
ROUTES as COMMON_ROUTES,
2323
EnvResourceType,
24+
OtherRegistryAuthenticationType,
2425
} from '@devtron-labs/devtron-fe-common-lib'
2526
export const DEFAULT_STATUS = 'checking'
2627
export const DEFAULT_STATUS_TEXT = 'Checking Status'
@@ -471,6 +472,7 @@ export type OCIRegistryStorageConfigType = {
471472
CONTAINER?: OCIRegistryStorageActionType
472473
CHART?: OCIRegistryStorageActionType
473474
}
475+
474476
export const OCIRegistryConfigConstants: Record<string, OCIRegistryStorageActionType> = {
475477
PULL: 'PULL',
476478
PUSH: 'PUSH',
@@ -541,6 +543,7 @@ export interface RegistryPayloadType {
541543
sshAuthKey: string
542544
}
543545
}
546+
credentialsType?: OtherRegistryAuthenticationType
544547
}
545548

546549
export interface RegistryPayloadWithSelectType extends RegistryPayloadType, SelectPickerOptionType {}

src/services/service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ export function getDockerRegistryStatus(isStorageActionPush?: boolean): Promise<
250250
}
251251

252252
export function getDockerRegistryList(): Promise<ResponseType> {
253-
const URL = `${Routes.DOCKER_REGISTRY_CONFIG}`
254-
return get(URL)
253+
return get(Routes.DOCKER_REGISTRY_CONFIG)
255254
}
256255

257256
export function getAppOtherEnvironmentMin(

0 commit comments

Comments
 (0)