Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] FWaaS v2.0 Rule Get (depends on PR 1771) #1772

Merged
merged 15 commits into from
Nov 26, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (

"github.com/gophercloud/gophercloud/acceptance/clients"
"github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas_v2/rules"
th "github.com/gophercloud/gophercloud/testhelper"
)

func TestRuleCD(t *testing.T) {
func TestRuleCRD(t *testing.T) {

client, err := clients.NewNetworkV2Client()
th.AssertNoErr(t, err)

Expand All @@ -19,4 +21,9 @@ func TestRuleCD(t *testing.T) {
defer DeleteRule(t, client, rule.ID)

tools.PrintResource(t, rule)

newRule, err := rules.Get(client, rule.ID).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, newRule)
}
6 changes: 6 additions & 0 deletions openstack/networking/v2/extensions/fwaas_v2/rules/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResul
return
}

// Get retrieves a particular firewall rule based on its unique ID.
func Get(c *gophercloud.ServiceClient, id string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
return
}

// Delete will permanently delete a particular firewall rule based on its unique ID.
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(resourceURL(c, id), nil)
Expand Down
5 changes: 5 additions & 0 deletions openstack/networking/v2/extensions/fwaas_v2/rules/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func (r commonResult) Extract() (*Rule, error) {
return s.Rule, err
}

// GetResult represents the result of a get operation.
type GetResult struct {
commonResult
}

// DeleteResult represents the result of a delete operation.
type DeleteResult struct {
gophercloud.ErrResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,57 @@ func TestCreateAnyProtocol(t *testing.T) {
th.AssertNoErr(t, err)
}

func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

th.Mux.HandleFunc("/v2.0/fwaas/firewall_rules/f03bd950-6c56-4f5e-a307-45967078f507", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

fmt.Fprintf(w, `
{
"firewall_rule":{
"protocol": "tcp",
"description": "ssh rule",
"source_port": null,
"source_ip_address": null,
"destination_ip_address": "192.168.1.0/24",
"firewall_policy_id": "e2a5fb51-698c-4898-87e8-f1eee6b50919",
"position": 2,
"destination_port": "22",
"id": "f03bd950-6c56-4f5e-a307-45967078f507",
"name": "ssh_form_any",
"tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61",
"enabled": true,
"action": "allow",
"ip_version": 4,
"shared": false
}
}
`)
})

rule, err := rules.Get(fake.ServiceClient(), "f03bd950-6c56-4f5e-a307-45967078f507").Extract()
th.AssertNoErr(t, err)

th.AssertEquals(t, "tcp", rule.Protocol)
th.AssertEquals(t, "ssh rule", rule.Description)
th.AssertEquals(t, "192.168.1.0/24", rule.DestinationIPAddress)
th.AssertEquals(t, "e2a5fb51-698c-4898-87e8-f1eee6b50919", rule.FirewallPolicyID)
th.AssertEquals(t, "22", rule.DestinationPort)
th.AssertEquals(t, "f03bd950-6c56-4f5e-a307-45967078f507", rule.ID)
th.AssertEquals(t, "ssh_form_any", rule.Name)
th.AssertEquals(t, "80cf934d6ffb4ef5b244f1c512ad1e61", rule.TenantID)
th.AssertEquals(t, true, rule.Enabled)
th.AssertEquals(t, "allow", rule.Action)
th.AssertEquals(t, 4, rule.IPVersion)
th.AssertEquals(t, false, rule.Shared)
}

func TestDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
Expand Down