All files / modules/30-secrets/pages/secretDetails/views ViewSecretDetails.tsx

78.43% Statements 40/51
42.06% Branches 53/126
100% Functions 3/3
78.43% Lines 40/51

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              10x 10x 10x                           10x   10x 10x 10x       10x 10x           10x     14x 12x   12x 12x               12x 12x 12x 12x 9x       9x 9x       9x       9x             9x                     9x 9x         9x             9x                                                             12x 2x 2x 2x         2x   2x         12x 1x         1x         12x     12x                                                     10x  
/*
 * 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 { Layout } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import type {
  KerberosConfigDTO,
  SecretResponseWrapper,
  SecretTextSpecDTO,
  SSHConfigDTO,
  SSHKeyPathCredentialDTO,
  SSHKeyReferenceCredentialDTO,
  SSHKeySpecDTO,
  SSHPasswordCredentialDTO,
  TGTKeyTabFilePathSpecDTO,
  ConnectorConnectivityDetails,
  TGTPasswordSpecDTO
} from 'services/cd-ng'
import { getKeyForCredentialType, getStringForType } from '@secrets/utils/SSHAuthUtils'
 
import VerifyConnection from '@secrets/modals/CreateSSHCredModal/views/VerifyConnection'
import ConnectorStats from '@common/components/ConnectorStats/ConnectorStats'
import {
  ActivityDetailsRowInterface,
  RenderDetailsTable
} from '@common/components/RenderDetailsTable/RenderDetailsTable'
import { useStrings } from 'framework/strings'
import css from './ViewSecretDetails.module.scss'
 
interface ViewSecretDetailsProps {
  secret: SecretResponseWrapper
}
 
const ViewSecretDetails: React.FC<ViewSecretDetailsProps> = props => {
  const {
    secret: { secret }
  } = props
  const { getString } = useStrings()
 
  const getSecretDetailsRow = (): ActivityDetailsRowInterface[] => {
    return [
      { label: getString('name'), value: secret.name },
      { label: getString('description'), value: secret.description },
      { label: getString('identifier'), value: secret.identifier },
      { label: getString('tagsLabel'), value: secret.tags }
    ]
  }
 
  const getSecretCredentialsRow = (): ActivityDetailsRowInterface[] => {
    const items: ActivityDetailsRowInterface[] = []
    items.push({ label: getString('secrets.labelType'), value: getStringForType(secret.type) })
    if (secret.type === 'SSHKey' && (secret.spec as SSHKeySpecDTO)?.auth?.type) {
      items.push({
        label: getString('authentication'),
        value: (secret.spec as SSHKeySpecDTO)?.auth.type
      })
      Eif ((secret.spec as SSHKeySpecDTO)?.auth.type === 'SSH') {
        items.push({
          label: getString('credType'),
          value: getKeyForCredentialType((secret.spec as SSHKeySpecDTO)?.auth.spec.credentialType)
        })
        items.push({
          label: getString('username'),
          value: (((secret.spec as SSHKeySpecDTO)?.auth.spec as SSHConfigDTO).spec as SSHPasswordCredentialDTO).userName
        })
        Iif (((secret.spec as SSHKeySpecDTO)?.auth.spec as SSHConfigDTO).credentialType === 'Password') {
          items.push({
            label: getString('username'),
            value: (((secret.spec as SSHKeySpecDTO)?.auth.spec as SSHConfigDTO).spec as SSHPasswordCredentialDTO)
              .userName
          })
        }
        Iif (((secret.spec as SSHKeySpecDTO)?.auth.spec as SSHConfigDTO).credentialType === 'KeyPath') {
          items.push({
            label: getString('secrets.sshAuthFormFields.labelKeyFilePath'),
            value: (((secret.spec as SSHKeySpecDTO)?.auth.spec as SSHConfigDTO).spec as SSHKeyPathCredentialDTO).keyPath
          })
          items.push({
            label: getString('secrets.sshAuthFormFields.labelPassphrase'),
            value: (((secret.spec as SSHKeySpecDTO)?.auth.spec as SSHConfigDTO).spec as SSHKeyPathCredentialDTO)
              .encryptedPassphrase
          })
        }
        Eif (((secret.spec as SSHKeySpecDTO)?.auth.spec as SSHConfigDTO).credentialType === 'KeyReference') {
          items.push({
            label: getString('secrets.sshAuthFormFields.labelKeyReference'),
            value: (((secret.spec as SSHKeySpecDTO)?.auth.spec as SSHConfigDTO).spec as SSHKeyReferenceCredentialDTO)
              .key
          })
          items.push({
            label: getString('secrets.sshAuthFormFields.labelPassphrase'),
            value: (((secret.spec as SSHKeySpecDTO)?.auth.spec as SSHConfigDTO).spec as SSHKeyReferenceCredentialDTO)
              .encryptedPassphrase
          })
        }
      }
      Iif ((secret.spec as SSHKeySpecDTO)?.auth.type === 'Kerberos') {
        items.push({
          label: getString('secrets.sshAuthFormFields.labelPrincipal'),
          value: ((secret.spec as SSHKeySpecDTO)?.auth.spec as KerberosConfigDTO).principal
        })
        items.push({
          label: getString('secrets.sshAuthFormFields.labelRealm'),
          value: ((secret.spec as SSHKeySpecDTO)?.auth.spec as KerberosConfigDTO).realm
        })
        items.push({
          label: getString('secrets.sshAuthFormFields.labelTGT'),
          value:
            ((secret.spec as SSHKeySpecDTO)?.auth.spec as KerberosConfigDTO).tgtGenerationMethod || getString('none')
        })
        if (((secret.spec as SSHKeySpecDTO)?.auth.spec as KerberosConfigDTO).tgtGenerationMethod === 'KeyTabFilePath') {
          items.push({
            label: getString('secrets.sshAuthFormFields.labelKeyTab'),
            value: (((secret.spec as SSHKeySpecDTO)?.auth.spec as KerberosConfigDTO)?.spec as TGTKeyTabFilePathSpecDTO)
              ?.keyPath
          })
        }
        if (((secret.spec as SSHKeySpecDTO)?.auth.spec as KerberosConfigDTO).tgtGenerationMethod === 'Password') {
          items.push({
            label: getString('password'),
            value: (((secret.spec as SSHKeySpecDTO)?.auth.spec as KerberosConfigDTO).spec as TGTPasswordSpecDTO)
              .password
          })
        }
      }
    }
 
    if (secret.type === 'SecretText') {
      const secretTextSpec = secret.spec as SecretTextSpecDTO
      Eif (secretTextSpec.valueType == 'Inline')
        items.push({
          label: getString('secrets.labelValue'),
          value: getString('encrypted').toLowerCase(),
          valueColor: Color.GREY_350
        })
      Iif (secretTextSpec.valueType == 'Reference')
        items.push({ label: getString('secrets.labelPath'), value: secretTextSpec.value })
      items.push({
        label: getString('secrets.labelSecretsManager'),
        value: (secret.spec as SecretTextSpecDTO).secretManagerIdentifier
      })
    }
    if (secret.type === 'SecretFile') {
      items.push({
        label: getString('secrets.labelValue'),
        value: getString('encryptedFile').toLowerCase(),
        valueColor: Color.GREY_350
      })
      items.push({
        label: getString('secrets.labelSecretsManager'),
        value: (secret.spec as SecretTextSpecDTO).secretManagerIdentifier
      })
    }
    return items
  }
 
  return (
    <Layout.Horizontal>
      <Layout.Vertical width="60%" spacing="large">
        <Layout.Horizontal spacing="medium">
          <RenderDetailsTable
            title={getString('overview')}
            data={getSecretDetailsRow()}
            className={css.renderDetails}
          />
          <RenderDetailsTable title={'Credentials'} data={getSecretCredentialsRow()} className={css.renderDetails} />
        </Layout.Horizontal>
      </Layout.Vertical>
      {secret.type === 'SSHKey' ? (
        <Layout.Vertical width="40%" spacing="xxxlarge" border={{ left: true }} padding={{ left: 'xxxlarge' }}>
          <ConnectorStats
            createdAt={props.secret.createdAt as number}
            lastUpdated={props.secret.updatedAt}
            status={'' as ConnectorConnectivityDetails['status']}
            className={css.stats}
          />
          <VerifyConnection identifier={secret.identifier} />
        </Layout.Vertical>
      ) : null}
    </Layout.Horizontal>
  )
}
 
export default ViewSecretDetails