|
| 1 | +package whois |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "context" |
| 6 | + "encoding/json" |
| 7 | + "log" |
| 8 | + |
| 9 | + "github.com/hostinger/api-cli/api" |
| 10 | + "github.com/hostinger/api-cli/output" |
| 11 | + "github.com/spf13/cobra" |
| 12 | +) |
| 13 | + |
| 14 | +var ChangeForCmd = &cobra.Command{ |
| 15 | + Use: "change-for", |
| 16 | + Short: "Change WHOIS profile for domain", |
| 17 | + Long: "Change WHOIS contact profile for a domain.\n\nRepoints the given contact roles to a new WHOIS profile and submits the change to the registry.\nThe profile currently assigned to those roles is resolved automatically;\nthe request fails if the given roles are not all on the same profile today.\n\nChanging transfer sensitive fields on the owner contact starts an IRTP verification.\n\nThe change is processed asynchronously.\n\nUse this endpoint to move a registered domain onto different contact information.", |
| 18 | + Run: func(cmd *cobra.Command, args []string) { |
| 19 | + payload, err := json.Marshal(changeForBody(cmd)) |
| 20 | + if err != nil { |
| 21 | + log.Fatal(err) |
| 22 | + } |
| 23 | + r, err := api.Request().DomainsChangeWHOISProfileForDomainV1WithBodyWithResponse(context.TODO(), "application/json", bytes.NewReader(payload)) |
| 24 | + if err != nil { |
| 25 | + log.Fatal(err) |
| 26 | + } |
| 27 | + |
| 28 | + output.Format(cmd, r.Body, r.StatusCode()) |
| 29 | + }, |
| 30 | +} |
| 31 | + |
| 32 | +func init() { |
| 33 | + ChangeForCmd.Flags().StringSliceP("change-for", "", nil, "Contact roles to repoint to the new WHOIS profile (one of: owner, admin, billing, tech)") |
| 34 | + ChangeForCmd.Flags().StringP("domain", "", "", "Domain name") |
| 35 | + ChangeForCmd.Flags().IntP("new-whois-id", "", 0, "WHOIS profile ID to assign to the domain") |
| 36 | + ChangeForCmd.MarkFlagRequired("change-for") |
| 37 | + ChangeForCmd.MarkFlagRequired("domain") |
| 38 | + ChangeForCmd.MarkFlagRequired("new-whois-id") |
| 39 | +} |
| 40 | + |
| 41 | +func changeForBody(cmd *cobra.Command) map[string]any { |
| 42 | + body := map[string]any{} |
| 43 | + changeForVal, _ := cmd.Flags().GetStringSlice("change-for") |
| 44 | + body["change_for"] = changeForVal |
| 45 | + domainVal, _ := cmd.Flags().GetString("domain") |
| 46 | + body["domain"] = domainVal |
| 47 | + newWhoisIdVal, _ := cmd.Flags().GetInt("new-whois-id") |
| 48 | + body["new_whois_id"] = newWhoisIdVal |
| 49 | + return body |
| 50 | +} |
0 commit comments