Skip to content

Commit

Permalink
regru: HTTP method changed to POST (#2051)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
  • Loading branch information
boiler and ldez committed Nov 12, 2023
1 parent cab8e1f commit 5af3c6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
21 changes: 12 additions & 9 deletions providers/dns/regru/internal/client.go
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"net/url"
"strings"
"time"

"github.com/go-acme/lego/v4/providers/dns/internal/errutils"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions providers/dns/regru/internal/types.go
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down

0 comments on commit 5af3c6c

Please sign in to comment.