github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/helpers/security_group.go (about) 1 package helpers 2 3 import ( 4 "encoding/json" 5 "io/ioutil" 6 "os" 7 "path/filepath" 8 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 type SecurityGroup struct { 14 Name string `json:"-"` 15 Protocol string `json:"protocol"` 16 Destination string `json:"destination"` 17 Ports string `json:"ports"` 18 Description string `json:"description"` 19 } 20 21 func NewSecurityGroup(name string, protocol string, destination string, ports string, description string) SecurityGroup { 22 return SecurityGroup{ 23 Name: name, 24 Protocol: protocol, 25 Destination: destination, 26 Ports: ports, 27 Description: description, 28 } 29 } 30 31 func (s SecurityGroup) Create() { 32 dir, err := ioutil.TempDir("", "simple-security-group") 33 Expect(err).ToNot(HaveOccurred()) 34 defer os.RemoveAll(dir) 35 36 tempfile := filepath.Join(dir, "security-group.json") 37 38 securityGroup, err := json.Marshal([]SecurityGroup{s}) 39 Expect(err).ToNot(HaveOccurred()) 40 41 err = ioutil.WriteFile(tempfile, securityGroup, 0666) 42 Expect(err).ToNot(HaveOccurred()) 43 Eventually(CF("create-security-group", s.Name, tempfile)).Should(Exit(0)) 44 }