From 5af3c6c04238e05b02567816a1fbe4d7ba60e4c9 Mon Sep 17 00:00:00 2001 From: Alexander Kazarin Date: Sun, 12 Nov 2023 15:38:13 +0300 Subject: [PATCH] regru: HTTP method changed to POST (#2051) Co-authored-by: Fernandez Ludovic --- providers/dns/regru/internal/client.go | 21 ++++++++++++--------- providers/dns/regru/internal/types.go | 6 ------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/providers/dns/regru/internal/client.go b/providers/dns/regru/internal/client.go index b4b81dc0..8d91f4a6 100644 --- a/providers/dns/regru/internal/client.go +++ b/providers/dns/regru/internal/client.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "net/url" + "strings" "time" "github.com/go-acme/lego/v4/providers/dns/internal/errutils" @@ -39,8 +40,6 @@ func NewClient(username, password string) *Client { // https://www.reg.ru/support/help/api2#zone_remove_record func (c Client) RemoveTxtRecord(ctx context.Context, domain, subDomain, content string) error { request := RemoveRecordRequest{ - Username: c.username, - Password: c.password, Domains: []Domain{{DName: domain}}, SubDomain: subDomain, Content: content, @@ -60,8 +59,6 @@ func (c Client) RemoveTxtRecord(ctx context.Context, domain, subDomain, content // https://www.reg.ru/support/help/api2#zone_add_txt func (c Client) AddTXTRecord(ctx context.Context, domain, subDomain, content string) error { request := AddTxtRequest{ - Username: c.username, - Password: c.password, Domains: []Domain{{DName: domain}}, SubDomain: subDomain, Text: content, @@ -79,21 +76,27 @@ func (c Client) AddTXTRecord(ctx context.Context, domain, subDomain, content str func (c Client) doRequest(ctx context.Context, request any, fragments ...string) (*APIResponse, error) { endpoint := c.baseURL.JoinPath(fragments...) + query := endpoint.Query() + query.Set("username", c.username) + query.Set("password", c.password) + endpoint.RawQuery = query.Encode() + inputData, err := json.Marshal(request) if err != nil { return nil, fmt.Errorf("failed to create input data: %w", err) } - query := endpoint.Query() - query.Add("input_data", string(inputData)) - query.Add("input_format", "json") - endpoint.RawQuery = query.Encode() + data := url.Values{} + data.Set("input_data", string(inputData)) + data.Set("input_format", "json") - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), http.NoBody) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), strings.NewReader(data.Encode())) if err != nil { return nil, fmt.Errorf("unable to create request: %w", err) } + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + resp, err := c.HTTPClient.Do(req) if err != nil { return nil, errutils.NewHTTPDoError(req, err) diff --git a/providers/dns/regru/internal/types.go b/providers/dns/regru/internal/types.go index 785b9229..6d4d557f 100644 --- a/providers/dns/regru/internal/types.go +++ b/providers/dns/regru/internal/types.go @@ -56,9 +56,6 @@ func (d DomainResponse) Error() string { // AddTxtRequest is the representation of the payload of a request to add a TXT record. type AddTxtRequest struct { - Username string `json:"username"` - Password string `json:"password"` - Domains []Domain `json:"domains,omitempty"` SubDomain string `json:"subdomain,omitempty"` Text string `json:"text,omitempty"` @@ -67,9 +64,6 @@ type AddTxtRequest struct { // RemoveRecordRequest is the representation of the payload of a request to remove a record. type RemoveRecordRequest struct { - Username string `json:"username"` - Password string `json:"password"` - Domains []Domain `json:"domains,omitempty"` SubDomain string `json:"subdomain,omitempty"` Content string `json:"content,omitempty"`