diff --git a/README.md b/README.md index bcef561..2820a5c 100644 --- a/README.md +++ b/README.md @@ -164,9 +164,11 @@ valar domains verify [domain] #### Link a domain to a service ```bash -valar domains link [domain] ([service]) +valar domains link [--insecure] [domain] ([service]) ``` +> If `--insecure` is enabled, the default HTTP-to-HTTPS redirection handler will be disabled and any plaintext HTTP requests will be forwarded to your service. + #### Unlink a domain from a service ```bash valar domains unlink [domain] ([service]) diff --git a/cmd/domains.go b/cmd/domains.go index 59efdab..bb6d4d4 100644 --- a/cmd/domains.go +++ b/cmd/domains.go @@ -134,8 +134,10 @@ var domainsVerifyCmd = &cobra.Command{ }), } +var domainsLinkAllowInsecureTraffic bool + var domainsLinkCmd = &cobra.Command{ - Use: "link [domain] ([service])", + Use: "link [--insecure] [domain] ([service])", Short: "Link a domain to a service", Args: cobra.RangeArgs(1, 2), Run: runAndHandle(func(cmd *cobra.Command, args []string) error { @@ -160,7 +162,7 @@ var domainsLinkCmd = &cobra.Command{ if err != nil { return err } - return client.LinkDomain(project, args[0], svc) + return client.LinkDomain(project, args[0], svc, domainsLinkAllowInsecureTraffic) }), } @@ -195,6 +197,7 @@ var domainsUnlinkCmd = &cobra.Command{ } func initDomainsCmd() { + domainsLinkCmd.Flags().BoolVarP(&domainsLinkAllowInsecureTraffic, "insecure", "i", false, "Allow insecure traffic to the service. Disables the default HTTPS redirect for this domain.") domainsCmd.AddCommand(domainsAddCmd) domainsCmd.AddCommand(domainsVerifyCmd) domainsCmd.AddCommand(domainsLinkCmd) diff --git a/pkg/api/client.go b/pkg/api/client.go index 533cec6..a0e8584 100644 --- a/pkg/api/client.go +++ b/pkg/api/client.go @@ -334,12 +334,16 @@ func (client *Client) DeleteDomain(project, domain string) error { return nil } -func (client *Client) LinkDomain(project, domain, service string) error { +func (client *Client) LinkDomain(project, domain, service string, allowInsecureTraffic bool) error { var ( path = fmt.Sprintf("/projects/%s/domains/%s/link", project, domain) payload, _ = json.Marshal(struct { - Service string `json:"service"` - }{service}) + Service string `json:"service"` + AllowInsecureTraffic bool `json:"allowInsecureTraffic"` + }{ + Service: service, + AllowInsecureTraffic: allowInsecureTraffic, + }) ) if err := client.request(http.MethodPost, path, nil, bytes.NewReader(payload)); err != nil { return err