All files / modules/35-connectors/components/CreateConnector/CEK8sConnector SecretCreationStep.tsx

95.24% Statements 20/21
37.5% Branches 3/8
66.67% Functions 2/3
95.24% Lines 20/21

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              219x 219x 219x 219x   219x   219x 219x 219x 219x                   219x 1x   1x 1x   1x   1x                             1x       1x 1x     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, { useState } from 'react'
import { useParams } from 'react-router-dom'
import { Button, Heading, Layout, StepProps } from '@wings-software/uicore'
import { yamlStringify } from '@common/utils/YamlHelperMethods'
import type { AccountPathProps } from '@common/interfaces/RouteInterfaces'
import { useStrings } from 'framework/strings'
import type { ConnectorInfoDTO } from 'services/cd-ng'
import { CE_K8S_CONNECTOR_CREATION_EVENTS } from '@connectors/trackingConstants'
import { useStepLoadTelemetry } from '@connectors/common/useTrackStepLoad/useStepLoadTelemetry'
import CopyCodeSection from './components/CopyCodeSection'
import css from './CEK8sConnector.module.scss'
 
interface SecretCreationStepProps {
  name: string
}
 
interface StepSecretManagerProps extends ConnectorInfoDTO {
  spec: any
}
 
const SecretCreationStep: React.FC<StepProps<StepSecretManagerProps> & SecretCreationStepProps> = props => {
  const { prevStepData, nextStep, previousStep } = props
 
  const { accountId } = useParams<AccountPathProps>()
  const { getString } = useStrings()
 
  useStepLoadTelemetry(CE_K8S_CONNECTOR_CREATION_EVENTS.LOAD_SECRET_CREATION)
 
  const [secretYaml] = useState<string>(
    yamlStringify({
      apiVersion: 'v1',
      data: {
        token: '<paste token here>'
      },
      kind: 'Secret',
      metadata: {
        name: 'harness-api-key',
        namespace: 'harness-autostopping'
      },
      type: 'Opaque'
    })
  )
 
  const handleprev = () => {
    previousStep?.({ ...prevStepData } as ConnectorInfoDTO)
  }
 
  const handleSubmit = () => {
    nextStep?.({ ...prevStepData } as ConnectorInfoDTO)
  }
 
  return (
    <Layout.Vertical className={css.secretCreationCont}>
      <Heading level={2} className={css.header}>
        {'Secret Creation'}
      </Heading>
      <ol type="1">
        <li>
          {getString('connectors.ceK8.secretCreationStep.step1')}
          <a
            href={`${window.location.origin}/#/account/${accountId}/access-management/api-keys`}
            target="_blank"
            rel="noreferrer"
          >
            here
          </a>
        </li>
        <li>{getString('connectors.ceK8.secretCreationStep.step2')}</li>
        <CopyCodeSection snippet={getString('connectors.ceK8.secretCreationStep.namespaceCommand')} />
        <li>{getString('connectors.ceK8.secretCreationStep.step3')}</li>
        <CopyCodeSection snippet={`${secretYaml}`} />
        <li>{getString('connectors.ceK8.secretCreationStep.step4')}</li>
        <CopyCodeSection snippet={getString('connectors.ceK8.secretCreationStep.creationCommand')} />
      </ol>
      <Layout.Horizontal className={css.buttonPanel} spacing="small">
        <Button text={getString('previous')} icon="chevron-left" onClick={handleprev}></Button>
        <Button
          type="submit"
          intent="primary"
          text={getString('continue')}
          rightIcon="chevron-right"
          onClick={handleSubmit}
        />
      </Layout.Horizontal>
    </Layout.Vertical>
  )
}
 
export default SecretCreationStep