-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_ingest_check.go
76 lines (66 loc) · 1.92 KB
/
create_ingest_check.go
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
package ingestcheck
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/calyptia/api/types"
"github.com/calyptia/cli/completer"
cfg "github.com/calyptia/cli/config"
)
func NewCmdCreateIngestCheck(config *cfg.Config) *cobra.Command {
var (
retries uint
configSectionID string
status string
environment string
collectLogs bool
)
completer := completer.Completer{Config: config}
cmd := &cobra.Command{
Use: "ingest_check CORE_INSTANCE",
Short: "Create an ingest check",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
coreInstance := args[0]
ctx := context.Background()
params := types.CreateIngestCheck{
CollectLogs: collectLogs,
}
if configSectionID == "" {
return fmt.Errorf("invalid config section id")
}
params.ConfigSectionID = configSectionID
if retries > 0 {
params.Retries = retries
}
if status != "" && !types.ValidCheckStatus(types.CheckStatus(status)) {
return fmt.Errorf("invalid check status")
}
var environmentID string
if environment != "" {
var err error
environmentID, err = completer.LoadEnvironmentID(environment)
if err != nil {
return err
}
}
coreInstanceID, err := completer.LoadCoreInstanceID(coreInstance, environmentID)
if err != nil {
return err
}
check, err := config.Cloud.CreateIngestCheck(ctx, coreInstanceID, params)
if err != nil {
return err
}
cmd.Println(check.ID)
return nil
},
}
flags := cmd.Flags()
flags.UintVar(&retries, "retries", 0, "number of retries")
flags.StringVar(&configSectionID, "config-section-id", "", "config section ID")
flags.StringVar(&status, "status", "", "status")
flags.BoolVar(&collectLogs, "collect-logs", false, "Collect logs from the kubernetes pods once the job is finished")
flags.StringVar(&environment, "environment", "default", "calyptia environment name")
return cmd
}