Skip to content

Commit

Permalink
Merge pull request #18 from StackPointCloud/firewall-improvements
Browse files Browse the repository at this point in the history
Firewall improvements
  • Loading branch information
alibazlamit authored Jul 30, 2018
2 parents 8f10d5c + e0939a9 commit 7fc7f89
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 73 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ request := oneandone.FirewallPolicyRequest {
Rules: []oneandone.FirewallPolicyRule {
{
Protocol: protocol,
PortFrom: oneandone.Int2Pointer(port_from),
PortTo: oneandone.Int2Pointer(port_to),
Port: "80",
Action: "allow",
SourceIp: source_ip,
},
},
Expand Down Expand Up @@ -639,14 +639,13 @@ Passing an empty string in `fp_new_name` or `fp_new_description` skips updating
fp_rules := []oneandone.FirewallPolicyRule {
{
Protocol: protocol1,
PortFrom: oneandone.Int2Pointer(port_from1),
PortTo: oneandone.Int2Pointer(port_to1),
Port: "80",
SourceIp: source_ip,
},
{
Protocol: protocol2,
PortFrom: oneandone.Int2Pointer(port_from2),
PortTo: oneandone.Int2Pointer(port_to2),
Port: "4000-5000",
Action: "allow",
},
}
Expand Down Expand Up @@ -2398,7 +2397,7 @@ func (api *API) GetVPNConfigFile(vpn_id string) (string, error)
```

```Go
func (api *API) ListBaremetalModels(args ...interface{}) ([]BaremetalModel, error)
func (api *API) ListBaremetalModels() ([]BaremetalModel, error)
```

```Go
Expand Down
2 changes: 1 addition & 1 deletion baremetal_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func create_baremetal_test_server(power_on bool) (string, *Server, error) {
sap := get_baremetal_appliance(hdd_size)
baremetal_ser_app_id = sap.Id
//mp := get_default_mon_policy()
baremetalModels, err := api.ListBaremetalModels(1, 1, "", "BMC_L", "")
baremetalModels, err := api.ListBaremetalModels()
baremetalModel = baremetalModels[0]
baremetalModelId := baremetalModels[0].Id

Expand Down
11 changes: 7 additions & 4 deletions firewallpolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ type FirewallPolicy struct {

type FirewallPolicyRule struct {
idField
Protocol string `json:"protocol,omitempty"`
PortFrom *int `json:"port_from,omitempty"`
PortTo *int `json:"port_to,omitempty"`
SourceIp string `json:"source,omitempty"`
Protocol string `json:"protocol,omitempty"`
PortFrom *int `json:"port_from,omitempty"`
PortTo *int `json:"port_to,omitempty"`
Port string `json:"port,omitempty"`
Action string `json:"action,omitempty"`
Description string `json:"description,omitempty"`
SourceIp string `json:"source,omitempty"`
}

type FirewallPolicyRequest struct {
Expand Down
13 changes: 7 additions & 6 deletions firewallpolicies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func create_firewall_policy() *FirewallPolicy {
Rules: []FirewallPolicyRule{
{
Protocol: "UDP",
PortFrom: Int2Pointer(161),
PortTo: Int2Pointer(162),
Port:"161",
Action: "allow",
Description:"test rules",
},
},
}
Expand Down Expand Up @@ -264,14 +265,14 @@ func TestAddFirewallPolicyRules(t *testing.T) {
rules := []FirewallPolicyRule{
{
Protocol: "TCP",
PortFrom: Int2Pointer(4567),
PortTo: Int2Pointer(4567),
Port:"4567",
Action:"allow",
SourceIp: "0.0.0.0",
},
{
Protocol: "TCP/UDP",
PortFrom: Int2Pointer(143),
PortTo: Int2Pointer(143),
Port:"143",
Action:"allow",
},
{
Protocol: "GRE", // PortFrom & PortTo are optional for GRE, ICMP and IPSEC protocols.
Expand Down
48 changes: 25 additions & 23 deletions servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ type Server struct {
ApiPtr
Identity
descField
CreationDate string `json:"creation_date,omitempty"`
FirstPassword string `json:"first_password,omitempty"`
ServerType string `json:"server_type,omitempty"`
Ipv6Range string `json:"ipv6_range,omitempty"`
Hostname string `json:"hostname,omitempty"`
Datacenter *Datacenter `json:"datacenter,omitempty"`
Status *Status `json:"status,omitempty"`
Hardware *Hardware `json:"hardware,omitempty"`
Image *Identity `json:"image,omitempty"`
Dvd *Identity `json:"dvd,omitempty"`
MonPolicy *Identity `json:"monitoring_policy,omitempty"`
Snapshot *ServerSnapshot `json:"snapshot,omitempty"`
Ips []ServerIp `json:"ips,omitempty"`
PrivateNets []Identity `json:"private_networks,omitempty"`
Alerts *ServerAlerts `json:"-"`
AlertsRaw *json.RawMessage `json:"alerts,omitempty"`
CreationDate string `json:"creation_date,omitempty"`
FirstPassword string `json:"first_password,omitempty"`
ServerType string `json:"server_type,omitempty"`
Ipv6Range string `json:"ipv6_range,omitempty"`
Hostname string `json:"hostname,omitempty"`
Datacenter *Datacenter `json:"datacenter,omitempty"`
Status *Status `json:"status,omitempty"`
Hardware *Hardware `json:"hardware,omitempty"`
Image *Identity `json:"image,omitempty"`
Dvd *Identity `json:"dvd,omitempty"`
MonPolicy *Identity `json:"monitoring_policy,omitempty"`
Snapshot *ServerSnapshot `json:"snapshot,omitempty"`
Ips []ServerIp `json:"ips,omitempty"`
PrivateNets []ServerPrivateNetwork `json:"private_networks,omitempty"`
Alerts *ServerAlerts `json:"-"`
AlertsRaw *json.RawMessage `json:"alerts,omitempty"`
}

type Hardware struct {
Expand All @@ -43,6 +43,11 @@ type ServerHdds struct {
Hdds []Hdd `json:"hdds,omitempty"`
}

type ServerPrivateNetwork struct {
Identity
ServerPrivateIp string `json:"server_ip,omitempty"`
}

type Hdd struct {
idField
Size int `json:"size,omitempty"`
Expand Down Expand Up @@ -146,7 +151,7 @@ type BaremetalHardware struct {
CoresPerProcessor int `json:"cores_per_processor"`
Ram float32 `json:"ram"`
Unit string `json:"unit,omitempty"`
Hdds []Hdd `json:"hdds,omitempty"`
Hdds []Hdd `json:"hdds,omitempty"`
ApiPtr
}

Expand Down Expand Up @@ -817,13 +822,10 @@ func (api *API) CloneServer(server_id string, new_name string, datacenter_id str
}

// GET /servers/baremetal_models
func (api *API) ListBaremetalModels(args ...interface{}) ([]BaremetalModel, error) {
url, err := processQueryParams(createUrl(api, serverPathSegment, baremetalSegment), args...)
if err != nil {
return nil, err
}
func (api *API) ListBaremetalModels() ([]BaremetalModel, error) {
url := createUrl(api, serverPathSegment, baremetalSegment)
res := []BaremetalModel{}
err = api.Client.Get(url, &res, http.StatusOK)
err := api.Client.Get(url, &res, http.StatusOK)
if err != nil {
return nil, err
}
Expand Down
32 changes: 0 additions & 32 deletions servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,41 +301,9 @@ func TestListBaremetalModel(t *testing.T) {

baremetalModelId = res[0].Id

res, err = api.ListBaremetalModels(1, 2, "name", "", "id,name")

if err != nil {
t.Errorf("ListBaremetalModels with parameter options failed. Error: " + err.Error())
return
}
if len(res) == 0 {
t.Errorf("No baremetal model found.")
}
if len(res) > 2 {
t.Errorf("Wrong number of objects per page.")
}
if res[0].Hardware != nil {
t.Errorf("Filtering parameters failed.")
}
if res[0].Name == "" {
t.Errorf("Filtering parameters failed.")
}

// Test for error response
res, err = api.ListBaremetalModels(0, 0, true, "name", "")
if res != nil || err == nil {
t.Errorf("ListBaremetalModels failed to handle incorrect argument type.")
}

res, err = api.ListBaremetalModels(0, 0, "", "BMC", "")

if err != nil {
t.Errorf("ListBaremetalModels with parameter options failed. Error: " + err.Error())
return
}

if !strings.Contains(res[0].Name, "BMC") {
t.Errorf("Search parameter failed.")
}
}

func TestListFixedInstanceSizes(t *testing.T) {
Expand Down

0 comments on commit 7fc7f89

Please sign in to comment.