Skip to content

Commit 2d0bc0b

Browse files
adding get security group impl + test
1 parent 20e6b29 commit 2d0bc0b

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.cloudfoundry.client.v3.securitygroups.SecurityGroupsV3;
2020
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest;
2121
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse;
22+
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest;
23+
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse;
2224
import org.cloudfoundry.reactor.ConnectionContext;
2325
import org.cloudfoundry.reactor.TokenProvider;
2426
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations;
@@ -54,4 +56,12 @@ public Mono<CreateSecurityGroupResponse> create(CreateSecurityGroupRequest reque
5456

5557
}
5658

59+
@Override
60+
public Mono<GetSecurityGroupResponse> get(GetSecurityGroupRequest request) {
61+
return get(request, GetSecurityGroupResponse.class,
62+
builder -> builder.pathSegment("security_groups", request.getSecurityGroupId()))
63+
.checkpoint();
64+
65+
}
66+
5767
}

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3Test.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import org.cloudfoundry.client.v3.securitygroups.GloballyEnabled;
2626
import org.cloudfoundry.client.v3.securitygroups.Protocol;
2727
import org.cloudfoundry.client.v3.securitygroups.Rule;
28-
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest;
28+
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest;
29+
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse;
2930
import org.cloudfoundry.client.v3.ToManyRelationship;
3031
import org.cloudfoundry.reactor.client.AbstractClientApiTest;
3132
import org.junit.Test;
@@ -36,9 +37,11 @@
3637
import java.time.Duration;
3738
import java.util.Collections;
3839

40+
import static io.netty.handler.codec.http.HttpMethod.GET;
3941
import static io.netty.handler.codec.http.HttpMethod.POST;
4042
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;
4143
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;
44+
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
4245

4346
public final class ReactorSecurityGroupsV3Test extends AbstractClientApiTest {
4447

@@ -117,4 +120,61 @@ public void create() {
117120

118121
}
119122

123+
@Test
124+
public void get() {
125+
mockRequest(InteractionContext.builder()
126+
.request(TestRequest.builder()
127+
.method(GET)
128+
.path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a")
129+
.build())
130+
.response(TestResponse.builder()
131+
.status(OK)
132+
.payload("fixtures/client/v3/security_groups/GET_{id}_response.json")
133+
.build())
134+
.build());
135+
this.securityGroups
136+
.get(GetSecurityGroupRequest.builder()
137+
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
138+
.build())
139+
.as(StepVerifier::create)
140+
.expectNext(GetSecurityGroupResponse.builder()
141+
.name("my-group0")
142+
.id("b85a788e-671f-4549-814d-e34cdb2f539a")
143+
.createdAt("2020-02-20T17:42:08Z")
144+
.updatedAt("2020-02-20T17:42:08Z")
145+
.globallyEnabled(GloballyEnabled.builder()
146+
.staging(false)
147+
.running(true)
148+
.build())
149+
.rules(Rule.builder()
150+
.protocol(Protocol.TCP)
151+
.destination("10.10.10.0/24")
152+
.ports("443,80,8080")
153+
.build())
154+
.rules(Rule.builder()
155+
.protocol(Protocol.ICMP)
156+
.destination("10.10.10.0/24")
157+
.description("Allow ping requests to private services")
158+
.type(8)
159+
.code(0)
160+
.build())
161+
.relationships(Relationships.builder()
162+
.stagingSpaces(ToManyRelationship.builder()
163+
.data(Relationship.builder()
164+
.id("space-guid-1")
165+
.build())
166+
.data(Relationship.builder()
167+
.id("space-guid-2")
168+
.build())
169+
.build())
170+
.runningSpaces(ToManyRelationship.builder().build())
171+
.build())
172+
.link("self", Link.builder()
173+
.href("https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a")
174+
.build())
175+
.build())
176+
.expectComplete()
177+
.verify(Duration.ofSeconds(5));
178+
}
179+
120180
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"guid": "b85a788e-671f-4549-814d-e34cdb2f539a",
3+
"created_at": "2020-02-20T17:42:08Z",
4+
"updated_at": "2020-02-20T17:42:08Z",
5+
"name": "my-group0",
6+
"globally_enabled": {
7+
"running": true,
8+
"staging": false
9+
},
10+
"rules": [
11+
{
12+
"protocol": "tcp",
13+
"destination": "10.10.10.0/24",
14+
"ports": "443,80,8080"
15+
},
16+
{
17+
"protocol": "icmp",
18+
"destination": "10.10.10.0/24",
19+
"type": 8,
20+
"code": 0,
21+
"description": "Allow ping requests to private services"
22+
}
23+
],
24+
"relationships": {
25+
"staging_spaces": {
26+
"data": [
27+
{
28+
"guid": "space-guid-1"
29+
},
30+
{
31+
"guid": "space-guid-2"
32+
}
33+
]
34+
},
35+
"running_spaces": {
36+
"data": []
37+
}
38+
},
39+
"links": {
40+
"self": {
41+
"href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a"
42+
}
43+
}
44+
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroupsV3.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,14 @@ public interface SecurityGroupsV3 {
3030
*/
3131
Mono<CreateSecurityGroupResponse> create(CreateSecurityGroupRequest request);
3232

33+
/**
34+
* Makes the <a href=
35+
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#get-a-security-group">Get
36+
* a Security Group</a> request.
37+
*
38+
* @param request the get security group request
39+
* @return the response from the get security group request
40+
*/
41+
Mono<GetSecurityGroupResponse> get(GetSecurityGroupRequest request);
42+
3343
}

0 commit comments

Comments
 (0)