Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions drivers/resipsgcp_dnsalias/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/opensvc/om3/v3/util/sgcp"
)

const noneTarget = "none."
const noneTarget = "none.ocp"

type (
T struct {
Expand Down Expand Up @@ -52,7 +52,7 @@ type (
}

aliasListResponse struct {
Aliases []sgcp.Alias `json:"aliases"`
CnameRecords []sgcp.Alias `json:"cnameRecords"`
}

apiProvider interface {
Expand All @@ -62,10 +62,6 @@ type (
GetAliases(ctx context.Context, zoneID, name, uuid string) (method, url string, code int, data []byte, err error)
UpdateAlias(ctx context.Context, zoneID string, aliasUUID string, name string, target string) (alias *sgcp.Alias, err error)
}

authInfoProvider interface {
GetAuthInfo(string) (*sgcp.AuthInfo, error)
}
)

func New() resource.Driver {
Expand Down
8 changes: 4 additions & 4 deletions drivers/resipsgcp_dnsalias/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestStatus(t *testing.T) {
{
UUID: "a1",
Name: "svc1",
Target: "none.",
Target: "none.ocp",
FQDN: "svc1.example.org",
ZoneID: "z1",
},
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestStatus(t *testing.T) {
resTarget: "tgt2",
expectedStatus: status.Down,
expectedStatusLog: []resource.StatusLogEntry{
{Level: "error", Message: "get alias failed: unexpected status code for GET /file/alias got 500 wanted [200 404]"},
{Level: "error", Message: "get alias failed: unexpected status code for GET https://dns.example.com/zones/z1/cname-records?name=bad500 got 500 wanted [200 404]"},
{Level: "info", Message: "not found"},
},
},
Expand Down Expand Up @@ -436,7 +436,7 @@ func TestStop(t *testing.T) {
{
UUID: "uuid-none",
Name: "name-none",
Target: "none.",
Target: "none.ocp",
FQDN: "name2.z1",
ZoneID: "z1",
},
Expand Down Expand Up @@ -528,7 +528,7 @@ func TestStop(t *testing.T) {
db, drv := newDBAndDrv(t, "rid1", dbEntries)
drv.Name = "name-none"
drv.UUID = "uuid-none"
drv.Target = "none."
drv.Target = "none.ocp"
drv.ZoneID = "z1"
require.NoError(t, drv.Configure())

Expand Down
2 changes: 1 addition & 1 deletion drivers/resipsgcp_dnsalias/mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (m *mgr) getAliases(ctx context.Context) ([]sgcp.Alias, error) {
if err := json.Unmarshal(data, &resp); err != nil {
return nil, fmt.Errorf("decode aliases: %w", err)
}
return resp.Aliases, nil
return resp.CnameRecords, nil
}

// create creates a new alias with the specified target and returns the created alias or an error if the operation fails.
Expand Down
19 changes: 7 additions & 12 deletions util/sgcp/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ type Alias struct {
Name string `json:"name,omitempty"`
Target string `json:"target,omitempty"`
FQDN string `json:"fqdn,omitempty"`
ZoneID string `json:"zone_id,omitempty"`
}

// aliasListResponse is the API response for listing aliases.
type aliasListResponse struct {
Aliases []Alias `json:"aliases"`
ZoneID string `json:"zoneId,omitempty"`
}

// NewDNSAPI creates a new DNSAPI instance.
Expand Down Expand Up @@ -76,12 +71,12 @@ func (a *DNSAPI) CreateAlias(ctx context.Context, zoneID, name, target string) (
return &result, nil
}

// UpdateAlias updates an existing DNS alias.
// UpdateAlias updates an existing DNS alias (PATCH, target only).
func (a *DNSAPI) UpdateAlias(ctx context.Context, zoneID, aliasUUID, name, target string) (alias *Alias, err error) {
method := http.MethodPut
method := http.MethodPatch
path := a.getAliasURL(zoneID, aliasUUID)

payload := map[string]any{"name": name, "target": target, "ttl": 60}
payload := map[string]any{"target": target, "ttl": 60}
var b []byte
b, err = json.Marshal(payload)
if err != nil {
Expand Down Expand Up @@ -121,16 +116,16 @@ func (a *DNSAPI) GetScopes(scopeType string) []string {
// getAliasesURL constructs the URL for listing aliases with query parameters.
func (a *DNSAPI) getAliasesURL(zoneID, name, uuid string) string {
values := url.Values{}
values.Set("zone_id", zoneID)
if name != "" {
values.Set("name", name)
}
if uuid != "" {
values.Set("id", uuid)
}
base := strings.TrimRight(a.config.DNS.BaseURL, "/")
path := a.config.DNS.Path.CName
return fmt.Sprintf("%s%s?%s", base, path, values.Encode())
zonePath := a.config.DNS.Path.Zone
aliasPath := a.config.DNS.Path.CName
return fmt.Sprintf("%s%s/%s%s?%s", base, zonePath, zoneID, aliasPath, values.Encode())
}

// getAliasesCreateURL constructs the URL for creating an alias.
Expand Down
12 changes: 10 additions & 2 deletions util/sgcpdnstesthelper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ func (a *Api) GetAliases(_ context.Context, zoneID, name, uuid string) (method,
a.callCount.Search++
a.rLock.RUnlock()
method = http.MethodGet
url = "/file/alias"
base := "https://dns.example.com"
url = fmt.Sprintf("%s/zones/%s/cname-records", base, zoneID)
if name != "" && uuid != "" {
url += fmt.Sprintf("?name=%s&id=%s", name, uuid)
} else if name != "" {
url += fmt.Sprintf("?name=%s", name)
} else if uuid != "" {
url += fmt.Sprintf("?id=%s", uuid)
}
if ok {
code := resp.StatusCode
if code == 0 {
code = http.StatusOK
}
m := map[string][]sgcp.Alias{
"aliases": resp.AliasL,
"cnameRecords": resp.AliasL,
}
b, err := json.Marshal(m)
if err == nil {
Expand Down
Loading