regru: HTTP method changed to POST (#2051)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
cab8e1f556
commit
5af3c6c042
2 changed files with 12 additions and 15 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/providers/dns/internal/errutils"
|
"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
|
// https://www.reg.ru/support/help/api2#zone_remove_record
|
||||||
func (c Client) RemoveTxtRecord(ctx context.Context, domain, subDomain, content string) error {
|
func (c Client) RemoveTxtRecord(ctx context.Context, domain, subDomain, content string) error {
|
||||||
request := RemoveRecordRequest{
|
request := RemoveRecordRequest{
|
||||||
Username: c.username,
|
|
||||||
Password: c.password,
|
|
||||||
Domains: []Domain{{DName: domain}},
|
Domains: []Domain{{DName: domain}},
|
||||||
SubDomain: subDomain,
|
SubDomain: subDomain,
|
||||||
Content: content,
|
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
|
// https://www.reg.ru/support/help/api2#zone_add_txt
|
||||||
func (c Client) AddTXTRecord(ctx context.Context, domain, subDomain, content string) error {
|
func (c Client) AddTXTRecord(ctx context.Context, domain, subDomain, content string) error {
|
||||||
request := AddTxtRequest{
|
request := AddTxtRequest{
|
||||||
Username: c.username,
|
|
||||||
Password: c.password,
|
|
||||||
Domains: []Domain{{DName: domain}},
|
Domains: []Domain{{DName: domain}},
|
||||||
SubDomain: subDomain,
|
SubDomain: subDomain,
|
||||||
Text: content,
|
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) {
|
func (c Client) doRequest(ctx context.Context, request any, fragments ...string) (*APIResponse, error) {
|
||||||
endpoint := c.baseURL.JoinPath(fragments...)
|
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)
|
inputData, err := json.Marshal(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create input data: %w", err)
|
return nil, fmt.Errorf("failed to create input data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
query := endpoint.Query()
|
data := url.Values{}
|
||||||
query.Add("input_data", string(inputData))
|
data.Set("input_data", string(inputData))
|
||||||
query.Add("input_format", "json")
|
data.Set("input_format", "json")
|
||||||
endpoint.RawQuery = query.Encode()
|
|
||||||
|
|
||||||
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to create request: %w", err)
|
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)
|
resp, err := c.HTTPClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errutils.NewHTTPDoError(req, err)
|
return nil, errutils.NewHTTPDoError(req, err)
|
||||||
|
|
|
@ -56,9 +56,6 @@ func (d DomainResponse) Error() string {
|
||||||
|
|
||||||
// AddTxtRequest is the representation of the payload of a request to add a TXT record.
|
// AddTxtRequest is the representation of the payload of a request to add a TXT record.
|
||||||
type AddTxtRequest struct {
|
type AddTxtRequest struct {
|
||||||
Username string `json:"username"`
|
|
||||||
Password string `json:"password"`
|
|
||||||
|
|
||||||
Domains []Domain `json:"domains,omitempty"`
|
Domains []Domain `json:"domains,omitempty"`
|
||||||
SubDomain string `json:"subdomain,omitempty"`
|
SubDomain string `json:"subdomain,omitempty"`
|
||||||
Text string `json:"text,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.
|
// RemoveRecordRequest is the representation of the payload of a request to remove a record.
|
||||||
type RemoveRecordRequest struct {
|
type RemoveRecordRequest struct {
|
||||||
Username string `json:"username"`
|
|
||||||
Password string `json:"password"`
|
|
||||||
|
|
||||||
Domains []Domain `json:"domains,omitempty"`
|
Domains []Domain `json:"domains,omitempty"`
|
||||||
SubDomain string `json:"subdomain,omitempty"`
|
SubDomain string `json:"subdomain,omitempty"`
|
||||||
Content string `json:"content,omitempty"`
|
Content string `json:"content,omitempty"`
|
||||||
|
|
Loading…
Reference in a new issue