diff --git a/drivers/resipsgcp_dnsalias/main.go b/drivers/resipsgcp_dnsalias/main.go index 2f0fda5e1..e8a3fa6ff 100644 --- a/drivers/resipsgcp_dnsalias/main.go +++ b/drivers/resipsgcp_dnsalias/main.go @@ -16,7 +16,7 @@ import ( "github.com/opensvc/om3/v3/util/sgcp" ) -const noneTarget = "none." +const noneTarget = "none.ocp" type ( T struct { @@ -52,7 +52,7 @@ type ( } aliasListResponse struct { - Aliases []sgcp.Alias `json:"aliases"` + CnameRecords []sgcp.Alias `json:"cnameRecords"` } apiProvider interface { @@ -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 { diff --git a/drivers/resipsgcp_dnsalias/main_test.go b/drivers/resipsgcp_dnsalias/main_test.go index 85067112b..c5e815c42 100644 --- a/drivers/resipsgcp_dnsalias/main_test.go +++ b/drivers/resipsgcp_dnsalias/main_test.go @@ -55,7 +55,7 @@ func TestStatus(t *testing.T) { { UUID: "a1", Name: "svc1", - Target: "none.", + Target: "none.ocp", FQDN: "svc1.example.org", ZoneID: "z1", }, @@ -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"}, }, }, @@ -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", }, @@ -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()) diff --git a/drivers/resipsgcp_dnsalias/mgr.go b/drivers/resipsgcp_dnsalias/mgr.go index ef4a606ff..e087c61c6 100644 --- a/drivers/resipsgcp_dnsalias/mgr.go +++ b/drivers/resipsgcp_dnsalias/mgr.go @@ -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. diff --git a/util/sgcp/dns.go b/util/sgcp/dns.go index 1f89ccdfb..11b836489 100644 --- a/util/sgcp/dns.go +++ b/util/sgcp/dns.go @@ -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. @@ -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 { @@ -121,7 +116,6 @@ 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) } @@ -129,8 +123,9 @@ func (a *DNSAPI) getAliasesURL(zoneID, name, uuid string) string { 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. diff --git a/util/sgcpdnstesthelper/main.go b/util/sgcpdnstesthelper/main.go index 4b095b117..cbd14dd6b 100644 --- a/util/sgcpdnstesthelper/main.go +++ b/util/sgcpdnstesthelper/main.go @@ -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 {