All files / src/api config.ts

9.09% Statements 2/22
0% Branches 0/14
0% Functions 0/4
9.09% Lines 2/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 97 98 99 100 101 102 103 104 105                                      1x                                                                     1x                                                                                                    
import * as vscode from 'vscode'
 
interface EnvConfig {
  authUrl: string
  loginUrl: string
  appStoreApiUrl: string
  backendBaseUrl: string
  dynasApiUrl: string
  dpyesApiUrl: string
  dpyesSchedulerApiUrl: string
  anksyApiUrl: string
  appStoreSpecUrl: string
  dynasSpecUrl: string
  dpyesSpecUrl: string
  dpyesSchedulerSpecUrl: string
  anksySpecUrl: string
  templateServiceAccount: { username: string; password: string }
}
 
const ENV_CONFIGS: Record<string, EnvConfig> = {
  prod: {
    authUrl: 'https://boltzhub.com',
    loginUrl: 'https://boltzhub.com/authentication-service/login',
    appStoreApiUrl: 'https://boltzhub.com/bz-appstore-api',
    backendBaseUrl: 'https://flow.boltzbit.com/bz-api',
    dynasApiUrl: 'https://flow.boltzbit.com/bz-dynas/api',
    dpyesApiUrl: 'https://flow.boltzbit.com/bz-dpyes/api',
    dpyesSchedulerApiUrl: 'https://flow.boltzbit.com/bz-dpyes-scheduler/api',
    anksyApiUrl: 'https://boltzhub.com/bz-anksy',
    appStoreSpecUrl: 'https://boltzhub.com/bz-appstore-api/swagger/doc.json',
    dynasSpecUrl: 'https://flow.boltzbit.com/bz-dynas/openapi.json',
    dpyesSpecUrl: 'https://flow.boltzbit.com/bz-dpyes/openapi.json',
    dpyesSchedulerSpecUrl: 'https://flow.boltzbit.com/bz-dpyes-scheduler/openapi.json',
    anksySpecUrl: 'https://boltzhub.com/bz-anksy/openapi.json',
    templateServiceAccount: { username: 'boltzbit', password: 'officialboltzbit' },
  },
  test: {
    authUrl: 'https://test.boltzhub.com',
    loginUrl: 'https://test.boltzhub.com/authentication-service/login',
    appStoreApiUrl: 'https://test.boltzhub.com/bz-appstore-api',
    backendBaseUrl: 'https://ocr.boltztest.com/bz-api',
    dynasApiUrl: 'https://ocr.boltztest.com/bz-dynas/api',
    dpyesApiUrl: 'https://ocr.boltztest.com/bz-dpyes/api',
    dpyesSchedulerApiUrl: 'https://ocr.boltztest.com/bz-dpyes-scheduler/api',
    anksyApiUrl: 'https://test.boltzhub.com/bz-anksy',
    appStoreSpecUrl: 'https://test.boltzhub.com/bz-appstore-api/swagger/doc.json',
    dynasSpecUrl: 'https://ocr.boltztest.com/bz-dynas/openapi.json',
    dpyesSpecUrl: 'https://ocr.boltztest.com/bz-dpyes/openapi.json',
    dpyesSchedulerSpecUrl: 'https://ocr.boltztest.com/bz-dpyes-scheduler/openapi.json',
    anksySpecUrl: 'https://test.boltzhub.com/bz-anksy/openapi.json',
    templateServiceAccount: { username: 'test-user', password: 'test-password' },
  },
}
 
const TEMPLATE_APP_IDS: Record<string, string> = {
  test: '837d67ff-a06c-4697-a74d-9a18ee8c57df',
  prod: '700bc320-1bec-4d66-8f74-dbecd4b543fa',
}
 
export function getTemplateAppId(): string {
  const config = vscode.workspace.getConfiguration('bzcode')
  const env = config.get<string>('environment', 'prod')
  return TEMPLATE_APP_IDS[env] ?? TEMPLATE_APP_IDS.prod
}
 
export function getEnvConfig(): EnvConfig {
  const config = vscode.workspace.getConfiguration('bzcode')
  const env = config.get<string>('environment', 'prod')
  return ENV_CONFIGS[env] ?? ENV_CONFIGS.prod
}
 
export type ServiceName = 'appstore' | 'dynas' | 'dpyes' | 'dpyes-scheduler' | 'anksy'
 
export function getServiceBaseUrl(service: ServiceName): string {
  const config = getEnvConfig()
  switch (service) {
    case 'appstore':
      return config.appStoreApiUrl
    case 'dynas':
      return config.dynasApiUrl
    case 'dpyes':
      return config.dpyesApiUrl
    case 'dpyes-scheduler':
      return config.dpyesSchedulerApiUrl
    case 'anksy':
      return config.anksyApiUrl
  }
}
 
export function getSpecUrl(service: ServiceName): string {
  const config = getEnvConfig()
  switch (service) {
    case 'appstore':
      return config.appStoreSpecUrl
    case 'dynas':
      return config.dynasSpecUrl
    case 'dpyes':
      return config.dpyesSpecUrl
    case 'dpyes-scheduler':
      return config.dpyesSchedulerSpecUrl
    case 'anksy':
      return config.anksySpecUrl
  }
}