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 | 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 219x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 5x 1x 1x 5x 1x 1x 1x 1x 1x 1x 1x 1x 5x 1x 219x | /* * 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, { useContext, useState } from 'react' import { Button, Heading, Icon, Layout, ModalErrorHandler, ModalErrorHandlerBinding, StepProps, Text } from '@wings-software/uicore' import { useParams } from 'react-router-dom' import { Color } from '@harness/design-system' import { omit as _omit, defaultTo as _defaultTo } from 'lodash-es' import type { AccountPathProps } from '@common/interfaces/RouteInterfaces' import { ConnectorInfoDTO, ConnectorRequestBody, useCreateConnector, useUpdateConnector } from 'services/cd-ng' import { downloadYamlAsFile } from '@common/utils/downloadYamlUtils' import { DialogExtensionContext } from '@connectors/common/ConnectorExtention/DialogExtention' import { Connectors } from '@connectors/constants' import { useStrings } from 'framework/strings' import { useCloudCostK8sClusterSetup } from 'services/ce' import { useTelemetry } from '@common/hooks/useTelemetry' import { CE_K8S_CONNECTOR_CREATION_EVENTS } from '@connectors/trackingConstants' import { useStepLoadTelemetry } from '@connectors/common/useTrackStepLoad/useStepLoadTelemetry' import { useMutateAsGet } from '@common/hooks' import useRBACError from '@rbac/utils/useRBACError/useRBACError' import CopyCodeSection from './components/CopyCodeSection' import PermissionYAMLPreview from './PermissionYAMLPreview' import css from './CEK8sConnector.module.scss' interface ProvidePermissionsProps { name: string onSuccess?: (connector: ConnectorRequestBody) => void isEditMode: boolean } interface StepSecretManagerProps extends ConnectorInfoDTO { spec: any } const yamlFileName = 'ccm-kubernetes.yaml' const ProvidePermissions: React.FC<StepProps<StepSecretManagerProps> & ProvidePermissionsProps> = props => { const { getString } = useStrings() const { getRBACErrorMessage } = useRBACError() const { accountId } = useParams<AccountPathProps>() const [isDownloadComplete, setIsDownloadComplete] = useState<boolean>(false) const [isDelegateDone, setIsDelegateDone] = useState<boolean>(false) const [command] = useState(`kubectl apply -f ${yamlFileName}`) const [isSaving, setIsSaving] = useState<boolean>(false) const [modalErrorHandler, setModalErrorHandler] = useState<ModalErrorHandlerBinding | undefined>() const { triggerExtension } = useContext(DialogExtensionContext) const { trackEvent } = useTelemetry() useStepLoadTelemetry(CE_K8S_CONNECTOR_CREATION_EVENTS.LOAD_PROVIDE_PERMISSIONS) const { mutate: createConnector } = useCreateConnector({ queryParams: { accountIdentifier: accountId } }) const { mutate: updateConnector } = useUpdateConnector({ queryParams: { accountIdentifier: accountId } }) const { data: permissionsYaml } = useMutateAsGet(useCloudCostK8sClusterSetup, { queryParams: { accountIdentifier: accountId }, body: { connectorIdentifier: _defaultTo(props.prevStepData?.spec?.connectorRef, ''), featuresEnabled: props.prevStepData?.spec?.featuresEnabled, ccmConnectorIdentifier: _defaultTo(props.prevStepData?.identifier, '') } }) const handleDownload = async () => { trackEvent(CE_K8S_CONNECTOR_CREATION_EVENTS.DOWNLOAD_YAML, {}) const { status } = await downloadYamlAsFile(permissionsYaml, yamlFileName) status && setIsDownloadComplete(true) } const handleDoneClick = () => { trackEvent(CE_K8S_CONNECTOR_CREATION_EVENTS.APPLY_COMMAND_DONE, {}) setIsDelegateDone(true) } const saveAndContinue = async (): Promise<void> => { setIsSaving(true) try { modalErrorHandler?.hide() const connector: ConnectorRequestBody = { connector: { ...props.prevStepData, spec: _omit({ ...props.prevStepData?.spec }, 'fixFeatureSelection'), type: Connectors.CE_KUBERNETES } as ConnectorInfoDTO } const response = props.isEditMode ? await updateConnector(connector) : await createConnector(connector) props.onSuccess?.(response?.data as ConnectorRequestBody) props.nextStep?.({ ...props.prevStepData } as ConnectorInfoDTO) } catch (e) { modalErrorHandler?.showDanger(getRBACErrorMessage(e)) } finally { setIsSaving(false) } } return ( <Layout.Vertical spacing={'xlarge'} className={css.providePermissionContainer}> <Heading level={2} className={css.heading}> {getString('connectors.ceK8.providePermissionsStep.heading')} </Heading> <ModalErrorHandler bind={setModalErrorHandler} /> <Text icon={'info'} iconProps={{ color: Color.PRIMARY_7 }} color={Color.PRIMARY_7}> {getString('connectors.ceK8.providePermissionsStep.info')} <a href="https://ngdocs.harness.io/article/ltt65r6k39-set-up-cost-visibility-for-kubernetes#prerequisites" target="_blank" rel="noreferrer" > {getString('connectors.readMore')} </a> </Text> <Text> {getString('connectors.ceK8.providePermissionsStep.downloadYamlText')} <span className={css.previewLink} onClick={() => triggerExtension(<PermissionYAMLPreview yamlContent={permissionsYaml as unknown as string} />)} > here </span> . </Text> <div> <Text>{getString('connectors.ceK8.providePermissionsStep.fileDescription.heading')}</Text> <ul> <li>{getString('connectors.ceK8.providePermissionsStep.fileDescription.info1')}</li> <li>{getString('connectors.ceK8.providePermissionsStep.fileDescription.info2')}</li> <li>{getString('connectors.ceK8.providePermissionsStep.fileDescription.info3')}</li> <li>{getString('connectors.ceK8.providePermissionsStep.fileDescription.info4')}</li> </ul> {!isDownloadComplete && ( <Button intent={'primary'} outlined={true} onClick={handleDownload} text={getString('connectors.ceK8.providePermissionsStep.downloadYamlBtnText')} className={css.stepBtn} /> )} {isDownloadComplete && ( <Layout.Horizontal className={css.successTextContainer}> <Icon name="tick" /> <span>{getString('connectors.ceK8.providePermissionsStep.downloadComplete')}</span> </Layout.Horizontal> )} {isDownloadComplete && ( <div className={css.commandSection}> <Text>{getString('connectors.ceK8.providePermissionsStep.applyDelegateText')}</Text> <CopyCodeSection snippet={`${command}`} /> {!isDelegateDone && ( <Button intent={'primary'} outlined={true} onClick={handleDoneClick} text={getString('done')} className={css.stepBtn} /> )} {isDelegateDone && ( <Layout.Horizontal className={css.successTextContainer}> <Icon name="tick" /> <span>{getString('connectors.ceK8.providePermissionsStep.successfulCommandExec')}</span> </Layout.Horizontal> )} </div> )} </div> <Button intent="primary" text={getString('continue')} rightIcon="chevron-right" loading={isSaving} disabled={isSaving || !(isDownloadComplete && isDelegateDone)} onClick={() => saveAndContinue()} className={css.submitBtn} /> </Layout.Vertical> ) } export default ProvidePermissions |