chore: use UTC instead of GMT when possible (#2275)

This commit is contained in:
Ludovic Fernandez 2024-09-16 19:04:08 +02:00 committed by GitHub
parent d52f7b0b58
commit 0da0942081
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 19 deletions

View file

@ -178,17 +178,12 @@ func (c *Client) do(ctx context.Context, query url.Values, result any) error {
}
func sign(apiUsername, apiKey string, query url.Values) (url.Values, error) {
location, err := time.LoadLocation("GMT")
if err != nil {
return nil, fmt.Errorf("time location: %w", err)
}
timestamp := time.Now().In(location).Format("2006-01-02T15:04:05Z")
timestamp := time.Now().UTC().Format("2006-01-02T15:04:05Z")
canonicalRequest := fmt.Sprintf("%s%s%s", apiUsername, timestamp, defaultBaseURL)
mac := hmac.New(sha256.New, []byte(apiKey))
_, err = mac.Write([]byte(canonicalRequest))
_, err := mac.Write([]byte(canonicalRequest))
if err != nil {
return nil, err
}

View file

@ -121,12 +121,7 @@ func (c *Client) do(req *http.Request, result any) error {
func (c *Client) sign(req *http.Request) error {
if req.Header.Get("Date") == "" {
location, err := time.LoadLocation("GMT")
if err != nil {
return err
}
req.Header.Set("Date", time.Now().In(location).Format(time.RFC1123))
req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
}
if req.URL.Path == "" {

View file

@ -150,12 +150,7 @@ func (c *Client) DeleteRecord(ctx context.Context, domainName string, recordID i
func (c *Client) do(req *http.Request, result any) error {
req.Header.Set("Accept-Language", "en_us")
location, err := time.LoadLocation("GMT")
if err != nil {
return fmt.Errorf("time location: %w", err)
}
err = c.sign(req, time.Now().In(location))
err := c.sign(req, time.Now().UTC())
if err != nil {
return fmt.Errorf("signature: %w", err)
}