Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow deleting rDNS entries #839

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions internal/cmd/base/set_rdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (rc *SetRdnsCmd) CobraCommand(s state.State) *cobra.Command {
},
}
cmd.Flags().StringP("hostname", "r", "", "Hostname to set as a reverse DNS PTR entry (required)")
apricote marked this conversation as resolved.
Show resolved Hide resolved
cmd.MarkFlagRequired("hostname")
cmd.Flags().Bool("reset", false, "Reset the reverse DNS entry to the default value")

cmd.Flags().IPP("ip", "i", net.IP{}, "IP address for which the reverse DNS entry should be set")
if rc.AdditionalFlags != nil {
Expand All @@ -51,6 +51,17 @@ func (rc *SetRdnsCmd) CobraCommand(s state.State) *cobra.Command {
// Run executes a setRDNS command.
func (rc *SetRdnsCmd) Run(s state.State, cmd *cobra.Command, args []string) error {

var hostnamePtr *string
if reset, _ := cmd.Flags().GetBool("reset"); reset {
hostnamePtr = nil
} else {
hostname, _ := cmd.Flags().GetString("hostname")
if hostname == "" {
return fmt.Errorf("either --hostname or --reset must be specified")
}
hostnamePtr = &hostname
}

idOrName := args[0]
resource, _, err := rc.Fetch(s, cmd, idOrName)
if err != nil {
Expand All @@ -67,8 +78,8 @@ func (rc *SetRdnsCmd) Run(s state.State, cmd *cobra.Command, args []string) erro
if ip.IsUnspecified() || ip == nil {
ip = rc.GetDefaultIP(resource)
}
hostname, _ := cmd.Flags().GetString("hostname")
action, _, err := s.Client().RDNS().ChangeDNSPtr(s, resource.(hcloud.RDNSSupporter), ip, hcloud.String(hostname))

action, _, err := s.Client().RDNS().ChangeDNSPtr(s, resource.(hcloud.RDNSSupporter), ip, hostnamePtr)
if err != nil {
return err
}
Expand Down