Merge pull request #267 from digitalocean/asb/db-firewall-get
Return []DatabaseFirewallRule in addition to raw response.
This commit is contained in:
commit
f9210ed2a4
16
databases.go
16
databases.go
|
@ -56,7 +56,7 @@ type DatabasesService interface {
|
||||||
DeleteReplica(context.Context, string, string) (*Response, error)
|
DeleteReplica(context.Context, string, string) (*Response, error)
|
||||||
GetEvictionPolicy(context.Context, string) (string, *Response, error)
|
GetEvictionPolicy(context.Context, string) (string, *Response, error)
|
||||||
SetEvictionPolicy(context.Context, string, string) (*Response, error)
|
SetEvictionPolicy(context.Context, string, string) (*Response, error)
|
||||||
GetFirewallRules(context.Context, string) (*Response, error)
|
GetFirewallRules(context.Context, string) ([]DatabaseFirewallRule, *Response, error)
|
||||||
UpdateFirewallRules(context.Context, string, *DatabaseUpdateFirewallRulesRequest) (*Response, error)
|
UpdateFirewallRules(context.Context, string, *DatabaseUpdateFirewallRulesRequest) (*Response, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ type evictionPolicyRoot struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type databaseFirewallRuleRoot struct {
|
type databaseFirewallRuleRoot struct {
|
||||||
Rules []*DatabaseFirewallRule `json:"rules"`
|
Rules []DatabaseFirewallRule `json:"rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Database) URN() string {
|
func (d Database) URN() string {
|
||||||
|
@ -692,14 +692,20 @@ func (svc *DatabasesServiceOp) SetEvictionPolicy(ctx context.Context, databaseID
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFirewallRules loads the inbound sources for a given cluster.
|
// GetFirewallRules loads the inbound sources for a given cluster.
|
||||||
func (svc *DatabasesServiceOp) GetFirewallRules(ctx context.Context, databaseID string) (*Response, error) {
|
func (svc *DatabasesServiceOp) GetFirewallRules(ctx context.Context, databaseID string) ([]DatabaseFirewallRule, *Response, error) {
|
||||||
path := fmt.Sprintf(databaseFirewallRulesPath, databaseID)
|
path := fmt.Sprintf(databaseFirewallRulesPath, databaseID)
|
||||||
root := new(databaseFirewallRuleRoot)
|
root := new(databaseFirewallRuleRoot)
|
||||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return svc.client.Do(ctx, req, root)
|
|
||||||
|
resp, err := svc.client.Do(ctx, req, root)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return root.Rules, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateFirewallRules sets the inbound sources for a given cluster.
|
// UpdateFirewallRules sets the inbound sources for a given cluster.
|
||||||
|
|
|
@ -1192,6 +1192,15 @@ func TestDatabases_GetFirewallRules(t *testing.T) {
|
||||||
|
|
||||||
path := fmt.Sprintf("/v2/databases/%s/firewall", dbID)
|
path := fmt.Sprintf("/v2/databases/%s/firewall", dbID)
|
||||||
|
|
||||||
|
want := []DatabaseFirewallRule{
|
||||||
|
{
|
||||||
|
Type: "ip_addr",
|
||||||
|
Value: "192.168.1.1",
|
||||||
|
UUID: "deadbeef-dead-4aa5-beef-deadbeef347d",
|
||||||
|
ClusterUUID: "deadbeef-dead-4aa5-beef-deadbeef347d",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
body := ` {"rules": [{
|
body := ` {"rules": [{
|
||||||
"type": "ip_addr",
|
"type": "ip_addr",
|
||||||
"value": "192.168.1.1",
|
"value": "192.168.1.1",
|
||||||
|
@ -1204,8 +1213,9 @@ func TestDatabases_GetFirewallRules(t *testing.T) {
|
||||||
fmt.Fprint(w, body)
|
fmt.Fprint(w, body)
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err := client.Databases.GetFirewallRules(ctx, dbID)
|
got, _, err := client.Databases.GetFirewallRules(ctx, dbID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, want, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDatabases_UpdateFirewallRules(t *testing.T) {
|
func TestDatabases_UpdateFirewallRules(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue