Skip to content

Commit

Permalink
Add domain removal
Browse files Browse the repository at this point in the history
  • Loading branch information
lnsp committed Aug 9, 2022
1 parent d492667 commit 889b79f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ valar domains link [domain] ([service])
valar domains unlink [domain] ([service])
```
#### Remove a domain and all domain links [not implemented]
#### Remove a domain
```bash
valar domains delete [domain]
```
Expand Down
26 changes: 26 additions & 0 deletions cmd/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ var domainsAddCmd = &cobra.Command{
}),
}

var domainsRemoveCmd = &cobra.Command{
Use: "remove [domain]",
Short: "Removes an existing domain from the project",
Args: cobra.ExactArgs(1),
Run: runAndHandle(func(cmd *cobra.Command, args []string) error {
var project string
// Attempt to read project from file if possible
cfg := &config.ServiceConfig{}
if err := cfg.ReadFromFile(functionConfiguration); err != nil {
// Fall back to global project
project = globalConfiguration.Project()
} else {
project = cfg.Project
}
client, err := globalConfiguration.APIClient()
if err != nil {
return err
}
if err := client.RemoveDomain(project, args[0]); err != nil {
return err
}
return nil
}),
}

var domainsVerifyCmd = &cobra.Command{
Use: "verify [domain]",
Short: "Verify a newly added domain",
Expand Down Expand Up @@ -174,5 +199,6 @@ func initDomainsCmd() {
domainsCmd.AddCommand(domainsVerifyCmd)
domainsCmd.AddCommand(domainsLinkCmd)
domainsCmd.AddCommand(domainsUnlinkCmd)
domainsCmd.AddCommand(domainsRemoveCmd)
rootCmd.AddCommand(domainsCmd)
}
10 changes: 10 additions & 0 deletions pkg/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ func (client *Client) AddDomain(project, domain string) (map[string]string, erro
return records, nil
}

func (client *Client) RemoveDomain(project, domain string) error {
var (
path = fmt.Sprintf("/projects/%s/domains/%s", project, domain)
)
if err := client.request(http.MethodDelete, path, nil, nil); err != nil {
return err
}
return nil
}

func (client *Client) LinkDomain(project, domain, service string) error {
var (
path = fmt.Sprintf("/projects/%s/domains/%s/link", project, domain)
Expand Down

0 comments on commit 889b79f

Please sign in to comment.