All files / modules/30-secrets/components/SSHAuthFormFields SSHAuthFormFields.tsx

92.31% Statements 12/13
35.71% Branches 5/14
50% Functions 1/2
92.31% Lines 12/13

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              233x 233x     233x 233x                 233x 15x 14x 14x                             14x                     14x                             14x                                                                                                                                                 233x  
/*
 * 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 from 'react'
import { FormInput, Layout, Text, SelectOption, DropDown } from '@wings-software/uicore'
import type { IOptionProps } from '@blueprintjs/core'
import type { FormikProps } from 'formik'
import { useStrings } from 'framework/strings'
import SecretInput from '@secrets/components/SecretInput/SecretInput'
import type { SSHConfigFormData } from '@secrets/modals/CreateSSHCredModal/views/StepAuthentication'
 
interface SSHAuthFormFieldsProps {
  formik: FormikProps<SSHConfigFormData>
  secretName?: string
  editing?: boolean
}
 
const SSHAuthFormFields: React.FC<SSHAuthFormFieldsProps> = props => {
  const { getString } = useStrings()
  const { formik } = props
  const credentialTypeOptions: SelectOption[] = [
    {
      label: getString('secrets.sshAuthFormFields.optionKey'),
      value: 'KeyReference'
    },
    {
      label: getString('secrets.sshAuthFormFields.optionKeypath'),
      value: 'KeyPath'
    },
    {
      label: getString('secrets.sshAuthFormFields.optionPassword'),
      value: 'Password'
    }
  ]
 
  const authSchemeOptions: IOptionProps[] = [
    {
      label: getString('SSH_KEY'),
      value: 'SSH'
    },
    {
      label: getString('kerberos'),
      value: 'Kerberos'
    }
  ]
 
  const tgtGenerationMethodOptions: IOptionProps[] = [
    {
      label: getString('secrets.sshAuthFormFields.labelKeyTab'),
      value: 'KeyTabFilePath'
    },
    {
      label: getString('password'),
      value: 'Password'
    },
    {
      label: getString('secrets.sshAuthFormFields.optionKerbNone'),
      value: 'None'
    }
  ]
 
  return (
    <>
      <FormInput.RadioGroup
        name="authScheme"
        label={getString('secrets.sshAuthFormFields.labelType')}
        items={authSchemeOptions}
        radioGroup={{ inline: true }}
      />
      {formik.values.authScheme === 'SSH' ? (
        <>
          <Layout.Horizontal margin={{ bottom: 'medium' }} flex>
            <Text icon="lock" style={{ flex: 1 }}>
              {getString('authentication')}
            </Text>
            <DropDown
              items={credentialTypeOptions}
              value={formik.values.credentialType}
              isLabel={true}
              filterable={false}
              minWidth="unset"
              onChange={item => {
                formik.setFieldValue('credentialType', item.value)
              }}
            />
          </Layout.Horizontal>
          <FormInput.Text name="userName" label={getString('username')} />
          {formik.values.credentialType === 'KeyReference' ? (
            <>
              <SecretInput name="key" label={getString('secrets.sshAuthFormFields.labelFile')} type="SecretFile" />
              <SecretInput
                name={'encryptedPassphrase'}
                label={getString('secrets.sshAuthFormFields.labelPassphrase')}
              />
            </>
          ) : null}
          {formik.values.credentialType === 'KeyPath' ? (
            <>
              <FormInput.Text name="keyPath" label={getString('secrets.sshAuthFormFields.labelKeyFilePath')} />
              <SecretInput
                name={'encryptedPassphrase'}
                label={getString('secrets.sshAuthFormFields.labelPassphrase')}
              />
            </>
          ) : null}
          {formik.values.credentialType === 'Password' ? (
            <SecretInput name={'password'} label={getString('password')} />
          ) : null}
          <FormInput.Text name="port" label={getString('secrets.sshAuthFormFields.labelSSHPort')} />
        </>
      ) : null}
      {formik.values.authScheme === 'Kerberos' ? (
        <>
          <FormInput.Text name="principal" label={getString('secrets.sshAuthFormFields.labelPrincipal')} />
          <FormInput.Text name="realm" label={getString('secrets.sshAuthFormFields.labelRealm')} />
          <FormInput.Text name="port" label={getString('secrets.sshAuthFormFields.labelSSHPort')} />
          <FormInput.RadioGroup
            name="tgtGenerationMethod"
            label={getString('secrets.sshAuthFormFields.labelTGT')}
            items={tgtGenerationMethodOptions}
            radioGroup={{ inline: true }}
          />
          {formik.values.tgtGenerationMethod === 'KeyTabFilePath' ? (
            <FormInput.Text name="keyPath" label={getString('secrets.sshAuthFormFields.labelKeyTab')} />
          ) : null}
          {formik.values.tgtGenerationMethod === 'Password' ? (
            <SecretInput name={'password'} label={getString('password')} />
          ) : null}
        </>
      ) : null}
    </>
  )
}
 
export default SSHAuthFormFields