Skip to content

Commit 39c1ca6

Browse files
committed
Support include query parameter for list roles
1 parent 013e35d commit 39c1ca6

File tree

6 files changed

+158
-0
lines changed

6 files changed

+158
-0
lines changed

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/roles/_ListRolesRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ abstract class _ListRolesRequest extends PaginatedRequest {
5858
@FilterParameter("user_guids")
5959
abstract List<String> getUserIds();
6060

61+
/**
62+
* The include parameter
63+
*/
64+
@FilterParameter("include")
65+
abstract List<String> getInclude();
66+
6167
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/roles/_ListRolesResponse.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

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

19+
import com.fasterxml.jackson.annotation.JsonProperty;
1920
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import org.cloudfoundry.Nullable;
2022
import org.cloudfoundry.client.v3.PaginatedResponse;
2123
import org.immutables.value.Value;
2224

@@ -27,4 +29,8 @@
2729
@Value.Immutable
2830
abstract class _ListRolesResponse extends PaginatedResponse<RoleResource> {
2931

32+
@JsonProperty("included")
33+
@Nullable
34+
public abstract RoleIncluded getIncluded();
35+
3036
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.roles;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import org.cloudfoundry.Nullable;
22+
import org.cloudfoundry.client.v3.organizations.OrganizationResource;
23+
import org.cloudfoundry.client.v3.spaces.SpaceResource;
24+
import org.cloudfoundry.client.v3.users.UserResource;
25+
import org.immutables.value.Value;
26+
27+
import java.util.List;
28+
29+
30+
@JsonDeserialize
31+
@Value.Immutable
32+
public abstract class _RoleIncluded {
33+
@JsonProperty("users")
34+
@Nullable
35+
public abstract List<UserResource> getUsers();
36+
37+
@JsonProperty("spaces")
38+
@Nullable
39+
public abstract List<SpaceResource> getSpaces();
40+
41+
@JsonProperty("organizations")
42+
@Nullable
43+
public abstract List<OrganizationResource> getOrganizations();
44+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.users;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import org.cloudfoundry.client.v3.Resource;
21+
22+
/**
23+
* Base class for responses that are users
24+
*/
25+
public abstract class User extends Resource {
26+
27+
/**
28+
* The username
29+
*/
30+
@JsonProperty("username")
31+
public abstract String getUsername();
32+
33+
/**
34+
* The presentation name
35+
*/
36+
@JsonProperty("presentation_name")
37+
public abstract String getPresentationName();
38+
39+
/**
40+
* The origin
41+
*/
42+
@JsonProperty("origin")
43+
public abstract String getOrigin();
44+
45+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.users;
18+
19+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20+
import org.immutables.value.Value;
21+
22+
/**
23+
* The Resource response payload for the List Users operation
24+
*/
25+
@JsonDeserialize
26+
@Value.Immutable
27+
abstract class _UserResource extends User {
28+
29+
}

integration-test/src/test/java/org/cloudfoundry/client/v3/RolesTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.cloudfoundry.client.v3.roles.ListRolesRequest;
3333
import org.cloudfoundry.client.v3.roles.RoleRelationships;
3434
import org.cloudfoundry.client.v3.roles.RoleResource;
35+
import org.cloudfoundry.client.v3.users.UserResource;
3536
import org.cloudfoundry.util.JobUtils;
3637
import org.cloudfoundry.util.PaginationUtils;
3738
import org.junit.jupiter.api.Test;
@@ -202,6 +203,33 @@ public void listFilterByOrganizationId() {
202203
.verify(Duration.ofMinutes(5));
203204
}
204205

206+
@Test
207+
public void listIncludeUser() {
208+
String organizationName = this.nameFactory.getOrganizationName();
209+
String userId = this.nameFactory.getUserId();
210+
211+
createOrganizationId(this.cloudFoundryClient, organizationName)
212+
.flatMap(
213+
organizationId ->
214+
requestCreateOrganizationRelationship(
215+
this.cloudFoundryClient, organizationId, userId)
216+
.map(CreateRoleResponse::getId))
217+
.flatMapMany(
218+
roleId ->
219+
this.cloudFoundryClient
220+
.rolesV3()
221+
.list(ListRolesRequest.builder()
222+
.roleId(roleId)
223+
.include("user")
224+
.build())
225+
.flatMapIterable(i -> i.getIncluded().getUsers())
226+
.map(UserResource::getId))
227+
.as(StepVerifier::create)
228+
.expectNext(userId)
229+
.expectComplete()
230+
.verify(Duration.ofMinutes(5));
231+
}
232+
205233
private static Mono<String> createOrganizationId(
206234
CloudFoundryClient cloudFoundryClient, String organizationName) {
207235
return requestCreateOrganization(cloudFoundryClient, organizationName)

0 commit comments

Comments
 (0)