Skip to content

Commit dba4242

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

File tree

6 files changed

+165
-0
lines changed

6 files changed

+165
-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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.Metadata;
21+
import org.cloudfoundry.client.v3.Resource;
22+
23+
/**
24+
* Base class for responses that are users
25+
*/
26+
public abstract class User extends Resource {
27+
28+
/**
29+
* The metadata
30+
*/
31+
@JsonProperty("metadata")
32+
public abstract Metadata getMetadata();
33+
34+
/**
35+
* The username
36+
*/
37+
@JsonProperty("username")
38+
public abstract String getUsername();
39+
40+
/**
41+
* The presentation name
42+
*/
43+
@JsonProperty("presentation_name")
44+
public abstract String getPresentationName();
45+
46+
/**
47+
* The origin
48+
*/
49+
@JsonProperty("origin")
50+
public abstract String getOrigin();
51+
}
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: 29 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,34 @@ 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(
222+
ListRolesRequest.builder()
223+
.roleId(roleId)
224+
.include("user")
225+
.build())
226+
.flatMapIterable(i -> i.getIncluded().getUsers())
227+
.map(UserResource::getId))
228+
.as(StepVerifier::create)
229+
.expectNext(userId)
230+
.expectComplete()
231+
.verify(Duration.ofMinutes(5));
232+
}
233+
205234
private static Mono<String> createOrganizationId(
206235
CloudFoundryClient cloudFoundryClient, String organizationName) {
207236
return requestCreateOrganization(cloudFoundryClient, organizationName)

0 commit comments

Comments
 (0)