-
Notifications
You must be signed in to change notification settings - Fork 24
/
application_domain_edit.go
101 lines (81 loc) · 3.85 KB
/
application_domain_edit.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package cmd
import (
"context"
"fmt"
"github.com/qovery/qovery-client-go"
"os"
"strconv"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"github.com/qovery/qovery-cli/utils"
)
var applicationDomainEditCmd = &cobra.Command{
Use: "edit",
Short: "Edit application custom domain",
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)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
applications, _, err := client.ApplicationsAPI.ListApplication(context.Background(), envId).Execute()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
application := utils.FindByApplicationName(applications.GetResults(), applicationName)
if application == nil {
utils.PrintlnError(fmt.Errorf("application %s not found", applicationName))
utils.PrintlnInfo("You can list all applications with: qovery application list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
customDomains, _, err := client.ApplicationCustomDomainAPI.ListApplicationCustomDomain(context.Background(), application.Id).Execute()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
customDomain := utils.FindByCustomDomainName(customDomains.GetResults(), applicationCustomDomain)
if customDomain == nil {
utils.PrintlnError(fmt.Errorf("custom domain %s does not exist", applicationCustomDomain))
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
generateCertificate := !doNotGenerateCertificate
req := qovery.CustomDomainRequest{
Domain: applicationCustomDomain,
GenerateCertificate: generateCertificate,
UseCdn: &useCdn,
}
editedDomain, _, err := client.ApplicationCustomDomainAPI.EditCustomDomain(context.Background(), application.Id, customDomain.Id).CustomDomainRequest(req).Execute()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
utils.Println(fmt.Sprintf("Custom domain %s has been edited (generate certificate: %s)", pterm.FgBlue.Sprintf("%s", editedDomain.Domain), pterm.FgBlue.Sprintf("%s", strconv.FormatBool(editedDomain.GenerateCertificate))))
},
}
func init() {
applicationDomainCmd.AddCommand(applicationDomainEditCmd)
applicationDomainEditCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
applicationDomainEditCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
applicationDomainEditCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
applicationDomainEditCmd.Flags().StringVarP(&applicationName, "application", "n", "", "Application Name")
applicationDomainEditCmd.Flags().StringVarP(&applicationCustomDomain, "domain", "", "", "Custom Domain <subdomain.domain.tld>")
applicationDomainEditCmd.Flags().BoolVarP(&doNotGenerateCertificate, "do-not-generate-certificate", "", false, "Do Not Generate Certificate")
applicationDomainEditCmd.Flags().BoolVarP(&useCdn, "is-behind-a-cdn", "", false, "Custom Domain is behind a CDN")
_ = applicationDomainEditCmd.MarkFlagRequired("application")
_ = applicationDomainEditCmd.MarkFlagRequired("domain")
}