-
Notifications
You must be signed in to change notification settings - Fork 24
/
cronjob_env_create.go
79 lines (63 loc) · 2.91 KB
/
cronjob_env_create.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
77
78
79
package cmd
import (
"context"
"fmt"
"os"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"github.com/qovery/qovery-cli/utils"
)
var cronjobEnvCreateCmd = &cobra.Command{
Use: "create",
Short: "Create cronjob environment variable or secret",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)
tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
client := utils.GetQoveryClient(tokenType, token)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
cronjobs, _, err := client.JobsAPI.ListJobs(context.Background(), envId).Execute()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
cronjob := utils.FindByJobName(cronjobs.GetResults(), cronjobName)
if cronjob == nil || cronjob.CronJobResponse == nil {
utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName))
utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
err = utils.CreateEnvironmentVariable(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobScope, utils.Key, utils.Value, utils.IsSecret)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
utils.Println(fmt.Sprintf("Environment variable %s has been created", pterm.FgBlue.Sprintf("%s", utils.Key)))
},
}
func init() {
cronjobEnvCmd.AddCommand(cronjobEnvCreateCmd)
cronjobEnvCreateCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
cronjobEnvCreateCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
cronjobEnvCreateCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
cronjobEnvCreateCmd.Flags().StringVarP(&cronjobName, "cronjob", "n", "", "Cronjob Name")
cronjobEnvCreateCmd.Flags().StringVarP(&utils.Key, "key", "k", "", "Environment variable or secret key")
cronjobEnvCreateCmd.Flags().StringVarP(&utils.Value, "value", "v", "", "Environment variable or secret value")
cronjobEnvCreateCmd.Flags().StringVarP(&utils.JobScope, "scope", "", "JOB", "Scope of this env var <PROJECT|ENVIRONMENT|JOB>")
cronjobEnvCreateCmd.Flags().BoolVarP(&utils.IsSecret, "secret", "", false, "This environment variable is a secret")
_ = cronjobEnvCreateCmd.MarkFlagRequired("key")
_ = cronjobEnvCreateCmd.MarkFlagRequired("value")
_ = cronjobEnvCreateCmd.MarkFlagRequired("cronjob")
}