forked from cloudfoundry-community/cloudfoundry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
security_group.go
44 lines (36 loc) · 1.08 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
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)
Expect(err).ToNot(HaveOccurred())
Eventually(CF("create-security-group", s.Name, tempfile)).Should(Exit(0))
}