MCPcopy
hub / github.com/cortexlabs/cortex / getAPIsByEnv

Function getAPIsByEnv

cli/cmd/get.go:337–460  ·  view source on GitHub ↗
(env cliconfig.Environment)

Source from the content-addressed store, hash-verified

335}
336
337func getAPIsByEnv(env cliconfig.Environment) (string, error) {
338 apisRes, err := cluster.GetAPIs(MustGetOperatorConfig(env.Name))
339 if err != nil {
340 return "", err
341 }
342
343 var bytes []byte
344 if _flagOutput == flags.JSONOutputType {
345 bytes, err = libjson.Marshal(apisRes)
346 } else if _flagOutput == flags.YAMLOutputType {
347 bytes, err = yaml.Marshal(apisRes)
348 }
349 if err != nil {
350 return "", err
351 }
352 if _flagOutput == flags.JSONOutputType || _flagOutput == flags.YAMLOutputType {
353 return string(bytes), nil
354 }
355
356 var allRealtimeAPIs []schema.APIResponse
357 var allAsyncAPIs []schema.APIResponse
358 var allBatchAPIs []schema.APIResponse
359 var allTaskAPIs []schema.APIResponse
360 var allTrafficSplitters []schema.APIResponse
361
362 for _, api := range apisRes {
363 switch api.Metadata.Kind {
364 case userconfig.BatchAPIKind:
365 allBatchAPIs = append(allBatchAPIs, api)
366 case userconfig.TaskAPIKind:
367 allTaskAPIs = append(allTaskAPIs, api)
368 case userconfig.RealtimeAPIKind:
369 allRealtimeAPIs = append(allRealtimeAPIs, api)
370 case userconfig.AsyncAPIKind:
371 allAsyncAPIs = append(allAsyncAPIs, api)
372 case userconfig.TrafficSplitterKind:
373 allTrafficSplitters = append(allTrafficSplitters, api)
374 }
375 }
376
377 if len(allRealtimeAPIs) == 0 && len(allAsyncAPIs) == 0 && len(allBatchAPIs) == 0 && len(allTaskAPIs) == 0 && len(allTrafficSplitters) == 0 {
378 return console.Bold("no apis are deployed"), nil
379 }
380
381 out := ""
382
383 if len(allBatchAPIs) > 0 {
384 envNames := []string{}
385 for range allBatchAPIs {
386 envNames = append(envNames, env.Name)
387 }
388
389 t := batchAPIsTable(allBatchAPIs, envNames)
390 t.FindHeaderByTitle(_titleEnvironment).Hidden = true
391
392 out += t.MustFormat()
393 }
394

Callers 1

get.goFile · 0.85

Calls 10

GetAPIsFunction · 0.92
BoldFunction · 0.92
MustGetOperatorConfigFunction · 0.85
batchAPIsTableFunction · 0.85
taskAPIsTableFunction · 0.85
realtimeAPIsTableFunction · 0.85
asyncAPIsTableFunction · 0.85
trafficSplitterListTableFunction · 0.85
FindHeaderByTitleMethod · 0.80
MustFormatMethod · 0.80

Tested by

no test coverage detected