From 7962ec99ce8b69f1ac83c532240f5f7a5b697e18 Mon Sep 17 00:00:00 2001 From: Shivanand Sonnad Date: Fri, 7 Mar 2025 06:33:59 +0000 Subject: [PATCH] feat: [AH-1024]: support python package type in repository creation, listing flow (#3519) * feat: [AH-1024]: support python package type in repository creation, listing flow --- web/src/ar/MFEAppTypes.ts | 3 +- web/src/ar/common/types.ts | 2 +- web/src/ar/hooks/useGetRepositoryTypes.ts | 3 +- .../useGetUpstreamRepositoryPackageTypes.ts | 8 ++ .../PythonRepository/PythonRepositoryType.tsx | 130 ++++++++++++++++++ .../repository-details/RepositoryFactory.tsx | 2 + .../AuthenticationFormInput/constants.tsx | 4 + .../RepositoryUrlInput/constants.ts | 4 + .../strings/strings.en.yaml | 1 + .../ar/pages/upstream-proxy-details/types.ts | 6 +- web/src/ar/strings/strings.en.yaml | 4 +- web/src/ar/strings/types.ts | 1 + 12 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 web/src/ar/pages/repository-details/PythonRepository/PythonRepositoryType.tsx diff --git a/web/src/ar/MFEAppTypes.ts b/web/src/ar/MFEAppTypes.ts index d5b605618..1f8e09320 100644 --- a/web/src/ar/MFEAppTypes.ts +++ b/web/src/ar/MFEAppTypes.ts @@ -134,5 +134,6 @@ export interface MFEAppProps { export enum FeatureFlags { HAR_TRIGGERS = 'HAR_TRIGGERS', - HAR_NPM_PACKAGE_TYPE_ENABLED = 'HAR_NPM_PACKAGE_TYPE_ENABLED' + HAR_NPM_PACKAGE_TYPE_ENABLED = 'HAR_NPM_PACKAGE_TYPE_ENABLED', + HAR_PYTHON_PACKAGE_TYPE_ENABLED = 'HAR_PYTHON_PACKAGE_TYPE_ENABLED' } diff --git a/web/src/ar/common/types.ts b/web/src/ar/common/types.ts index 8f851c8c6..d9ba42d2a 100644 --- a/web/src/ar/common/types.ts +++ b/web/src/ar/common/types.ts @@ -51,7 +51,7 @@ export enum RepositoryPackageType { MAVEN = 'MAVEN', NPM = 'NPM', GRADLE = 'GRADLE', - PYPI = 'PYPI', + PYTHON = 'PYTHON', NUGET = 'NUGET' } diff --git a/web/src/ar/hooks/useGetRepositoryTypes.ts b/web/src/ar/hooks/useGetRepositoryTypes.ts index 89e50df85..1358203aa 100644 --- a/web/src/ar/hooks/useGetRepositoryTypes.ts +++ b/web/src/ar/hooks/useGetRepositoryTypes.ts @@ -75,9 +75,10 @@ const RepositoryTypes: RepositoryTypeListItem[] = [ }, { label: 'repositoryTypes.pypi', - value: RepositoryPackageType.PYPI, + value: RepositoryPackageType.PYTHON, icon: 'python', tooltip: 'Coming Soon!', + featureFlag: FeatureFlags.HAR_PYTHON_PACKAGE_TYPE_ENABLED, disabled: true }, { diff --git a/web/src/ar/hooks/useGetUpstreamRepositoryPackageTypes.ts b/web/src/ar/hooks/useGetUpstreamRepositoryPackageTypes.ts index b5fad67e0..0df33e235 100644 --- a/web/src/ar/hooks/useGetUpstreamRepositoryPackageTypes.ts +++ b/web/src/ar/hooks/useGetUpstreamRepositoryPackageTypes.ts @@ -69,5 +69,13 @@ export const UpstreamProxyPackageTypeList: UpstreamRepositoryPackageTypeListItem tooltip: 'Coming Soon!', featureFlag: FeatureFlags.HAR_NPM_PACKAGE_TYPE_ENABLED, disabled: true + }, + { + label: 'repositoryTypes.pypi', + value: UpstreamProxyPackageType.PYTHON, + icon: 'python', + tooltip: 'Coming Soon!', + featureFlag: FeatureFlags.HAR_PYTHON_PACKAGE_TYPE_ENABLED, + disabled: true } ] diff --git a/web/src/ar/pages/repository-details/PythonRepository/PythonRepositoryType.tsx b/web/src/ar/pages/repository-details/PythonRepository/PythonRepositoryType.tsx new file mode 100644 index 000000000..f0fe9f5b5 --- /dev/null +++ b/web/src/ar/pages/repository-details/PythonRepository/PythonRepositoryType.tsx @@ -0,0 +1,130 @@ +/* + * Copyright 2024 Harness, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react' +import type { IconName } from '@harnessio/icons' + +import { RepositoryConfigType, RepositoryPackageType } from '@ar/common/types' +import UpstreamProxyActions from '@ar/pages/upstream-proxy-details/components/UpstreamProxyActions/UpstreamProxyActions' +import UpstreamProxyConfigurationForm from '@ar/pages/upstream-proxy-details/components/Forms/UpstreamProxyConfigurationForm' +import UpstreamProxyCreateFormContent from '@ar/pages/upstream-proxy-details/components/FormContent/UpstreamProxyCreateFormContent' +import UpstreamProxyDetailsHeader from '@ar/pages/upstream-proxy-details/components/UpstreamProxyDetailsHeader/UpstreamProxyDetailsHeader' +import { + type CreateRepositoryFormProps, + type RepositoryActionsProps, + type RepositoryConfigurationFormProps, + type RepositoryDetailsHeaderProps, + RepositoryStep, + type RepositoySetupClientProps +} from '@ar/frameworks/RepositoryStep/Repository' +import { + UpstreamProxyAuthenticationMode, + type UpstreamRegistryRequest, + UpstreamRepositoryURLInputSource +} from '@ar/pages/upstream-proxy-details/types' + +import type { Repository, VirtualRegistryRequest } from '../types' +import RepositoryActions from '../components/Actions/RepositoryActions' +import RedirectPageView from '../components/RedirectPageView/RedirectPageView' +import SetupClientContent from '../components/SetupClientContent/SetupClientContent' +import RepositoryConfigurationForm from '../components/Forms/RepositoryConfigurationForm' +import RepositoryCreateFormContent from '../components/FormContent/RepositoryCreateFormContent' +import RepositoryDetailsHeader from '../components/RepositoryDetailsHeader/RepositoryDetailsHeader' + +export class PythonRepositoryType extends RepositoryStep { + protected packageType = RepositoryPackageType.PYTHON + protected repositoryName = 'Python Repository' + protected repositoryIcon: IconName = 'python' + protected supportedScanners = [] + protected supportsUpstreamProxy = true + protected supportedUpstreamURLSources = [ + UpstreamRepositoryURLInputSource.PyPi, + UpstreamRepositoryURLInputSource.Custom + ] + + protected defaultValues: VirtualRegistryRequest = { + packageType: RepositoryPackageType.PYTHON, + identifier: '', + config: { + type: RepositoryConfigType.VIRTUAL + }, + scanners: [] + } + + protected defaultUpstreamProxyValues: UpstreamRegistryRequest = { + packageType: RepositoryPackageType.PYTHON, + identifier: '', + config: { + type: RepositoryConfigType.UPSTREAM, + source: UpstreamRepositoryURLInputSource.PyPi, + authType: UpstreamProxyAuthenticationMode.ANONYMOUS, + url: '' + }, + cleanupPolicy: [], + scanners: [] + } + + renderCreateForm(props: CreateRepositoryFormProps): JSX.Element { + const { type } = props + if (type === RepositoryConfigType.VIRTUAL) { + return + } else { + return + } + } + + renderCofigurationForm(props: RepositoryConfigurationFormProps): JSX.Element { + const { type } = props + if (type === RepositoryConfigType.VIRTUAL) { + return + } else { + return + } + } + + renderActions(props: RepositoryActionsProps): JSX.Element { + if (props.type === RepositoryConfigType.VIRTUAL) { + return + } + return + } + + renderSetupClient(props: RepositoySetupClientProps): JSX.Element { + const { repoKey, onClose, artifactKey, versionKey } = props + return ( + + ) + } + + renderRepositoryDetailsHeader(props: RepositoryDetailsHeaderProps): JSX.Element { + const { type } = props + if (type === RepositoryConfigType.VIRTUAL) { + return + } else { + return + } + } + + renderRedirectPage(): JSX.Element { + return + } +} diff --git a/web/src/ar/pages/repository-details/RepositoryFactory.tsx b/web/src/ar/pages/repository-details/RepositoryFactory.tsx index 333798ee2..5c045c611 100644 --- a/web/src/ar/pages/repository-details/RepositoryFactory.tsx +++ b/web/src/ar/pages/repository-details/RepositoryFactory.tsx @@ -20,9 +20,11 @@ import { MavenRepositoryType } from './MavenRepository/MavenRepository' import { HelmRepositoryType } from './HelmRepository/HelmRepositoryType' import { GenericRepositoryType } from './GenericRepository/GenericRepositoryType' import { NpmRepositoryType } from './NpmRepository/NpmRepositoryType' +import { PythonRepositoryType } from './PythonRepository/PythonRepositoryType' repositoryFactory.registerStep(new DockerRepositoryType()) repositoryFactory.registerStep(new HelmRepositoryType()) repositoryFactory.registerStep(new GenericRepositoryType()) repositoryFactory.registerStep(new MavenRepositoryType()) repositoryFactory.registerStep(new NpmRepositoryType()) +repositoryFactory.registerStep(new PythonRepositoryType()) diff --git a/web/src/ar/pages/upstream-proxy-details/components/AuthenticationFormInput/constants.tsx b/web/src/ar/pages/upstream-proxy-details/components/AuthenticationFormInput/constants.tsx index 41df40ee8..e1e842c1c 100644 --- a/web/src/ar/pages/upstream-proxy-details/components/AuthenticationFormInput/constants.tsx +++ b/web/src/ar/pages/upstream-proxy-details/components/AuthenticationFormInput/constants.tsx @@ -62,5 +62,9 @@ export const URLSourceToSupportedAuthTypesMapping: Record< [UpstreamRepositoryURLInputSource.NpmJS]: [ UpstreamProxyAuthenticationMode.USER_NAME_AND_PASSWORD, UpstreamProxyAuthenticationMode.ANONYMOUS + ], + [UpstreamRepositoryURLInputSource.PyPi]: [ + UpstreamProxyAuthenticationMode.USER_NAME_AND_PASSWORD, + UpstreamProxyAuthenticationMode.ANONYMOUS ] } diff --git a/web/src/ar/pages/upstream-proxy-details/components/RepositoryUrlInput/constants.ts b/web/src/ar/pages/upstream-proxy-details/components/RepositoryUrlInput/constants.ts index 0362ac7a4..3b7ccdd3b 100644 --- a/web/src/ar/pages/upstream-proxy-details/components/RepositoryUrlInput/constants.ts +++ b/web/src/ar/pages/upstream-proxy-details/components/RepositoryUrlInput/constants.ts @@ -41,5 +41,9 @@ export const UpstreamURLSourceConfig: Record