Skip to content

Commit

Permalink
Add --insecure flag to LinkDomain to disable default HTTPS redirect.
Browse files Browse the repository at this point in the history
  • Loading branch information
lnsp committed Oct 28, 2023
1 parent 3800e4c commit 0ff6c62
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
7 changes: 5 additions & 2 deletions cmd/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}),
}

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions pkg/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ff6c62

Please sign in to comment.