All files / modules/35-connectors/pages/connectors/utils ConnectorHelper.tsx

80.56% Statements 87/108
75.29% Branches 64/85
75% Functions 6/8
79.21% Lines 80/101

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                  283x 283x     283x               283x           283x         283x               283x                                       283x 265x   8x               6x   251x       283x 88x   7x   3x   9x   9x   7x   7x   3x   3x               7x   1x   4x   1x   4x   2x   2x   4x   4x   2x   1x   2x   5x           1x               283x 389x     19x   9x   3x   9x   7x   7x   3x   3x       32x   32x   32x   35x   32x     7x   4x   1x   4x   4x   2x   2x       8x   1x   5x   32x   1x       1x   2x   28x           32x   32x           283x 283x 283x 283x     283x 3x       3x       283x       283x 8x   6x               2x      
/*
 * Copyright 2022 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 type { IconName } from '@wings-software/uicore'
import type { IconProps } from '@wings-software/uicore/dist/icons/Icon'
import { Connectors } from '@connectors/constants'
import { StringUtils } from '@common/exports'
import type { StringKeys } from 'framework/strings'
 
export const AuthTypes = {
  CLIENT_KEY_CERT: 'ClientKeyCert',
  USER_PASSWORD: 'UsernamePassword',
  SERVICE_ACCOUNT: 'ServiceAccount',
  OIDC: 'OpenIdConnect',
  ANNONYMOUS: 'Anonymous'
}
 
export const GitAuthTypes = {
  USER_PASSWORD: 'UsernamePassword',
  USER_TOKEN: 'UsernameToken',
  KERBEROS: 'Kerberos'
}
 
export const GitAPIAuthTypes = {
  GITHUB_APP: 'GithubApp',
  TOKEN: 'Token'
}
 
export const dockerProviderTypes = {
  CLIENT_KEY_CERT: 'ClientKeyCert',
  USER_PASSWORD: 'UsernamePassword',
  SERVICE_ACCOUNT: 'ServiceAccount',
  OIDC: 'OpenIdConnect',
  ANNONYMOUS: 'Anonymous'
}
 
export const getKubInitialValues = () => {
  return {
    type: 'KUBERNETES_CLUSTER',
    name: 'NAME',
    description: '',
    identifier: '',
    tags: {},
    delegateMode: '',
    credentialType: '',
    credential: {
      masterUrl: '',
      manualCredentialType: '',
      manualCredentials: {
        userName: '',
        encryptedPassword: ''
      }
    }
  }
}
 
export const getHeadingIdByType = (type: string): StringKeys => {
  switch (type) {
    case Connectors.VAULT:
      return 'connectors.hashicorpVaultDetails'
    case Connectors.LOCAL:
      return 'connectors.secretManagerDetails'
    case Connectors.APP_DYNAMICS:
      return 'connectors.appDynamicsDetails'
    case Connectors.SPLUNK:
      return 'connectors.splunkConnectorDetails'
    case 'Gcr':
      return 'connectors.gcrConnectorDetails'
    default:
      return 'overview'
  }
}
 
export const getConnectorTitleIdByType = (type: string): StringKeys => {
  switch (type) {
    case Connectors.KUBERNETES_CLUSTER:
      return 'connectors.title.k8sCluster'
    case Connectors.HttpHelmRepo:
      return 'connectors.title.helmConnector'
    case Connectors.GIT:
      return 'connectors.title.gitConnector'
    case Connectors.GITHUB:
      return 'connectors.title.githubConnector'
    case Connectors.GITLAB:
      return 'connectors.title.gitlabConnector'
    case Connectors.BITBUCKET:
      return 'connectors.title.bitbucketConnector'
    case Connectors.VAULT:
      return 'connectors.title.hashicorpVault'
    case Connectors.GCP_KMS:
      return 'connectors.title.gcpKms'
    case Connectors.LOCAL:
      return 'connectors.title.secretManager'
    case Connectors.APP_DYNAMICS:
      return 'connectors.title.appdynamics'
    case Connectors.SPLUNK:
      return 'connectors.title.splunk'
    case Connectors.DOCKER:
      return 'dockerRegistry'
    case Connectors.CEAWS:
      return 'connectors.title.ceAws'
    case Connectors.AWS:
      return 'connectors.title.aws'
    case Connectors.AWS_CODECOMMIT:
      return 'connectors.title.awsCodeCommit'
    case Connectors.NEXUS:
      return 'connectors.title.nexus'
    case Connectors.Jira:
      return 'connectors.title.jira'
    case Connectors.SERVICE_NOW:
      return 'connectors.title.serviceNow'
    case Connectors.ARTIFACTORY:
      return 'connectors.title.artifactory'
    case Connectors.GCP:
      return 'connectors.title.gcpConnector'
    case 'Gcr':
      return 'connectors.GCR.fullName'
    case Connectors.AWS_KMS:
      return 'connectors.title.awsKms'
    case Connectors.AWS_SECRET_MANAGER:
      return 'connectors.title.awsSecretManager'
    case Connectors.CE_AZURE:
      return 'connectors.title.ceAzureConnector'
    case Connectors.DATADOG:
      return 'connectors.title.datadog'
    case Connectors.SUMOLOGIC:
      return 'connectors.title.sumologic'
    case Connectors.AZURE_KEY_VAULT:
      return 'connectors.title.azureKeyVault'
    case Connectors.ERROR_TRACKING:
      return 'connectors.title.errorTracking'
    default:
      return 'connector'
  }
}
 
export const getConnectorIconByType = (type: string): IconName => {
  switch (type) {
    case Connectors.KUBERNETES_CLUSTER:
    case Connectors.CE_KUBERNETES:
      return 'app-kubernetes'
    case Connectors.GIT:
      return 'service-github'
    case Connectors.HttpHelmRepo:
      return 'service-helm'
    case Connectors.GITHUB:
      return 'github'
    case Connectors.GITLAB:
      return 'service-gotlab'
    case Connectors.BITBUCKET:
      return 'bitbucket-selected'
    case Connectors.VAULT:
      return 'hashiCorpVault'
    case Connectors.GCP_KMS:
      return 'gcp-kms'
    case Connectors.LOCAL:
      return 'lock'
    case Connectors.APP_DYNAMICS:
      return 'service-appdynamics'
    case Connectors.SPLUNK:
      return 'service-splunk'
    case Connectors.NEW_RELIC:
      return 'service-newrelic'
    case Connectors.PROMETHEUS:
      return 'service-prometheus'
    case Connectors.DYNATRACE:
      return 'service-dynatrace'
    case Connectors.DOCKER:
    case 'Dockerhub':
      return 'service-dockerhub'
    case Connectors.AWS:
      return 'service-aws'
    case Connectors.AWS_CODECOMMIT:
      return 'aws-codecommit'
    case Connectors.NEXUS:
      return 'service-nexus'
    case Connectors.ARTIFACTORY:
      return 'service-artifactory'
    case Connectors.Jira:
      return 'service-jira'
    case Connectors.SERVICE_NOW:
      return 'service-servicenow'
    case Connectors.GCP:
    case Connectors.CE_GCP:
    case 'Gcr':
      return 'service-gcp'
    case Connectors.AWS_KMS:
      return 'aws-kms'
    case Connectors.CE_AZURE:
      return 'service-azure'
    case Connectors.DATADOG:
      return 'service-datadog'
    case Connectors.AZURE_KEY_VAULT:
      return 'azure-key-vault'
    case Connectors.SUMOLOGIC:
      return 'service-sumologic'
    case Connectors.CEAWS:
      return 'service-aws'
    case Connectors.AWS_SECRET_MANAGER:
      return 'aws-secret-manager'
    case Connectors.PAGER_DUTY:
      return 'service-pagerduty'
    case Connectors.ARGO:
      return 'argo'
    case Connectors.HARNESS_MANAGED_GITOPS:
      return 'harness'
    case Connectors.CUSTOM_HEALTH:
      return 'service-custom-connector'
    case Connectors.ERROR_TRACKING:
      return 'error-tracking'
    default:
      return 'placeholder'
  }
}
 
export enum ConnectorDetailsView {
  'overview' = 'overview',
  'referencedBy' = 'referencedBy',
  'activityHistory' = 'activityHistory'
}
 
export const getConnectorIconPropsByType = (type: string): Omit<IconProps, 'name'> => {
  switch (type) {
    case Connectors.CUSTOM_HEALTH:
      return { size: 37, background: 'white' }
    default:
      return { size: 37 }
  }
}
 
export const generateDefaultSecretConfig = (name: string, type: string) => {
  return StringUtils.getIdentifierFromName(name || '').concat(type)
}
 
export const getLabelForAuthType = (type: string) => {
  switch (type) {
    case AuthTypes.USER_PASSWORD:
      return 'Username and Password'
    case AuthTypes.SERVICE_ACCOUNT:
      return 'Service Account Token'
    case AuthTypes.OIDC:
      return 'OIDC Token'
    case AuthTypes.CLIENT_KEY_CERT:
      return 'Client Key Certificate'
    default:
      return ''
  }
}