Skip to content

Commit 696c8b0

Browse files
adding list security groups impl + api
1 parent 2d0bc0b commit 696c8b0

File tree

10 files changed

+345
-10
lines changed

10 files changed

+345
-10
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse;
2222
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest;
2323
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse;
24+
import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest;
25+
import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsResponse;
2426
import org.cloudfoundry.reactor.ConnectionContext;
2527
import org.cloudfoundry.reactor.TokenProvider;
2628
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations;
@@ -64,4 +66,10 @@ public Mono<GetSecurityGroupResponse> get(GetSecurityGroupRequest request) {
6466

6567
}
6668

69+
@Override
70+
public Mono<ListSecurityGroupsResponse> list(ListSecurityGroupsRequest request) {
71+
return get(request, ListSecurityGroupsResponse.class,
72+
builder -> builder.pathSegment("security_groups"))
73+
.checkpoint();
74+
}
6775
}

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

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616

1717
package org.cloudfoundry.reactor.client.v3.securitygroups;
1818

19+
import org.cloudfoundry.client.v3.Pagination;
1920
import org.cloudfoundry.reactor.InteractionContext;
2021
import org.cloudfoundry.reactor.TestRequest;
2122
import org.cloudfoundry.reactor.TestResponse;
2223
import org.cloudfoundry.client.v3.securitygroups.Relationships;
2324
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest;
2425
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse;
26+
import org.cloudfoundry.client.v3.securitygroups.SecurityGroupResource;
2527
import org.cloudfoundry.client.v3.securitygroups.GloballyEnabled;
28+
import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest;
29+
import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsResponse;
2630
import org.cloudfoundry.client.v3.securitygroups.Protocol;
2731
import org.cloudfoundry.client.v3.securitygroups.Rule;
2832
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest;
@@ -39,7 +43,6 @@
3943

4044
import static io.netty.handler.codec.http.HttpMethod.GET;
4145
import static io.netty.handler.codec.http.HttpMethod.POST;
42-
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;
4346
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;
4447
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
4548

@@ -177,4 +180,89 @@ public void get() {
177180
.verify(Duration.ofSeconds(5));
178181
}
179182

183+
@Test
184+
public void list() {
185+
mockRequest(InteractionContext.builder()
186+
.request(TestRequest.builder()
187+
.method(GET).path("/security_groups")
188+
.build())
189+
.response(TestResponse.builder()
190+
.status(OK)
191+
.payload("fixtures/client/v3/security_groups/GET_response.json")
192+
.build())
193+
.build());
194+
195+
this.securityGroups.list(ListSecurityGroupsRequest.builder().build())
196+
.as(StepVerifier::create)
197+
.expectNext(ListSecurityGroupsResponse.builder()
198+
.pagination(Pagination.builder()
199+
.totalResults(1)
200+
.totalPages(1)
201+
.first(Link.builder()
202+
.href("https://api.example.org/v3/security_groups?page=1&per_page=50")
203+
.build())
204+
.last(Link.builder()
205+
.href("https://api.example.org/v3/security_groups?page=1&per_page=50")
206+
.build())
207+
.build())
208+
.resource(SecurityGroupResource.builder()
209+
.name("my-group0")
210+
.id("b85a788e-671f-4549-814d-e34cdb2f539a")
211+
.createdAt("2020-02-20T17:42:08Z")
212+
.updatedAt("2020-02-20T17:42:08Z")
213+
.globallyEnabled(GloballyEnabled
214+
.builder()
215+
.staging(false)
216+
.running(true)
217+
.build())
218+
.rules(Rule.builder()
219+
.protocol(Protocol.TCP)
220+
.destination("10.10.10.0/24")
221+
.ports("443,80,8080")
222+
.build())
223+
.rules(Rule.builder()
224+
.protocol(Protocol.ICMP)
225+
.destination("10.10.10.0/24")
226+
.description("Allow ping requests to private services")
227+
.type(8)
228+
.code(0)
229+
.build())
230+
.relationships(Relationships.builder()
231+
.stagingSpaces(ToManyRelationship
232+
.builder()
233+
.data(Relationship
234+
.builder()
235+
.id("space-guid-1")
236+
.build())
237+
.data(Relationship
238+
.builder()
239+
.id("space-guid-2")
240+
.build())
241+
.build())
242+
.runningSpaces(ToManyRelationship
243+
.builder()
244+
.build())
245+
.build())
246+
.link("self", Link.builder()
247+
.href("https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a")
248+
.build())
249+
.build())
250+
.resource(SecurityGroupResource.builder()
251+
.name("my-group1")
252+
.id("a89a788e-671f-4549-814d-e34c1b2f533a")
253+
.createdAt("2020-02-20T17:42:08Z")
254+
.updatedAt("2020-02-20T17:42:08Z")
255+
.globallyEnabled(GloballyEnabled
256+
.builder()
257+
.staging(true)
258+
.running(true)
259+
.build())
260+
.link("self", Link.builder()
261+
.href("https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a")
262+
.build())
263+
.build())
264+
.build())
265+
.expectComplete()
266+
.verify(Duration.ofSeconds(5));
267+
}
180268
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"pagination": {
3+
"total_results": 1,
4+
"total_pages": 1,
5+
"first": {
6+
"href": "https://api.example.org/v3/security_groups?page=1&per_page=50"
7+
},
8+
"last": {
9+
"href": "https://api.example.org/v3/security_groups?page=1&per_page=50"
10+
},
11+
"next": null,
12+
"previous": null
13+
},
14+
"resources": [
15+
{
16+
"guid": "b85a788e-671f-4549-814d-e34cdb2f539a",
17+
"created_at": "2020-02-20T17:42:08Z",
18+
"updated_at": "2020-02-20T17:42:08Z",
19+
"name": "my-group0",
20+
"globally_enabled": {
21+
"running": true,
22+
"staging": false
23+
},
24+
"rules": [
25+
{
26+
"protocol": "tcp",
27+
"destination": "10.10.10.0/24",
28+
"ports": "443,80,8080"
29+
},
30+
{
31+
"protocol": "icmp",
32+
"destination": "10.10.10.0/24",
33+
"type": 8,
34+
"code": 0,
35+
"description": "Allow ping requests to private services"
36+
}
37+
],
38+
"relationships": {
39+
"staging_spaces": {
40+
"data": [
41+
{
42+
"guid": "space-guid-1"
43+
},
44+
{
45+
"guid": "space-guid-2"
46+
}
47+
]
48+
},
49+
"running_spaces": {
50+
"data": []
51+
}
52+
},
53+
"links": {
54+
"self": {
55+
"href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a"
56+
}
57+
}
58+
},
59+
{
60+
"guid": "a89a788e-671f-4549-814d-e34c1b2f533a",
61+
"created_at": "2020-02-20T17:42:08Z",
62+
"updated_at": "2020-02-20T17:42:08Z",
63+
"name": "my-group1",
64+
"globally_enabled": {
65+
"running": true,
66+
"staging": true
67+
},
68+
"rules": [],
69+
"relationships": {
70+
"staging_spaces": {
71+
"data": []
72+
},
73+
"running_spaces": {
74+
"data": []
75+
}
76+
},
77+
"links": {
78+
"self": {
79+
"href": "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a"
80+
}
81+
}
82+
}
83+
]
84+
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,18 @@ public abstract class SecurityGroup extends Resource {
3939
* The globally enabled
4040
*/
4141
@JsonProperty("globally_enabled")
42-
@Nullable
4342
abstract GloballyEnabled getGloballyEnabled();
4443

4544
/**
4645
* The rules
4746
*/
4847
@JsonProperty("rules")
49-
@Nullable
5048
abstract List<Rule> getRules();
5149

5250
/**
5351
* The space relationships
5452
*/
5553
@JsonProperty("relationships")
56-
@Nullable
5754
abstract Relationships getRelationships();
5855

5956
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public interface SecurityGroupsV3 {
2525
* "https://apidocs.cloudfoundry.org/latest-release/security_groups/creating_a_security_group.html">Creating
2626
* a Security Group</a> request.
2727
*
28-
* @param request the create security group request
29-
* @return the response from the create security group request
28+
* @param request the Create Security Group request
29+
* @return the response from the Create Security Group request
3030
*/
3131
Mono<CreateSecurityGroupResponse> create(CreateSecurityGroupRequest request);
3232

@@ -35,9 +35,20 @@ public interface SecurityGroupsV3 {
3535
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#get-a-security-group">Get
3636
* a Security Group</a> request.
3737
*
38-
* @param request the get security group request
39-
* @return the response from the get security group request
38+
* @param request the Get Security Group request
39+
* @return the response from the Get Security Group request
4040
*/
4141
Mono<GetSecurityGroupResponse> get(GetSecurityGroupRequest request);
4242

43+
/**
44+
* Makes the <a href=
45+
*
46+
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#list-security-groups">List
47+
* Security Groups</a> request
48+
*
49+
* @param request the List Security Group request
50+
* @return the response from the List Security Group request
51+
*/
52+
Mono<ListSecurityGroupsResponse> list(ListSecurityGroupsRequest request);
53+
4354
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package org.cloudfoundry.client.v3.securitygroups;
1818

19-
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
19+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2020
import com.fasterxml.jackson.annotation.JsonIgnore;
2121
import org.immutables.value.Value;
2222

2323
/**
2424
* The request payload for the Get Security Group operation
2525
*/
26-
@JsonDeserialize
26+
@JsonSerialize
2727
@Value.Immutable
2828
abstract class _GetSecurityGroupRequest {
2929

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2013-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v3.securitygroups;
18+
19+
import org.cloudfoundry.client.v2.PaginatedRequest;
20+
import org.immutables.value.Value;
21+
import org.cloudfoundry.client.v3.FilterParameter;
22+
import org.cloudfoundry.Nullable;
23+
import java.util.List;
24+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;;
25+
26+
/**
27+
* The request payload for the List Security Group operation
28+
*/
29+
@JsonSerialize
30+
@Value.Immutable
31+
abstract class _ListSecurityGroupsRequest extends PaginatedRequest {
32+
33+
/**
34+
* The security group ids filter
35+
*/
36+
@FilterParameter("guids")
37+
abstract List<String> getSecurityGroupIds();
38+
39+
/**
40+
* The security group names filter
41+
*/
42+
@FilterParameter("names")
43+
abstract List<String> getNames();
44+
45+
/**
46+
* the security group globally enabled running filter
47+
*/
48+
@FilterParameter("globally_enabled_running")
49+
@Nullable
50+
abstract Boolean getGloballyEnabledRunning();
51+
52+
/**
53+
* the security group globally enabled staging filter
54+
*/
55+
@FilterParameter("globally_enabled_staging")
56+
@Nullable
57+
abstract Boolean getGloballyEnabledStagingBoolean();
58+
59+
/**
60+
* the security group running_space_guids filter
61+
*/
62+
@FilterParameter("running_space_guids")
63+
abstract List<String> getRunningSpaceIds();
64+
65+
/**
66+
* the security group staging_space_guids filter
67+
*/
68+
@FilterParameter("staging_space_guids")
69+
abstract List<String> getStagingSpaceIds();
70+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2013-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v3.securitygroups;
18+
19+
import org.immutables.value.Value;
20+
21+
import org.cloudfoundry.client.v3.PaginatedResponse;
22+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
23+
24+
/**
25+
* The response payload for the List Security Groups operation
26+
*/
27+
@JsonDeserialize
28+
@Value.Immutable
29+
abstract class _ListSecurityGroupsResponse extends PaginatedResponse<SecurityGroup> {
30+
31+
}

0 commit comments

Comments
 (0)