Skip to content

Commit

Permalink
feat: allow deleting rDNS entries
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Aug 12, 2024
1 parent 6fd096b commit dd5719f
Showing 1 changed file with 14 additions and 3 deletions.
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)")
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 Down Expand Up @@ -67,8 +67,19 @@ 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))

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
}

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

0 comments on commit dd5719f

Please sign in to comment.