forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
security_group.go
47 lines (38 loc) · 1.15 KB
/
security_group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package helpers
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
type SecurityGroup struct {
Name string `json:"-"`
Protocol string `json:"protocol"`
Destination string `json:"destination"`
Ports string `json:"ports"`
Description string `json:"description"`
}
func NewSecurityGroup(name string, protocol string, destination string, ports string, description string) SecurityGroup {
return SecurityGroup{
Name: name,
Protocol: protocol,
Destination: destination,
Ports: ports,
Description: description,
}
}
func (s SecurityGroup) Create() {
dir, err := ioutil.TempDir("", "simple-security-group")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(dir)
tempfile := filepath.Join(dir, "security-group.json")
securityGroup, err := json.Marshal([]SecurityGroup{s})
Expect(err).ToNot(HaveOccurred())
err = ioutil.WriteFile(tempfile, securityGroup, 0666)
Eventually(CF("create-security-group", s.Name, tempfile)).Should(Exit(0))
}
func (s SecurityGroup) Delete() {
Eventually(CF("delete-security-group", s.Name, "-f")).Should(Exit(0))
}