github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/security_group.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     5  	"code.cloudfoundry.org/cli/resources"
     6  )
     7  
     8  func (client *Client) CreateSecurityGroup(securityGroup resources.SecurityGroup) (resources.SecurityGroup, Warnings, error) {
     9  	var responseBody resources.SecurityGroup
    10  
    11  	_, warnings, err := client.MakeRequest(RequestParams{
    12  		RequestName:  internal.PostSecurityGroupRequest,
    13  		RequestBody:  securityGroup,
    14  		ResponseBody: &responseBody,
    15  	})
    16  
    17  	return responseBody, warnings, err
    18  }
    19  
    20  func (client *Client) GetSecurityGroups(queries ...Query) ([]resources.SecurityGroup, Warnings, error) {
    21  	var securityGroups []resources.SecurityGroup
    22  
    23  	_, warnings, err := client.MakeListRequest(RequestParams{
    24  		RequestName:  internal.GetSecurityGroupsRequest,
    25  		Query:        queries,
    26  		ResponseBody: resources.SecurityGroup{},
    27  		AppendToList: func(item interface{}) error {
    28  			securityGroups = append(securityGroups, item.(resources.SecurityGroup))
    29  			return nil
    30  		},
    31  	})
    32  
    33  	return securityGroups, warnings, err
    34  }
    35  
    36  func (client *Client) GetRunningSecurityGroups(spaceGUID string, queries ...Query) ([]resources.SecurityGroup, Warnings, error) {
    37  	var securityGroups []resources.SecurityGroup
    38  
    39  	_, warnings, err := client.MakeListRequest(RequestParams{
    40  		RequestName:  internal.GetSpaceRunningSecurityGroupsRequest,
    41  		URIParams:    internal.Params{"space_guid": spaceGUID},
    42  		Query:        queries,
    43  		ResponseBody: resources.SecurityGroup{},
    44  		AppendToList: func(item interface{}) error {
    45  			securityGroups = append(securityGroups, item.(resources.SecurityGroup))
    46  			return nil
    47  		},
    48  	})
    49  
    50  	return securityGroups, warnings, err
    51  }
    52  
    53  func (client *Client) GetStagingSecurityGroups(spaceGUID string, queries ...Query) ([]resources.SecurityGroup, Warnings, error) {
    54  	var securityGroups []resources.SecurityGroup
    55  
    56  	_, warnings, err := client.MakeListRequest(RequestParams{
    57  		RequestName:  internal.GetSpaceStagingSecurityGroupsRequest,
    58  		URIParams:    internal.Params{"space_guid": spaceGUID},
    59  		Query:        queries,
    60  		ResponseBody: resources.SecurityGroup{},
    61  		AppendToList: func(item interface{}) error {
    62  			securityGroups = append(securityGroups, item.(resources.SecurityGroup))
    63  			return nil
    64  		},
    65  	})
    66  
    67  	return securityGroups, warnings, err
    68  }
    69  
    70  func (client *Client) UnbindSecurityGroupRunningSpace(securityGroupGUID string, spaceGUID string) (Warnings, error) {
    71  	_, warnings, err := client.MakeRequest(RequestParams{
    72  		RequestName: internal.DeleteSecurityGroupRunningSpaceRequest,
    73  		URIParams: internal.Params{
    74  			"security_group_guid": securityGroupGUID,
    75  			"space_guid":          spaceGUID,
    76  		},
    77  	})
    78  
    79  	return warnings, err
    80  }
    81  
    82  func (client *Client) UnbindSecurityGroupStagingSpace(securityGroupGUID string, spaceGUID string) (Warnings, error) {
    83  	_, warnings, err := client.MakeRequest(RequestParams{
    84  		RequestName: internal.DeleteSecurityGroupStagingSpaceRequest,
    85  		URIParams: internal.Params{
    86  			"security_group_guid": securityGroupGUID,
    87  			"space_guid":          spaceGUID,
    88  		},
    89  	})
    90  
    91  	return warnings, err
    92  }
    93  
    94  func (client *Client) UpdateSecurityGroupRunningSpace(securityGroupGUID string, spaceGUIDs []string) (Warnings, error) {
    95  	_, warnings, err := client.MakeRequest(RequestParams{
    96  		RequestName: internal.PostSecurityGroupRunningSpaceRequest,
    97  		URIParams:   internal.Params{"security_group_guid": securityGroupGUID},
    98  		RequestBody: resources.RelationshipList{
    99  			GUIDs: spaceGUIDs,
   100  		},
   101  	})
   102  
   103  	return warnings, err
   104  }
   105  
   106  func (client *Client) UpdateSecurityGroupStagingSpace(securityGroupGUID string, spaceGUIDs []string) (Warnings, error) {
   107  	_, warnings, err := client.MakeRequest(RequestParams{
   108  		RequestName: internal.PostSecurityGroupStagingSpaceRequest,
   109  		URIParams:   internal.Params{"security_group_guid": securityGroupGUID},
   110  		RequestBody: resources.RelationshipList{
   111  			GUIDs: spaceGUIDs,
   112  		},
   113  	})
   114  
   115  	return warnings, err
   116  }
   117  
   118  func (client *Client) UpdateSecurityGroup(securityGroup resources.SecurityGroup) (resources.SecurityGroup, Warnings, error) {
   119  	var responseBody resources.SecurityGroup
   120  
   121  	securityGroupGUID := securityGroup.GUID
   122  	securityGroup.GUID = ""
   123  	securityGroup.Name = ""
   124  
   125  	_, warnings, err := client.MakeRequest(RequestParams{
   126  		RequestName:  internal.PatchSecurityGroupRequest,
   127  		URIParams:    internal.Params{"security_group_guid": securityGroupGUID},
   128  		RequestBody:  securityGroup,
   129  		ResponseBody: &responseBody,
   130  	})
   131  
   132  	return responseBody, warnings, err
   133  }
   134  
   135  func (client *Client) DeleteSecurityGroup(securityGroupGUID string) (JobURL, Warnings, error) {
   136  	jobURL, warnings, err := client.MakeRequest(RequestParams{
   137  		RequestName: internal.DeleteSecurityGroupRequest,
   138  		URIParams:   internal.Params{"security_group_guid": securityGroupGUID},
   139  	})
   140  
   141  	return jobURL, warnings, err
   142  }