regru: HTTP method changed to POST (#2051)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
Alexander Kazarin 2023-11-12 15:38:13 +03:00 committed by GitHub
parent cab8e1f556
commit 5af3c6c042
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 15 deletions

View file

@ -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)

View file

@ -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"`