github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+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  // SecurityGroup represents a security group API resource
    14  type SecurityGroup struct {
    15  	Name        string `json:"-"`
    16  	Protocol    string `json:"protocol"`
    17  	Destination string `json:"destination"`
    18  	Ports       string `json:"ports"`
    19  	Description string `json:"description"`
    20  }
    21  
    22  // NewSecurityGroup returns a new security group with the given attributes
    23  func NewSecurityGroup(name string, protocol string, destination string, ports string, description string) SecurityGroup {
    24  	return SecurityGroup{
    25  		Name:        name,
    26  		Protocol:    protocol,
    27  		Destination: destination,
    28  		Ports:       ports,
    29  		Description: description,
    30  	}
    31  }
    32  
    33  // Create Creates a new security group on the API using the 'cf create-security-group'
    34  func (s SecurityGroup) Create() {
    35  	dir, err := ioutil.TempDir("", "simple-security-group")
    36  	Expect(err).ToNot(HaveOccurred())
    37  	defer os.RemoveAll(dir)
    38  
    39  	tempfile := filepath.Join(dir, "security-group.json")
    40  
    41  	securityGroup, err := json.Marshal([]SecurityGroup{s})
    42  	Expect(err).ToNot(HaveOccurred())
    43  
    44  	err = ioutil.WriteFile(tempfile, securityGroup, 0666)
    45  	Expect(err).ToNot(HaveOccurred())
    46  	Eventually(CF("create-security-group", s.Name, tempfile)).Should(Exit(0))
    47  }