|
| 1 | +/* |
| 2 | + * Copyright 2024 Harness, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import React from 'react' |
| 18 | +import type { IconName } from '@harnessio/icons' |
| 19 | + |
| 20 | +import { RepositoryConfigType, RepositoryPackageType } from '@ar/common/types' |
| 21 | +import UpstreamProxyActions from '@ar/pages/upstream-proxy-details/components/UpstreamProxyActions/UpstreamProxyActions' |
| 22 | +import UpstreamProxyConfigurationForm from '@ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyConfigurationForm' |
| 23 | +import UpstreamProxyCreateFormContent from '@ar/pages/upstream-proxy-details/components/FormContent/UpstreamProxyCreateFormContent' |
| 24 | +import UpstreamProxyDetailsHeader from '@ar/pages/upstream-proxy-details/components/UpstreamProxyDetailsHeader/UpstreamProxyDetailsHeader' |
| 25 | +import { |
| 26 | + type CreateRepositoryFormProps, |
| 27 | + type RepositoryActionsProps, |
| 28 | + type RepositoryConfigurationFormProps, |
| 29 | + type RepositoryDetailsHeaderProps, |
| 30 | + RepositoryStep, |
| 31 | + type RepositoryTreeNodeProps, |
| 32 | + type RepositoySetupClientProps |
| 33 | +} from '@ar/frameworks/RepositoryStep/Repository' |
| 34 | +import { |
| 35 | + UpstreamProxyAuthenticationMode, |
| 36 | + type UpstreamRegistryRequest, |
| 37 | + UpstreamRepositoryURLInputSource |
| 38 | +} from '@ar/pages/upstream-proxy-details/types' |
| 39 | + |
| 40 | +import RepositoryDetails from '../RepositoryDetails' |
| 41 | +import type { Repository, VirtualRegistryRequest } from '../types' |
| 42 | +import RepositoryActions from '../components/Actions/RepositoryActions' |
| 43 | +import RedirectPageView from '../components/RedirectPageView/RedirectPageView' |
| 44 | +import SetupClientContent from '../components/SetupClientContent/SetupClientContent' |
| 45 | +import RepositoryTreeNode from '../components/RepositoryTreeNode/RepositoryTreeNode' |
| 46 | +import RepositoryConfigurationForm from '../components/Forms/RepositoryConfigurationForm' |
| 47 | +import RepositoryCreateFormContent from '../components/FormContent/RepositoryCreateFormContent' |
| 48 | +import RepositoryDetailsHeader from '../components/RepositoryDetailsHeader/RepositoryDetailsHeader' |
| 49 | + |
| 50 | +export class CondaRepositoryType extends RepositoryStep<VirtualRegistryRequest> { |
| 51 | + protected packageType = RepositoryPackageType.CONDA |
| 52 | + protected repositoryName = 'Conda Repository' |
| 53 | + protected repositoryIcon: IconName = 'conda-icon' |
| 54 | + protected supportedScanners = [] |
| 55 | + protected supportsUpstreamProxy = true |
| 56 | + protected supportedUpstreamURLSources = [ |
| 57 | + UpstreamRepositoryURLInputSource.Anaconda, |
| 58 | + UpstreamRepositoryURLInputSource.Custom |
| 59 | + ] |
| 60 | + |
| 61 | + protected defaultValues: VirtualRegistryRequest = { |
| 62 | + packageType: RepositoryPackageType.CONDA, |
| 63 | + identifier: '', |
| 64 | + config: { |
| 65 | + type: RepositoryConfigType.VIRTUAL |
| 66 | + }, |
| 67 | + scanners: [], |
| 68 | + isPublic: false |
| 69 | + } |
| 70 | + |
| 71 | + protected defaultUpstreamProxyValues: UpstreamRegistryRequest = { |
| 72 | + packageType: RepositoryPackageType.CONDA, |
| 73 | + identifier: '', |
| 74 | + config: { |
| 75 | + type: RepositoryConfigType.UPSTREAM, |
| 76 | + source: UpstreamRepositoryURLInputSource.Anaconda, |
| 77 | + authType: UpstreamProxyAuthenticationMode.ANONYMOUS, |
| 78 | + url: '' |
| 79 | + }, |
| 80 | + cleanupPolicy: [], |
| 81 | + scanners: [], |
| 82 | + isPublic: false |
| 83 | + } |
| 84 | + |
| 85 | + renderCreateForm(props: CreateRepositoryFormProps): JSX.Element { |
| 86 | + const { type } = props |
| 87 | + if (type === RepositoryConfigType.VIRTUAL) { |
| 88 | + return <RepositoryCreateFormContent isEdit={false} /> |
| 89 | + } else { |
| 90 | + return <UpstreamProxyCreateFormContent isEdit={false} readonly={false} /> |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + renderCofigurationForm(props: RepositoryConfigurationFormProps<Repository>): JSX.Element { |
| 95 | + const { type } = props |
| 96 | + if (type === RepositoryConfigType.VIRTUAL) { |
| 97 | + return <RepositoryConfigurationForm ref={props.formikRef} readonly={props.readonly} /> |
| 98 | + } else { |
| 99 | + return <UpstreamProxyConfigurationForm ref={props.formikRef} readonly={props.readonly} /> |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + renderActions(props: RepositoryActionsProps<Repository>): JSX.Element { |
| 104 | + if (props.type === RepositoryConfigType.VIRTUAL) { |
| 105 | + return <RepositoryActions data={props.data} readonly={props.readonly} pageType={props.pageType} /> |
| 106 | + } |
| 107 | + return <UpstreamProxyActions data={props.data} readonly={props.readonly} pageType={props.pageType} /> |
| 108 | + } |
| 109 | + |
| 110 | + renderSetupClient(props: RepositoySetupClientProps): JSX.Element { |
| 111 | + const { repoKey, onClose, artifactKey, versionKey } = props |
| 112 | + return ( |
| 113 | + <SetupClientContent |
| 114 | + repoKey={repoKey} |
| 115 | + artifactKey={artifactKey} |
| 116 | + versionKey={versionKey} |
| 117 | + onClose={onClose} |
| 118 | + packageType={RepositoryPackageType.CONDA} |
| 119 | + /> |
| 120 | + ) |
| 121 | + } |
| 122 | + |
| 123 | + renderRepositoryDetailsHeader(props: RepositoryDetailsHeaderProps<Repository>): JSX.Element { |
| 124 | + const { type } = props |
| 125 | + if (type === RepositoryConfigType.VIRTUAL) { |
| 126 | + return <RepositoryDetailsHeader data={props.data} /> |
| 127 | + } else { |
| 128 | + return <UpstreamProxyDetailsHeader data={props.data} /> |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + renderRedirectPage(): JSX.Element { |
| 133 | + return <RedirectPageView /> |
| 134 | + } |
| 135 | + |
| 136 | + renderTreeNodeView(props: RepositoryTreeNodeProps): JSX.Element { |
| 137 | + return <RepositoryTreeNode {...props} icon={this.repositoryIcon} /> |
| 138 | + } |
| 139 | + |
| 140 | + renderTreeNodeDetails(): JSX.Element { |
| 141 | + return <RepositoryDetails /> |
| 142 | + } |
| 143 | +} |
0 commit comments