Skip to content

Commit

Permalink
adding unbind security group
Browse files Browse the repository at this point in the history
  • Loading branch information
radoslav-tomov authored Jul 11, 2023
1 parent 173a169 commit e9bac3a
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse;
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupResponse;
import org.cloudfoundry.client.v3.servicebindings.ServiceBindingsV3;
import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest;
import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsResponse;
import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupResponse;
import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupResponse;
import org.cloudfoundry.client.v3.securitygroups.UnbindRunningSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.UnbindStagingSecurityGroupRequest;
import org.cloudfoundry.reactor.ConnectionContext;
import org.cloudfoundry.reactor.TokenProvider;
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations;
Expand Down Expand Up @@ -116,4 +119,24 @@ public Mono<BindStagingSecurityGroupResponse> bindStagingSecurityGroup(
"staging_spaces"))
.checkpoint();
}

@Override
public Mono<Void> unbindStagingSecurityGroup(
UnbindStagingSecurityGroupRequest request) {
return delete(request, Void.class,
builder -> builder.pathSegment("security_groups", request.getSecurityGroupId(),
"relationships",
"staging_spaces", request.getSpaceId()))
.checkpoint();
}

@Override
public Mono<Void> unbindRunningSecurityGroup(
UnbindRunningSecurityGroupRequest request) {
return delete(request, Void.class,
builder -> builder.pathSegment("security_groups", request.getSecurityGroupId(),
"relationships",
"running_spaces", request.getSpaceId()))
.checkpoint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.cloudfoundry.reactor.TestRequest;
import org.cloudfoundry.reactor.TestResponse;
import org.cloudfoundry.client.v3.securitygroups.Relationships;
import org.cloudfoundry.client.v3.securitygroups.UnbindRunningSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.UnbindStagingSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupResponse;
import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupRequest;
Expand Down Expand Up @@ -54,7 +56,8 @@
import static io.netty.handler.codec.http.HttpMethod.POST;
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;;
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;
import static io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT;;

public final class ReactorSecurityGroupsV3Test extends AbstractClientApiTest {

Expand Down Expand Up @@ -452,4 +455,45 @@ public void bindRunningSecurityGroup() {
.verify(Duration.ofSeconds(5));
}

@Test
public void unbindStagingSecurityGroup() {
mockRequest(InteractionContext.builder()
.request(TestRequest.builder()
.method(DELETE)
.path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/staging_spaces/space-guid-1")
.build())
.response(TestResponse.builder()
.status(NO_CONTENT)
.build())
.build());
this.securityGroups
.unbindStagingSecurityGroup(UnbindStagingSecurityGroupRequest.builder()
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
.spaceId("space-guid-1")
.build())
.as(StepVerifier::create)
.expectNextCount(0)
.verifyComplete();
}

@Test
public void unbindRunningSecurityGroup() {
mockRequest(InteractionContext.builder()
.request(TestRequest.builder()
.method(DELETE)
.path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/running_spaces/space-guid-1")
.build())
.response(TestResponse.builder()
.status(NO_CONTENT)
.build())
.build());
this.securityGroups
.unbindRunningSecurityGroup(UnbindRunningSecurityGroupRequest.builder()
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
.spaceId("space-guid-1")
.build())
.as(StepVerifier::create)
.expectNextCount(0)
.verifyComplete();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2013-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.cloudfoundry.client.v3.securitygroups;

import com.fasterxml.jackson.annotation.JsonIgnore;

public abstract class AbstractUnbindSecurityGroupRequest {

/**
* The Security Group id
*/
@JsonIgnore
abstract String getSecurityGroupId();

/**
* The Space id
*/
@JsonIgnore
abstract String getSpaceId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public interface SecurityGroupsV3 {
* Security Groups</a> request
*
* @param request the Update Security Group request
* @return the response from the List Security Group request
* @return the response from the Update Security Group request
*/
Mono<UpdateSecurityGroupResponse> update(UpdateSecurityGroupRequest request);

Expand All @@ -66,7 +66,7 @@ public interface SecurityGroupsV3 {
* Security Groups</a> request
*
* @param request the Delete Security Group request
* @return the response from the List Security Group request
* @return the response from the Delete Security Group request
*/
Mono<String> delete(DeleteSecurityGroupRequest request);

Expand All @@ -89,4 +89,26 @@ public interface SecurityGroupsV3 {
* @return the response from the Bind Running Security Group request
*/
Mono<BindRunningSecurityGroupResponse> bindRunningSecurityGroup(BindRunningSecurityGroupRequest request);

/**
* Makes the <a href=
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#unbind-a-staging-security-group-from-a-space">Unbind
* Staging
* Security Group</a> request
*
* @param request the Unbind Staging Security Group request
* @return the response from the Unbind staging Security Group request
*/
Mono<Void> unbindStagingSecurityGroup(UnbindStagingSecurityGroupRequest request);

/**
* Makes the <a href=
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#delete-a-security-group">Unbind
* Running
* Security Groups</a> request
*
* @param request the Unbind Staging Running Security Group request
* @return the response from the Unbind Running Security Group request
*/
Mono<Void> unbindRunningSecurityGroup(UnbindRunningSecurityGroupRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2013-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.cloudfoundry.client.v3.securitygroups;

import org.immutables.value.Value;

/**
* The request payload for the Unbind Running Security Group operation
*/
@Value.Immutable
abstract class _UnbindRunningSecurityGroupRequest extends AbstractUnbindSecurityGroupRequest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2013-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.cloudfoundry.client.v3.securitygroups;

import org.immutables.value.Value;

/**
* The request payload for the Unbind Staging Security Group operation
*/
@Value.Immutable
abstract class _UnbindStagingSecurityGroupRequest extends AbstractUnbindSecurityGroupRequest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.cloudfoundry.client.v3.securitygroups;

import org.junit.Test;

public class UnbindRunningSecurityGroupRequestTest {

@Test(expected = IllegalStateException.class)
public void noSecurityGroupId() {
UnbindRunningSecurityGroupRequest.builder()
.build();
}

@Test(expected = IllegalStateException.class)
public void noSpaceId() {
UnbindRunningSecurityGroupRequest.builder()
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
.build();
}

@Test
public void valid() {
UnbindRunningSecurityGroupRequest.builder()
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
.spaceId("space-guid2")
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.cloudfoundry.client.v3.securitygroups;

import org.junit.Test;

public class UnbindStagingSecurityGroupRequestTest {

@Test(expected = IllegalStateException.class)
public void noSecurityGroupId() {
UnbindStagingSecurityGroupRequest.builder()
.build();
}

@Test(expected = IllegalStateException.class)
public void noSpaceId() {
UnbindStagingSecurityGroupRequest.builder()
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
.build();
}

@Test
public void valid() {
UnbindStagingSecurityGroupRequest.builder()
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
.spaceId("space-guid2")
.build();
}
}

0 comments on commit e9bac3a

Please sign in to comment.