Skip to content

Commit 3797d2c

Browse files
Add support for events v3
1 parent 09bd6ee commit 3797d2c

File tree

18 files changed

+770
-0
lines changed

18 files changed

+770
-0
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import org.cloudfoundry.reactor.client.v2.userprovidedserviceinstances.ReactorUserProvidedServiceInstances;
9696
import org.cloudfoundry.reactor.client.v2.users.ReactorUsers;
9797
import org.cloudfoundry.reactor.client.v3.applications.ReactorApplicationsV3;
98+
import org.cloudfoundry.reactor.client.v3.auditevents.ReactorAuditEventsV3;
9899
import org.cloudfoundry.reactor.client.v3.builds.ReactorBuilds;
99100
import org.cloudfoundry.reactor.client.v3.deployments.ReactorDeploymentsV3;
100101
import org.cloudfoundry.reactor.client.v3.droplets.ReactorDroplets;
@@ -189,6 +190,12 @@ public Events events() {
189190
return new ReactorEvents(getConnectionContext(), getRootV2(), getTokenProvider());
190191
}
191192

193+
@Override
194+
@Value.Derived
195+
public ReactorAuditEventsV3 eventsV3() {
196+
return new ReactorAuditEventsV3(getConnectionContext(), getRootV2(), getTokenProvider());
197+
}
198+
192199
@Override
193200
@Value.Derived
194201
public FeatureFlags featureFlags() {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2013-2019 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.reactor.client.v3.auditevents;
18+
19+
import org.cloudfoundry.client.v3.auditevents.AuditEventsV3;
20+
import org.cloudfoundry.client.v3.auditevents.GetAuditEventRequest;
21+
import org.cloudfoundry.client.v3.auditevents.GetAuditEventResponse;
22+
import org.cloudfoundry.client.v3.auditevents.ListAuditEventsRequest;
23+
import org.cloudfoundry.client.v3.auditevents.ListAuditEventsResponse;
24+
import org.cloudfoundry.reactor.ConnectionContext;
25+
import org.cloudfoundry.reactor.TokenProvider;
26+
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations;
27+
import reactor.core.publisher.Mono;
28+
29+
public class ReactorAuditEventsV3 extends AbstractClientV3Operations implements AuditEventsV3 {
30+
31+
public ReactorAuditEventsV3(ConnectionContext connectionContext, Mono<String> root, TokenProvider tokenProvider) {
32+
super(connectionContext, root, tokenProvider);
33+
}
34+
35+
@Override
36+
public Mono<GetAuditEventResponse> get(GetAuditEventRequest request) {
37+
return get(request, GetAuditEventResponse.class, uriComponentsBuilder -> uriComponentsBuilder.pathSegment("audit_events", request.getEventId()));
38+
}
39+
40+
@Override
41+
public Mono<ListAuditEventsResponse> list(ListAuditEventsRequest request) {
42+
return get(request, ListAuditEventsResponse.class, uriComponentsBuilder -> uriComponentsBuilder.pathSegment("audit_events"))
43+
.checkpoint();
44+
}
45+
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Copyright 2013-2019 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.reactor.client.v3.auditevents;
18+
19+
import org.cloudfoundry.client.v3.Link;
20+
import org.cloudfoundry.client.v3.Pagination;
21+
import org.cloudfoundry.client.v3.auditevents.AuditEventReference;
22+
import org.cloudfoundry.client.v3.auditevents.AuditEventRelationship;
23+
import org.cloudfoundry.client.v3.auditevents.AuditEventResource;
24+
import org.cloudfoundry.client.v3.auditevents.GetAuditEventRequest;
25+
import org.cloudfoundry.client.v3.auditevents.GetAuditEventResponse;
26+
import org.cloudfoundry.client.v3.auditevents.ListAuditEventsRequest;
27+
import org.cloudfoundry.client.v3.auditevents.ListAuditEventsResponse;
28+
import org.cloudfoundry.reactor.InteractionContext;
29+
import org.cloudfoundry.reactor.TestRequest;
30+
import org.cloudfoundry.reactor.TestResponse;
31+
import org.cloudfoundry.reactor.client.AbstractClientApiTest;
32+
import org.junit.Test;
33+
import reactor.test.StepVerifier;
34+
35+
import java.time.Duration;
36+
37+
import static io.netty.handler.codec.http.HttpMethod.GET;
38+
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
39+
40+
public class ReactorAuditEventsV3Test extends AbstractClientApiTest {
41+
42+
private ReactorAuditEventsV3 events = new ReactorAuditEventsV3(CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER);
43+
44+
@Test
45+
public void get() {
46+
mockRequest(InteractionContext.builder()
47+
.request(TestRequest.builder()
48+
.method(GET).path("/audit_events/a595fe2f-01ff-4965-a50c-290258ab8582")
49+
.build())
50+
.response(TestResponse.builder()
51+
.status(OK)
52+
.payload("fixtures/client/v3/auditevents/GET_{id}_response.json")
53+
.build())
54+
.build());
55+
56+
this.events
57+
.get(GetAuditEventRequest.builder()
58+
.eventId("a595fe2f-01ff-4965-a50c-290258ab8582")
59+
.build())
60+
.as(StepVerifier::create)
61+
.expectNext(GetAuditEventResponse.builder()
62+
.id("a595fe2f-01ff-4965-a50c-290258ab8582")
63+
.createdAt("2016-11-04T16:41:23Z")
64+
.updatedAt("2016-11-04T16:41:23Z")
65+
.type("audit.app.update")
66+
.auditEventActor(AuditEventReference.builder()
67+
.id("test-user-id")
68+
.name("admin")
69+
.type("user")
70+
.build())
71+
.auditEventTarget(AuditEventReference.builder()
72+
.id("test-app-id")
73+
.name("test-app")
74+
.type("app")
75+
.build())
76+
.spaceRelationship(AuditEventRelationship.builder()
77+
.id("test-space-id")
78+
.build())
79+
.organizationRelationship(AuditEventRelationship.builder()
80+
.id("test-organization-id")
81+
.build())
82+
.link("self", Link.builder()
83+
.href("https://api.example.org/v3/audit_events/a595fe2f-01ff-4965-a50c-290258ab8582")
84+
.build())
85+
.build())
86+
.expectComplete()
87+
.verify(Duration.ofSeconds(5));
88+
}
89+
90+
@Test
91+
public void list() {
92+
mockRequest(InteractionContext.builder()
93+
.request(TestRequest.builder()
94+
.method(GET).path("/audit_events")
95+
.build())
96+
.response(TestResponse.builder()
97+
.status(OK)
98+
.payload("fixtures/client/v3/auditevents/GET_response.json")
99+
.build())
100+
.build());
101+
102+
this.events
103+
.list(ListAuditEventsRequest.builder()
104+
.build())
105+
.as(StepVerifier::create)
106+
.expectNext(ListAuditEventsResponse.builder()
107+
.pagination(Pagination.builder()
108+
.totalResults(3)
109+
.totalPages(2)
110+
.first(Link.builder()
111+
.href("https://api.example.org/v3/audit_events?page=1&per_page=2")
112+
.build())
113+
.last(Link.builder()
114+
.href("https://api.example.org/v3/audit_events?page=2&per_page=2")
115+
.build())
116+
.next(Link.builder()
117+
.href("https://api.example.org/v3/audit_events?page=2&per_page=2")
118+
.build())
119+
.build())
120+
.resource(AuditEventResource.builder()
121+
.id("a595fe2f-01ff-4965-a50c-290258ab8582")
122+
.createdAt("2016-11-04T16:41:23Z")
123+
.updatedAt("2016-11-04T16:41:23Z")
124+
.type("audit.app.update")
125+
.auditEventActor(AuditEventReference.builder()
126+
.id("test-user-id")
127+
.name("admin")
128+
.type("user")
129+
.build())
130+
.auditEventTarget(AuditEventReference.builder()
131+
.id("test-app-id")
132+
.name("test-app")
133+
.type("app")
134+
.build())
135+
.spaceRelationship(AuditEventRelationship.builder()
136+
.id("test-space-id")
137+
.build())
138+
.organizationRelationship(AuditEventRelationship.builder()
139+
.id("test-organization-id")
140+
.build())
141+
.link("self", Link.builder()
142+
.href("https://api.example.org/v3/audit_events/a595fe2f-01ff-4965-a50c-290258ab8582")
143+
.build())
144+
.build())
145+
.resource(AuditEventResource.builder()
146+
.id("8a8a14a3-beab-4946-ab6a-3e69741c6405")
147+
.createdAt("2016-11-04T16:41:23Z")
148+
.updatedAt("2016-11-04T16:41:23Z")
149+
.type("audit.app.update")
150+
.auditEventActor(AuditEventReference.builder()
151+
.id("test-user-id")
152+
.name("admin-admin")
153+
.type("user")
154+
.build())
155+
.auditEventTarget(AuditEventReference.builder()
156+
.id("test-app-id")
157+
.name("test-app-2")
158+
.type("app")
159+
.build())
160+
.spaceRelationship(AuditEventRelationship.builder()
161+
.id("test-space-id-1")
162+
.build())
163+
.organizationRelationship(AuditEventRelationship.builder()
164+
.id("test-organization-id-1")
165+
.build())
166+
.link("self", Link.builder()
167+
.href("https://api.example.org/v3/audit_events/8a8a14a3-beab-4946-ab6a-3e69741c6405")
168+
.build())
169+
.build())
170+
.build())
171+
.expectComplete()
172+
.verify(Duration.ofSeconds(5));
173+
}
174+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"pagination": {
3+
"total_results": 3,
4+
"total_pages": 2,
5+
"first": {
6+
"href": "https://api.example.org/v3/audit_events?page=1&per_page=2"
7+
},
8+
"last": {
9+
"href": "https://api.example.org/v3/audit_events?page=2&per_page=2"
10+
},
11+
"next": {
12+
"href": "https://api.example.org/v3/audit_events?page=2&per_page=2"
13+
},
14+
"previous": null
15+
},
16+
"resources": [
17+
{
18+
"guid": "a595fe2f-01ff-4965-a50c-290258ab8582",
19+
"created_at": "2016-11-04T16:41:23Z",
20+
"updated_at": "2016-11-04T16:41:23Z",
21+
"type": "audit.app.update",
22+
"actor": {
23+
"guid": "test-user-id",
24+
"type": "user",
25+
"name": "admin"
26+
},
27+
"target": {
28+
"guid": "test-app-id",
29+
"type": "app",
30+
"name": "test-app"
31+
},
32+
"space": {
33+
"guid": "test-space-id"
34+
},
35+
"organization": {
36+
"guid": "test-organization-id"
37+
},
38+
"links": {
39+
"self": {
40+
"href": "https://api.example.org/v3/audit_events/a595fe2f-01ff-4965-a50c-290258ab8582"
41+
}
42+
}
43+
},
44+
{
45+
"guid": "8a8a14a3-beab-4946-ab6a-3e69741c6405",
46+
"created_at": "2016-11-04T16:41:23Z",
47+
"updated_at": "2016-11-04T16:41:23Z",
48+
"type": "audit.app.update",
49+
"actor": {
50+
"guid": "test-user-id",
51+
"type": "user",
52+
"name": "admin-admin"
53+
},
54+
"target": {
55+
"guid": "test-app-id",
56+
"type": "app",
57+
"name": "test-app-2"
58+
},
59+
"space": {
60+
"guid": "test-space-id-1"
61+
},
62+
"organization": {
63+
"guid": "test-organization-id-1"
64+
},
65+
"links": {
66+
"self": {
67+
"href": "https://api.example.org/v3/audit_events/8a8a14a3-beab-4946-ab6a-3e69741c6405"
68+
}
69+
}
70+
}
71+
]
72+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"guid": "a595fe2f-01ff-4965-a50c-290258ab8582",
3+
"created_at": "2016-11-04T16:41:23Z",
4+
"updated_at": "2016-11-04T16:41:23Z",
5+
"type": "audit.app.update",
6+
"actor": {
7+
"guid": "test-user-id",
8+
"type": "user",
9+
"name": "admin"
10+
},
11+
"target": {
12+
"guid": "test-app-id",
13+
"type": "app",
14+
"name": "test-app"
15+
},
16+
"space": {
17+
"guid": "test-space-id"
18+
},
19+
"organization": {
20+
"guid": "test-organization-id"
21+
},
22+
"links": {
23+
"self": {
24+
"href": "https://api.example.org/v3/audit_events/a595fe2f-01ff-4965-a50c-290258ab8582"
25+
}
26+
}
27+
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.cloudfoundry.client.v2.userprovidedserviceinstances.UserProvidedServiceInstances;
4949
import org.cloudfoundry.client.v2.users.Users;
5050
import org.cloudfoundry.client.v3.applications.ApplicationsV3;
51+
import org.cloudfoundry.client.v3.auditevents.AuditEventsV3;
5152
import org.cloudfoundry.client.v3.builds.Builds;
5253
import org.cloudfoundry.client.v3.deployments.DeploymentsV3;
5354
import org.cloudfoundry.client.v3.droplets.Droplets;
@@ -126,6 +127,11 @@ public interface CloudFoundryClient {
126127
*/
127128
Events events();
128129

130+
/**
131+
* Main entry point to the Cloud Foundry Audit Events V3 Client API
132+
*/
133+
AuditEventsV3 eventsV3();
134+
129135
/**
130136
* Main entry point to the Cloud Foundry Feature Flags Client API
131137
*/

0 commit comments

Comments
 (0)