-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding create security group impl and tests
- Loading branch information
1 parent
b5aea46
commit 92fa5db
Showing
7 changed files
with
302 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../main/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2013-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.cloudfoundry.reactor.client.v3.securitygroups; | ||
|
||
import org.cloudfoundry.client.v3.securitygroups.SecurityGroupsV3; | ||
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest; | ||
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse; | ||
import org.cloudfoundry.reactor.ConnectionContext; | ||
import org.cloudfoundry.reactor.TokenProvider; | ||
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations; | ||
import reactor.core.publisher.Mono; | ||
import java.util.Map; | ||
|
||
/** | ||
* The Reactor-based implementation of {@link ServiceBindingsV3} | ||
*/ | ||
public final class ReactorSecurityGroupsV3 extends AbstractClientV3Operations implements SecurityGroupsV3 { | ||
|
||
/** | ||
* Creates an instance | ||
* | ||
* @param connectionContext the {@link ConnectionContext} to use when | ||
* communicating with the server | ||
* @param root the root URI of the server. Typically something like | ||
* {@code https://api.run.pivotal.io}. | ||
* @param tokenProvider the {@link TokenProvider} to use when communicating | ||
* with the server | ||
* @param requestTags map with custom http headers which will be added to | ||
* web request | ||
*/ | ||
public ReactorSecurityGroupsV3(ConnectionContext connectionContext, Mono<String> root, TokenProvider tokenProvider, | ||
Map<String, String> requestTags) { | ||
super(connectionContext, root, tokenProvider, requestTags); | ||
} | ||
|
||
@Override | ||
public Mono<CreateSecurityGroupResponse> create(CreateSecurityGroupRequest request) { | ||
return post(request, CreateSecurityGroupResponse.class, builder -> builder.pathSegment("security_groups")) | ||
.checkpoint(); | ||
|
||
} | ||
|
||
} |
120 changes: 120 additions & 0 deletions
120
...t/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright 2013-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.cloudfoundry.reactor.client.v3.securitygroups; | ||
|
||
import org.cloudfoundry.reactor.InteractionContext; | ||
import org.cloudfoundry.reactor.TestRequest; | ||
import org.cloudfoundry.reactor.TestResponse; | ||
import org.cloudfoundry.client.v3.securitygroups.Relationships; | ||
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest; | ||
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse; | ||
import org.cloudfoundry.client.v3.securitygroups.GloballyEnabled; | ||
import org.cloudfoundry.client.v3.securitygroups.Protocol; | ||
import org.cloudfoundry.client.v3.securitygroups.Rule; | ||
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest; | ||
import org.cloudfoundry.client.v3.ToManyRelationship; | ||
import org.cloudfoundry.reactor.client.AbstractClientApiTest; | ||
import org.junit.Test; | ||
import reactor.test.StepVerifier; | ||
import org.cloudfoundry.client.v3.Link; | ||
import org.cloudfoundry.client.v3.Relationship; | ||
|
||
import java.time.Duration; | ||
import java.util.Collections; | ||
|
||
import static io.netty.handler.codec.http.HttpMethod.POST; | ||
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED; | ||
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED; | ||
|
||
public final class ReactorSecurityGroupsV3Test extends AbstractClientApiTest { | ||
|
||
private final ReactorSecurityGroupsV3 securityGroups = new ReactorSecurityGroupsV3(CONNECTION_CONTEXT, | ||
this.root, | ||
TOKEN_PROVIDER, Collections.emptyMap()); | ||
|
||
@Test | ||
public void create() { | ||
mockRequest(InteractionContext.builder() | ||
.request(TestRequest.builder() | ||
.method(POST).path("/security_groups") | ||
.payload("fixtures/client/v3/security_groups/POST_request.json") | ||
.build()) | ||
.response(TestResponse.builder() | ||
.status(CREATED) | ||
.payload("fixtures/client/v3/security_groups/POST_response.json") | ||
.build()) | ||
.build()); | ||
this.securityGroups | ||
.create(CreateSecurityGroupRequest.builder() | ||
|
||
.rules(Rule.builder() | ||
.protocol(Protocol.TCP) | ||
.destination("10.10.10.0/24") | ||
.ports("443,80,8080") | ||
.build()) | ||
.name("my-group0") | ||
.rules(Rule.builder() | ||
.protocol(Protocol.ICMP) | ||
.destination("10.10.10.0/24") | ||
.description("Allow ping requests to private services") | ||
.type(8) | ||
.code(0) | ||
.build()) | ||
.build()) | ||
.as(StepVerifier::create) | ||
.expectNext(CreateSecurityGroupResponse.builder() | ||
.name("my-group0") | ||
.id("b85a788e-671f-4549-814d-e34cdb2f539a") | ||
.createdAt("2020-02-20T17:42:08Z") | ||
.updatedAt("2020-02-20T17:42:08Z") | ||
.globallyEnabled(GloballyEnabled.builder() | ||
.staging(false) | ||
.running(true) | ||
.build()) | ||
.rules(Rule.builder() | ||
.protocol(Protocol.TCP) | ||
.destination("10.10.10.0/24") | ||
.ports("443,80,8080") | ||
.build()) | ||
.rules(Rule.builder() | ||
.protocol(Protocol.ICMP) | ||
.destination("10.10.10.0/24") | ||
.description("Allow ping requests to private services") | ||
.type(8) | ||
.code(0) | ||
.build()) | ||
.relationships(Relationships.builder() | ||
.stagingSpaces(ToManyRelationship.builder() | ||
.data(Relationship.builder() | ||
.id("space-guid-1") | ||
.build()) | ||
.data(Relationship.builder() | ||
.id("space-guid-2") | ||
.build()) | ||
.build()) | ||
.runningSpaces(ToManyRelationship.builder().build()) | ||
.build()) | ||
.link("self", Link.builder() | ||
.href("https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") | ||
.build()) | ||
.build()) | ||
.expectComplete() | ||
.verify(Duration.ofSeconds(5)); | ||
|
||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...ry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_request.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "my-group0", | ||
"rules": [ | ||
{ | ||
"protocol": "tcp", | ||
"destination": "10.10.10.0/24", | ||
"ports": "443,80,8080" | ||
}, | ||
{ | ||
"protocol": "icmp", | ||
"destination": "10.10.10.0/24", | ||
"type": 8, | ||
"code": 0, | ||
"description": "Allow ping requests to private services" | ||
} | ||
] | ||
} |
44 changes: 44 additions & 0 deletions
44
...y-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"guid": "b85a788e-671f-4549-814d-e34cdb2f539a", | ||
"created_at": "2020-02-20T17:42:08Z", | ||
"updated_at": "2020-02-20T17:42:08Z", | ||
"name": "my-group0", | ||
"globally_enabled": { | ||
"running": true, | ||
"staging": false | ||
}, | ||
"rules": [ | ||
{ | ||
"protocol": "tcp", | ||
"destination": "10.10.10.0/24", | ||
"ports": "443,80,8080" | ||
}, | ||
{ | ||
"protocol": "icmp", | ||
"destination": "10.10.10.0/24", | ||
"type": 8, | ||
"code": 0, | ||
"description": "Allow ping requests to private services" | ||
} | ||
], | ||
"relationships": { | ||
"staging_spaces": { | ||
"data": [ | ||
{ | ||
"guid": "space-guid-1" | ||
}, | ||
{ | ||
"guid": "space-guid-2" | ||
} | ||
] | ||
}, | ||
"running_spaces": { | ||
"data": [] | ||
} | ||
}, | ||
"links": { | ||
"self": { | ||
"href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.