All files / modules/10-common/utils SnippetUtils.tsx

66.67% Statements 16/24
40% Branches 6/15
100% Functions 2/2
63.64% Lines 14/22

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                      501x 74x   40x   8x   16x   8x   2x           501x                                                                                   501x       9x 9x               9x 9x                 9x    
/*
 * 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 type { IconName } from '@wings-software/uicore'
import type { Module } from '@common/interfaces/RouteInterfaces'
import type { GetYamlSnippetMetadataQueryParams, GetYamlSchemaQueryParams, ConnectorInfoDTO } from 'services/cd-ng'
 
export const getIconNameForTag = (tag: string): IconName => {
  switch (tag) {
    case 'k8s':
      return 'app-kubernetes'
    case 'docker':
      return 'service-dockerhub'
    case 'git':
      return 'service-github'
    case 'secretmanager':
      return 'lock'
    default:
      return 'main-code-yaml'
  }
}
 
const entitySubTypeToTagMap: {
  [key in ConnectorInfoDTO['type']]: GetYamlSnippetMetadataQueryParams['tags'][number]
} = {
  K8sCluster: 'k8s',
  Git: 'git',
  Splunk: 'splunk',
  AppDynamics: 'appdynamics',
  Vault: 'vault',
  AzureKeyVault: 'azurekeyvault',
  DockerRegistry: 'docker',
  Local: 'local',
  GcpKms: 'gcpkms',
  Gcp: 'gcp',
  Aws: 'aws',
  AwsKms: 'awskms',
  Artifactory: 'artifactory',
  Jira: 'jira',
  // eslint-disable-next-line
  // @ts-ignore
  ServiceNow: 'servicenow',
  Nexus: 'nexus',
  Github: 'github',
  Gitlab: 'gitlab',
  Bitbucket: 'bitbucket',
  CEAws: 'ceaws',
  CEAzure: 'ceazure',
  CEK8sCluster: 'cek8s',
  Codecommit: 'codecommit',
  HttpHelmRepo: 'httphelmrepo',
  NewRelic: 'newrelic',
  GcpCloudCost: 'gcpcloudcost',
  Prometheus: 'prometheus',
  Datadog: 'datadog',
  SumoLogic: 'sumologic',
  Dynatrace: 'dynatrace',
  AwsSecretManager: 'awssecretmanager',
  PagerDuty: 'pagerduty',
  CustomHealth: 'customhealth',
  ErrorTracking: 'errortracking',
  Pdc: 'pdc',
  Azure: 'azure',
  AzureRepo: 'azurerepo'
}
 
export const getSnippetTags = (
  entityType: GetYamlSchemaQueryParams['entityType'],
  entitySubType?: ConnectorInfoDTO['type'] | Module
): GetYamlSnippetMetadataQueryParams['tags'] => {
  const tags: GetYamlSnippetMetadataQueryParams['tags'] = []
  switch (entityType) {
    case 'Connectors': {
      tags.push('connector')
      const entitySubTypeTag = entitySubType && entitySubTypeToTagMap[entitySubType as ConnectorInfoDTO['type']]
      entitySubTypeTag && tags.push(entitySubTypeTag)
      break
    }
    case 'Secrets':
      tags.push('secret')
      break
    case 'Pipelines':
      tags.push('pipeline')
      if (entitySubType === 'ci') {
        tags.splice(0, 1)
      }
      break
    default:
  }
  return tags
}