Skip to content

Commit 5af3c6c

Browse files
boilerldez
andauthored
regru: HTTP method changed to POST (go-acme#2051)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent cab8e1f commit 5af3c6c

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

providers/dns/regru/internal/client.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"net/http"
99
"net/url"
10+
"strings"
1011
"time"
1112

1213
"github.com/go-acme/lego/v4/providers/dns/internal/errutils"
@@ -39,8 +40,6 @@ func NewClient(username, password string) *Client {
3940
// https://www.reg.ru/support/help/api2#zone_remove_record
4041
func (c Client) RemoveTxtRecord(ctx context.Context, domain, subDomain, content string) error {
4142
request := RemoveRecordRequest{
42-
Username: c.username,
43-
Password: c.password,
4443
Domains: []Domain{{DName: domain}},
4544
SubDomain: subDomain,
4645
Content: content,
@@ -60,8 +59,6 @@ func (c Client) RemoveTxtRecord(ctx context.Context, domain, subDomain, content
6059
// https://www.reg.ru/support/help/api2#zone_add_txt
6160
func (c Client) AddTXTRecord(ctx context.Context, domain, subDomain, content string) error {
6261
request := AddTxtRequest{
63-
Username: c.username,
64-
Password: c.password,
6562
Domains: []Domain{{DName: domain}},
6663
SubDomain: subDomain,
6764
Text: content,
@@ -79,21 +76,27 @@ func (c Client) AddTXTRecord(ctx context.Context, domain, subDomain, content str
7976
func (c Client) doRequest(ctx context.Context, request any, fragments ...string) (*APIResponse, error) {
8077
endpoint := c.baseURL.JoinPath(fragments...)
8178

79+
query := endpoint.Query()
80+
query.Set("username", c.username)
81+
query.Set("password", c.password)
82+
endpoint.RawQuery = query.Encode()
83+
8284
inputData, err := json.Marshal(request)
8385
if err != nil {
8486
return nil, fmt.Errorf("failed to create input data: %w", err)
8587
}
8688

87-
query := endpoint.Query()
88-
query.Add("input_data", string(inputData))
89-
query.Add("input_format", "json")
90-
endpoint.RawQuery = query.Encode()
89+
data := url.Values{}
90+
data.Set("input_data", string(inputData))
91+
data.Set("input_format", "json")
9192

92-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), http.NoBody)
93+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), strings.NewReader(data.Encode()))
9394
if err != nil {
9495
return nil, fmt.Errorf("unable to create request: %w", err)
9596
}
9697

98+
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
99+
97100
resp, err := c.HTTPClient.Do(req)
98101
if err != nil {
99102
return nil, errutils.NewHTTPDoError(req, err)

providers/dns/regru/internal/types.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ func (d DomainResponse) Error() string {
5656

5757
// AddTxtRequest is the representation of the payload of a request to add a TXT record.
5858
type AddTxtRequest struct {
59-
Username string `json:"username"`
60-
Password string `json:"password"`
61-
6259
Domains []Domain `json:"domains,omitempty"`
6360
SubDomain string `json:"subdomain,omitempty"`
6461
Text string `json:"text,omitempty"`
@@ -67,9 +64,6 @@ type AddTxtRequest struct {
6764

6865
// RemoveRecordRequest is the representation of the payload of a request to remove a record.
6966
type RemoveRecordRequest struct {
70-
Username string `json:"username"`
71-
Password string `json:"password"`
72-
7367
Domains []Domain `json:"domains,omitempty"`
7468
SubDomain string `json:"subdomain,omitempty"`
7569
Content string `json:"content,omitempty"`

0 commit comments

Comments
 (0)