MCPcopy Create free account
hub / github.com/cloudfoundry/cli / UnbindSecurityGroup

Method UnbindSecurityGroup

actor/v7action/security_group.go:184–228  ·  view source on GitHub ↗
(securityGroupName string, orgName string, spaceName string, lifecycle constant.SecurityGroupLifecycle)

Source from the content-addressed store, hash-verified

182}
183
184func (actor Actor) UnbindSecurityGroup(securityGroupName string, orgName string, spaceName string, lifecycle constant.SecurityGroupLifecycle) (Warnings, error) {
185 var allWarnings Warnings
186
187 org, warnings, err := actor.GetOrganizationByName(orgName)
188 allWarnings = append(allWarnings, warnings...)
189 if err != nil {
190 return allWarnings, err
191 }
192
193 space, warnings, err := actor.GetSpaceByNameAndOrganization(spaceName, org.GUID)
194 allWarnings = append(allWarnings, warnings...)
195 if err != nil {
196 return allWarnings, err
197 }
198
199 securityGroup, warnings, err := actor.GetSecurityGroup(securityGroupName)
200 allWarnings = append(allWarnings, warnings...)
201 if err != nil {
202 return allWarnings, err
203 }
204
205 var ccv3Warnings ccv3.Warnings
206 switch lifecycle {
207 case constant.SecurityGroupLifecycleRunning:
208 ccv3Warnings, err = actor.CloudControllerClient.UnbindSecurityGroupRunningSpace(securityGroup.GUID, space.GUID)
209 case constant.SecurityGroupLifecycleStaging:
210 ccv3Warnings, err = actor.CloudControllerClient.UnbindSecurityGroupStagingSpace(securityGroup.GUID, space.GUID)
211 default:
212 return allWarnings, actionerror.InvalidLifecycleError{Lifecycle: string(lifecycle)}
213 }
214
215 allWarnings = append(allWarnings, ccv3Warnings...)
216
217 if err != nil {
218 if _, isNotBoundError := err.(ccerror.SecurityGroupNotBound); isNotBoundError {
219 return allWarnings, actionerror.SecurityGroupNotBoundToSpaceError{
220 Name: securityGroupName,
221 Space: spaceName,
222 Lifecycle: lifecycle,
223 }
224 }
225 }
226
227 return allWarnings, err
228}
229
230func (actor Actor) GetGlobalStagingSecurityGroups() ([]resources.SecurityGroup, Warnings, error) {
231 stagingSecurityGroups, warnings, err := actor.CloudControllerClient.GetSecurityGroups(ccv3.Query{Key: ccv3.GloballyEnabledStaging, Values: []string{"true"}})

Callers

nothing calls this directly

Implementers 1

FakeActorcommand/v7/v7fakes/fake_actor.go

Tested by

no test coverage detected