Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 110x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 6x 1x 6x 11x 11x 3x 8x 6x 6x 1x 3x 110x 110x 110x 7x 7x 7x 7x 7x 5x 1x 4x 4x | /* * Copyright 2021 Harness Inc. All rights reserved. * Use of this source code is governed by the PolyForm Shield 1.0.0 license * that can be found in the licenses directory at the root of this repository, also available at * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt. */ import React, { useState } from 'react' import { defaultTo, get } from 'lodash-es' import { FormInput, getMultiTypeFromValue, Layout, MultiTypeInputType } from '@wings-software/uicore' import { ArtifactSourceBase, ArtifactSourceRenderProps } from '@cd/factory/ArtifactSourceFactory/ArtifactSourceBase' import { yamlStringify } from '@common/utils/YamlHelperMethods' import { useMutateAsGet } from '@common/hooks' import { FormMultiTypeConnectorField } from '@connectors/components/ConnectorReferenceField/FormMultiTypeConnectorField' import { SidecarArtifact, useGetBuildDetailsForGcrWithYaml } from 'services/cd-ng' import { ArtifactToConnectorMap, ENABLED_ARTIFACT_TYPES } from '@pipeline/components/ArtifactsSelection/ArtifactHelper' import { TriggerDefaultFieldList } from '@triggers/pages/triggers/utils/TriggersWizardPageUtils' import { useStrings } from 'framework/strings' import { useVariablesExpression } from '@pipeline/components/PipelineStudio/PiplineHooks/useVariablesExpression' import { shouldFetchTagsSource } from '@pipeline/components/ArtifactsSelection/ArtifactUtils' import ExperimentalInput from '../../K8sServiceSpecForms/ExperimentalInput' import { isFieldRuntime } from '../../K8sServiceSpecHelper' import { gcrUrlList, getImagePath, getYamlData, isArtifactSourceRuntime, isFieldfromTriggerTabDisabled, resetTags } from '../artifactSourceUtils' import ArtifactTagRuntimeField from '../ArtifactSourceRuntimeFields/ArtifactTagRuntimeField' import css from '../../K8sServiceSpec.module.scss' interface GCRRenderContent extends ArtifactSourceRenderProps { isTagsSelectionDisabled: (data: ArtifactSourceRenderProps) => boolean } const Content = (props: GCRRenderContent): JSX.Element => { const { isPrimaryArtifactsRuntime, isSidecarRuntime, template, formik, path, initialValues, accountId, projectIdentifier, orgIdentifier, readonly, repoIdentifier, pipelineIdentifier, branch, stageIdentifier, isTagsSelectionDisabled, allowableTypes, fromTrigger, artifact, isSidecar, artifactPath } = props const { getString } = useStrings() const isPropagatedStage = path?.includes('serviceConfig.stageOverrides') const { expressions } = useVariablesExpression() const [lastQueryData, setLastQueryData] = useState({ imagePath: '', registryHostname: '' }) const { data: gcrTagsData, loading: fetchingTags, refetch, error: fetchTagsError } = useMutateAsGet(useGetBuildDetailsForGcrWithYaml, { body: yamlStringify(getYamlData(formik?.values)), requestOptions: { headers: { 'content-type': 'application/json' } }, queryParams: { accountIdentifier: accountId, projectIdentifier, orgIdentifier, repoIdentifier, branch, imagePath: getImagePath( artifact?.spec?.imagePath, get(initialValues, `artifacts.${artifactPath}.spec.imagePath`, '') ), connectorRef: getMultiTypeFromValue(artifact?.spec?.connectorRef) !== MultiTypeInputType.RUNTIME ? artifact?.spec?.connectorRef : get(initialValues?.artifacts, `${artifactPath}.spec.connectorRef`, ''), registryHostname: getMultiTypeFromValue(artifact?.spec?.registryHostname) !== MultiTypeInputType.RUNTIME ? artifact?.spec?.registryHostname : get(initialValues?.artifacts, `${artifactPath}.spec.registryHostname`, ''), pipelineIdentifier: defaultTo(pipelineIdentifier, formik?.values?.identifier), fqnPath: isPropagatedStage ? `pipeline.stages.${stageIdentifier}.spec.serviceConfig.stageOverrides.artifacts.${artifactPath}.spec.tag` : `pipeline.stages.${stageIdentifier}.spec.serviceConfig.serviceDefinition.spec.artifacts.${artifactPath}.spec.tag` }, lazy: true }) const imagePathValue = getImagePath( artifact?.spec?.imagePath, get(initialValues, `artifacts.${artifactPath}.spec.imagePath`, '') ) const connectorRefValue = get(initialValues, `artifacts.${artifactPath}.spec.connectorRef`, '') || artifact?.spec?.connectorRef const registryHostnameValue = get(initialValues, `artifacts.${artifactPath}.spec.registryHostname`, '') || artifact?.spec?.registryHostname const fetchTags = (): void => { Eif (canFetchTags()) { setLastQueryData({ imagePath: imagePathValue, registryHostname: registryHostnameValue }) refetch() } } const canFetchTags = (): boolean => { return !!( (lastQueryData.imagePath !== imagePathValue || lastQueryData.registryHostname !== registryHostnameValue) && shouldFetchTagsSource(connectorRefValue, [imagePathValue, registryHostnameValue]) ) } const isFieldDisabled = (fieldName: string, isTag = false): boolean => { /* instanbul ignore else */ Iif ( readonly || isFieldfromTriggerTabDisabled( fieldName, formik, stageIdentifier, fromTrigger, isSidecar ? (artifact as SidecarArtifact)?.identifier : undefined ) ) { return true } if (isTag) { return isTagsSelectionDisabled(props) } return false } const isRuntime = isArtifactSourceRuntime(isPrimaryArtifactsRuntime, isSidecarRuntime, isSidecar as boolean) return ( <> {isRuntime && ( <Layout.Vertical key={artifactPath} className={css.inputWidth}> {isFieldRuntime(`artifacts.${artifactPath}.spec.connectorRef`, template) && ( <FormMultiTypeConnectorField name={`${path}.artifacts.${artifactPath}.spec.connectorRef`} label={getString('pipelineSteps.deploy.inputSet.artifactServer')} selected={get(initialValues, `artifacts.${artifactPath}.spec.connectorRef`, '')} placeholder={''} accountIdentifier={accountId} projectIdentifier={projectIdentifier} orgIdentifier={orgIdentifier} width={391} setRefValue disabled={isFieldDisabled(`artifacts.${artifactPath}.spec.connectorRef`)} multiTypeProps={{ allowableTypes: [MultiTypeInputType.EXPRESSION, MultiTypeInputType.FIXED], expressions }} onChange={() => resetTags(formik, `${path}.artifacts.${artifactPath}.spec.tag`)} className={css.connectorMargin} type={ArtifactToConnectorMap[defaultTo(artifact?.type, '')]} gitScope={{ repo: defaultTo(repoIdentifier, ''), branch: defaultTo(branch, ''), getDefaultFromOtherRepo: true }} /> )} {isFieldRuntime(`artifacts.${artifactPath}.spec.imagePath`, template) && ( <FormInput.MultiTextInput label={getString('pipeline.imagePathLabel')} disabled={isFieldDisabled(`artifacts.${artifactPath}.spec.imagePath`)} multiTextInputProps={{ expressions, allowableTypes }} name={`${path}.artifacts.${artifactPath}.spec.imagePath`} onChange={() => resetTags(formik, `${path}.artifacts.${artifactPath}.spec.tag`)} /> )} {isFieldRuntime(`artifacts.${artifactPath}.spec.registryHostname`, template) && ( <ExperimentalInput formik={formik} disabled={isFieldDisabled(`artifacts.${artifactPath}.spec.registryHostname`)} selectItems={gcrUrlList} useValue multiTypeInputProps={{ onChange: () => resetTags(formik, `${path}.artifacts.${artifactPath}.spec.tag`), expressions, allowableTypes, selectProps: { allowCreatingNewItems: true, addClearBtn: true, items: gcrUrlList } }} label={getString('connectors.GCR.registryHostname')} name={`${path}.artifacts.${artifactPath}.spec.registryHostname`} /> )} {!!fromTrigger && isFieldRuntime(`artifacts.${artifactPath}.spec.tag`, template) && ( <FormInput.MultiTextInput label={getString('tagLabel')} multiTextInputProps={{ expressions, value: TriggerDefaultFieldList.build, allowableTypes }} disabled={true} name={`${path}.artifacts.${artifactPath}.spec.tag`} /> )} {!fromTrigger && isFieldRuntime(`artifacts.${artifactPath}.spec.tag`, template) && ( <ArtifactTagRuntimeField {...props} isFieldDisabled={() => isFieldDisabled(`artifacts.${artifactPath}.spec.tag`, true)} fetchingTags={fetchingTags} buildDetailsList={gcrTagsData?.data?.buildDetailsList} fetchTagsError={fetchTagsError} fetchTags={fetchTags} expressions={expressions} stageIdentifier={stageIdentifier} /> )} {isFieldRuntime(`artifacts.${artifactPath}.spec.tagRegex`, template) && ( <FormInput.MultiTextInput disabled={isFieldDisabled(`artifacts.${artifactPath}.spec.tagRegex`)} multiTextInputProps={{ expressions, allowableTypes }} label={getString('tagRegex')} name={`${path}.artifacts.${artifactPath}.spec.tagRegex`} /> )} </Layout.Vertical> )} </> ) } export class GCRArtifactSource extends ArtifactSourceBase<ArtifactSourceRenderProps> { protected artifactType = ENABLED_ARTIFACT_TYPES.Gcr protected isSidecar = false isTagsSelectionDisabled(props: ArtifactSourceRenderProps): boolean { const { initialValues, artifactPath, artifact } = props const isImagePathPresent = getImagePath( artifact?.spec?.imagePath, get(initialValues, `artifacts.${artifactPath}.spec.imagePath`, '') ) const isConnectorPresent = getMultiTypeFromValue(artifact?.spec?.connectorRef) !== MultiTypeInputType.RUNTIME ? artifact?.spec?.connectorRef : get(initialValues, `artifacts.${artifactPath}.spec.connectorRef`, '') const isRegistryHostnamePresent = getMultiTypeFromValue(artifact?.spec?.registryHostname) !== MultiTypeInputType.RUNTIME ? artifact?.spec?.registryHostname : get(initialValues, `artifacts.${artifactPath}.spec.registryHostname`, '') return !(isImagePathPresent && isConnectorPresent && isRegistryHostnamePresent) } renderContent(props: ArtifactSourceRenderProps): JSX.Element | null { if (!props.isArtifactsRuntime) { return null } this.isSidecar = defaultTo(props.isSidecar, false) return <Content {...props} isTagsSelectionDisabled={this.isTagsSelectionDisabled.bind(this)} /> } } |