-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(COR-719): add generate_certificate to custom domain
- Loading branch information
Showing
8 changed files
with
234 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/qovery/qovery-client-go" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/pterm/pterm" | ||
"github.com/qovery/qovery-cli/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
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.CustomDomainApi.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, | ||
} | ||
|
||
editedDomain, _, err := client.CustomDomainApi.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(editedDomain.Domain), pterm.FgBlue.Sprintf(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.MarkFlagRequired("application") | ||
_ = applicationDomainEditCmd.MarkFlagRequired("domain") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/qovery/qovery-client-go" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/pterm/pterm" | ||
"github.com/qovery/qovery-cli/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var containerDomainEditCmd = &cobra.Command{ | ||
Use: "edit", | ||
Short: "Edit container 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 | ||
} | ||
|
||
containers, _, err := client.ContainersApi.ListContainer(context.Background(), envId).Execute() | ||
|
||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
container := utils.FindByContainerName(containers.GetResults(), containerName) | ||
|
||
if container == nil { | ||
utils.PrintlnError(fmt.Errorf("container %s not found", containerName)) | ||
utils.PrintlnInfo("You can list all containers with: qovery container list") | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
customDomains, _, err := client.ContainerCustomDomainApi.ListContainerCustomDomain(context.Background(), container.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(), containerCustomDomain) | ||
if customDomain == nil { | ||
utils.PrintlnError(fmt.Errorf("custom domain %s does not exist", containerCustomDomain)) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
generateCertificate := !doNotGenerateCertificate | ||
req := qovery.CustomDomainRequest{ | ||
Domain: containerCustomDomain, | ||
GenerateCertificate: &generateCertificate, | ||
} | ||
|
||
editedDomain, _, err := client.ContainerCustomDomainApi.EditContainerCustomDomain(context.Background(), container.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(editedDomain.Domain), pterm.FgBlue.Sprintf(strconv.FormatBool(*editedDomain.GenerateCertificate)))) | ||
}, | ||
} | ||
|
||
func init() { | ||
containerDomainCmd.AddCommand(containerDomainEditCmd) | ||
containerDomainEditCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name") | ||
containerDomainEditCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name") | ||
containerDomainEditCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name") | ||
containerDomainEditCmd.Flags().StringVarP(&containerName, "container", "n", "", "Container Name") | ||
containerDomainEditCmd.Flags().StringVarP(&containerCustomDomain, "domain", "", "", "Custom Domain <subdomain.domain.tld>") | ||
containerDomainEditCmd.Flags().BoolVarP(&doNotGenerateCertificate, "do-not-generate-certificate", "", false, "Do Not Generate Certificate") | ||
|
||
_ = containerDomainEditCmd.MarkFlagRequired("container") | ||
_ = containerDomainEditCmd.MarkFlagRequired("domain") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters