Skip to content

Commit

Permalink
Fix trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
kluevandrew committed Sep 2, 2022
1 parent d4f14f0 commit 6015678
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions providers/dns/vkcloud/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"path"
"strings"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
Expand Down Expand Up @@ -47,7 +47,7 @@ func (c *Client) ListZones() ([]DNSZone, error) {
var zones []DNSZone
opts := &gophercloud.RequestOpts{JSONResponse: &zones}

err := c.request(http.MethodGet, "", opts)
err := c.request(http.MethodGet, "/", opts)
if err != nil {
return nil, err
}
Expand All @@ -59,7 +59,7 @@ func (c *Client) ListTXTRecords(zoneUUID string) ([]DNSTXTRecord, error) {
var records []DNSTXTRecord
opts := &gophercloud.RequestOpts{JSONResponse: &records}

err := c.request(http.MethodGet, path.Join(zoneUUID, "txt"), opts)
err := c.request(http.MethodGet, joinURL(zoneUUID, "txt", "/"), opts)
if err != nil {
return nil, err
}
Expand All @@ -73,19 +73,19 @@ func (c *Client) CreateTXTRecord(zoneUUID string, record *DNSTXTRecord) error {
JSONResponse: record,
}

return c.request(http.MethodPost, path.Join(zoneUUID, "txt"), opts)
return c.request(http.MethodPost, joinURL(zoneUUID, "txt", "/"), opts)
}

func (c *Client) DeleteTXTRecord(zoneUUID, recordUUID string) error {
return c.request(http.MethodDelete, path.Join(zoneUUID, "txt", recordUUID), &gophercloud.RequestOpts{})
return c.request(http.MethodDelete, joinURL(zoneUUID, "txt", recordUUID), &gophercloud.RequestOpts{})
}

func (c *Client) request(method, uri string, options *gophercloud.RequestOpts) error {
if err := c.lazyAuth(); err != nil {
return fmt.Errorf("auth: %w", err)
}

endpoint, err := c.baseURL.Parse(path.Join(c.baseURL.Path, "v2", "dns", uri))
endpoint, err := c.baseURL.Parse(joinURL(c.baseURL.Path, "v2", "dns", uri))
if err != nil {
return err
}
Expand Down Expand Up @@ -113,6 +113,10 @@ func (c *Client) lazyAuth() error {
return nil
}

func joinURL(parts ...string) string {
return strings.Join(parts, "/")
}

func validateAuthOptions(opts gophercloud.AuthOptions) error {
if opts.TenantID == "" {
return errors.New("project id is missing in credentials information")
Expand Down

0 comments on commit 6015678

Please sign in to comment.