diff --git a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java index 90833d4e66..96183944c1 100644 --- a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java +++ b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java @@ -34,6 +34,7 @@ import org.cloudfoundry.client.v2.routemappings.RouteMappings; import org.cloudfoundry.client.v2.routes.Routes; import org.cloudfoundry.client.v2.securitygroups.SecurityGroups; +import org.cloudfoundry.client.v3.securitygroups.SecurityGroupsV3; import org.cloudfoundry.client.v2.servicebindings.ServiceBindingsV2; import org.cloudfoundry.client.v2.servicebrokers.ServiceBrokers; import org.cloudfoundry.client.v2.serviceinstances.ServiceInstances; @@ -91,6 +92,7 @@ import org.cloudfoundry.reactor.client.v2.routemappings.ReactorRouteMappings; import org.cloudfoundry.reactor.client.v2.routes.ReactorRoutes; import org.cloudfoundry.reactor.client.v2.securitygroups.ReactorSecurityGroups; +import org.cloudfoundry.reactor.client.v3.securitygroups.ReactorSecurityGroupsV3; import org.cloudfoundry.reactor.client.v2.servicebindings.ReactorServiceBindingsV2; import org.cloudfoundry.reactor.client.v2.servicebrokers.ReactorServiceBrokers; import org.cloudfoundry.reactor.client.v2.serviceinstances.ReactorServiceInstances; @@ -151,7 +153,8 @@ public AdminV3 adminV3() { @Override @Value.Derived public ApplicationUsageEvents applicationUsageEvents() { - return new ReactorApplicationUsageEvents(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorApplicationUsageEvents(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -228,7 +231,8 @@ public Droplets droplets() { @Override @Value.Derived public EnvironmentVariableGroups environmentVariableGroups() { - return new ReactorEnvironmentVariableGroups(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorEnvironmentVariableGroups(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -270,7 +274,8 @@ public JobsV3 jobsV3() { @Override @Value.Derived public OrganizationQuotaDefinitions organizationQuotaDefinitions() { - return new ReactorOrganizationQuotaDefinitions(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorOrganizationQuotaDefinitions(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -345,6 +350,12 @@ public SecurityGroups securityGroups() { return new ReactorSecurityGroups(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); } + @Override + @Value.Derived + public SecurityGroupsV3 securityGroupsV3() { + return new ReactorSecurityGroupsV3(getConnectionContext(), getRootV3(), getTokenProvider(), getRequestTags()); + } + @Override @Value.Derived public ServiceBindingsV2 serviceBindingsV2() { @@ -366,7 +377,7 @@ public ServiceBrokers serviceBrokers() { @Override @Value.Derived public ServiceBrokersV3 serviceBrokersV3() { - return new ReactorServiceBrokersV3(getConnectionContext(), getRootV3(), getTokenProvider(), getRequestTags()); + return new ReactorServiceBrokersV3(getConnectionContext(), getRootV3(), getTokenProvider(), getRequestTags()); } @Override @@ -396,7 +407,8 @@ public ServiceOfferingsV3 serviceOfferingsV3() { @Override @Value.Derived public ServicePlanVisibilities servicePlanVisibilities() { - return new ReactorServicePlanVisibilities(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorServicePlanVisibilities(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -432,7 +444,8 @@ public SharedDomains sharedDomains() { @Override @Value.Derived public SpaceQuotaDefinitions spaceQuotaDefinitions() { - return new ReactorSpaceQuotaDefinitions(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorSpaceQuotaDefinitions(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -468,7 +481,8 @@ public Tasks tasks() { @Override @Value.Derived public UserProvidedServiceInstances userProvidedServiceInstances() { - return new ReactorUserProvidedServiceInstances(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorUserProvidedServiceInstances(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -483,7 +497,8 @@ public Users users() { abstract ConnectionContext getConnectionContext(); /** - * Map of http header name and value which will be added to every request to the controller + * Map of http header name and value which will be added to every request to the + * controller */ @Value.Default Map getRequestTags() { diff --git a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3.java b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3.java new file mode 100644 index 0000000000..23d64c3425 --- /dev/null +++ b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3.java @@ -0,0 +1,151 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups.GetSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupResponse; +import org.cloudfoundry.client.v3.servicebindings.ServiceBindingsV3; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.UnbindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UnbindStagingSecurityGroupRequest; +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 root, + TokenProvider tokenProvider, Map requestTags) { + super(connectionContext, root, tokenProvider, requestTags); + } + + @Override + public Mono create(CreateSecurityGroupRequest request) { + return post(request, CreateSecurityGroupResponse.class, + builder -> builder.pathSegment("security_groups")).checkpoint(); + + } + + @Override + public Mono get(GetSecurityGroupRequest request) { + return get(request, GetSecurityGroupResponse.class, builder -> builder + .pathSegment("security_groups", request.getSecurityGroupId())) + .checkpoint(); + + } + + @Override + public Mono list(ListSecurityGroupsRequest request) { + return get(request, ListSecurityGroupsResponse.class, + builder -> builder.pathSegment("security_groups")).checkpoint(); + } + + @Override + public Mono update(UpdateSecurityGroupRequest request) { + return patch(request, UpdateSecurityGroupResponse.class, builder -> builder + .pathSegment("security_groups", request.getSecurityGroupId())) + .checkpoint(); + } + + @Override + public Mono delete(DeleteSecurityGroupRequest request) { + return delete(request, builder -> builder.pathSegment("security_groups", + request.getSecurityGroupId())).checkpoint(); + + } + + @Override + public Mono bindRunningSecurityGroup( + BindRunningSecurityGroupRequest request) { + return post(request, BindRunningSecurityGroupResponse.class, + builder -> builder.pathSegment("security_groups", + request.getSecurityGroupId(), "relationships", + "running_spaces")).checkpoint(); + } + + @Override + public Mono bindStagingSecurityGroup( + BindStagingSecurityGroupRequest request) { + return post(request, BindStagingSecurityGroupResponse.class, + builder -> builder.pathSegment("security_groups", + request.getSecurityGroupId(), "relationships", + "staging_spaces")).checkpoint(); + } + + @Override + public Mono unbindStagingSecurityGroup(UnbindStagingSecurityGroupRequest request) { + return delete(request, Void.class, + builder -> builder.pathSegment("security_groups", + request.getSecurityGroupId(), "relationships", + "staging_spaces", request.getSpaceId())) + .checkpoint(); + } + + @Override + public Mono unbindRunningSecurityGroup(UnbindRunningSecurityGroupRequest request) { + return delete(request, Void.class, + builder -> builder.pathSegment("security_groups", + request.getSecurityGroupId(), "relationships", + "running_spaces", request.getSpaceId())) + .checkpoint(); + } + + @Override + public Mono listRunning( + ListRunningSecurityGroupsRequest request) { + return get(request, ListRunningSecurityGroupsResponse.class, + builder -> builder.pathSegment("spaces", request.getSpaceId(), + "running_security_groups")).checkpoint(); + } + + @Override + public Mono listStaging( + ListStagingSecurityGroupsRequest request) { + return get(request, ListStagingSecurityGroupsResponse.class, + builder -> builder.pathSegment("spaces", request.getSpaceId(), + "staging_security_groups")).checkpoint(); + } +} diff --git a/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3Test.java b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3Test.java new file mode 100644 index 0000000000..efe402f6a2 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3Test.java @@ -0,0 +1,707 @@ +/* + * 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.Pagination; +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.UnbindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UnbindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.SecurityGroupResource; +import org.cloudfoundry.client.v3.securitygroups.GloballyEnabled; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.Protocol; +import org.cloudfoundry.client.v3.securitygroups.Rule; +import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse; +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.GET; +import static io.netty.handler.codec.http.HttpMethod.DELETE; +import static io.netty.handler.codec.http.HttpMethod.PATCH; +import static io.netty.handler.codec.http.HttpMethod.POST; +import static io.netty.handler.codec.http.HttpResponseStatus.CREATED; +import static io.netty.handler.codec.http.HttpResponseStatus.OK; +import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED; +import static io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT; + +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)); + + } + + @Test + public void get() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(GET) + .path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .response(TestResponse.builder() + .status(OK) + .payload("fixtures/client/v3/security_groups/GET_{id}_response.json") + .build()) + .build()); + this.securityGroups + .get(GetSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .as(StepVerifier::create) + .expectNext(GetSecurityGroupResponse.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)); + } + + @Test + public void list() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(GET).path("/security_groups") + .build()) + .response(TestResponse.builder() + .status(OK) + .payload("fixtures/client/v3/security_groups/GET_response.json") + .build()) + .build()); + + this.securityGroups.list(ListSecurityGroupsRequest.builder().build()) + .as(StepVerifier::create) + .expectNext(ListSecurityGroupsResponse.builder() + .pagination(Pagination.builder() + .totalResults(1) + .totalPages(1) + .first(Link.builder() + .href("https://api.example.org/v3/security_groups?page=1&per_page=50") + .build()) + .last(Link.builder() + .href("https://api.example.org/v3/security_groups?page=1&per_page=50") + .build()) + .build()) + .resource(SecurityGroupResource.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()) + .resource(SecurityGroupResource.builder() + .name("my-group1") + .id("a89a788e-671f-4549-814d-e34c1b2f533a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .relationships(Relationships.builder() + .stagingSpaces(ToManyRelationship + .builder().build()) + .runningSpaces(ToManyRelationship + .builder().build()) + + .build()) + .globallyEnabled(GloballyEnabled + .builder() + .staging(true) + .running(true) + .build()) + .globallyEnabled(GloballyEnabled + .builder() + .staging(true) + .running(true) + .build()) + .link("self", Link.builder() + .href("https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a") + .build()) + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void update() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(PATCH) + .path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .payload("fixtures/client/v3/security_groups/PATCH_{id}_request.json") + .build()) + .response(TestResponse.builder() + .status(OK) + .payload("fixtures/client/v3/security_groups/PATCH_{id}_response.json") + .build()) + .build()); + this.securityGroups + .update(UpdateSecurityGroupRequest.builder() + .name("my-group0") + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .globallyEnabled(GloballyEnabled.builder() + .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()) + + .build()) + .as(StepVerifier::create) + .expectNext(UpdateSecurityGroupResponse.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)); + + } + + @Test + public void delete() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(DELETE) + .path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .response(TestResponse.builder() + .status(ACCEPTED) + .header("Location", + "https://api.example.org/v3/jobs/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .build()); + + this.securityGroups + .delete(DeleteSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .as(StepVerifier::create) + .expectNext("b85a788e-671f-4549-814d-e34cdb2f539a") + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void bindStagingSecurityGroup() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(POST) + .path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/staging_spaces") + .payload("fixtures/client/v3/security_groups/bind_staging/POST_request.json") + .build()) + .response(TestResponse.builder() + .status(OK) + .payload("fixtures/client/v3/security_groups/bind_staging/POST_response.json") + .build()) + .build()); + this.securityGroups.bindStagingSecurityGroup(BindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .boundSpaces(Relationship.builder().id("space-guid1").build()) + .boundSpaces(Relationship.builder().id("space-guid2").build()) + + .build()) + .as(StepVerifier::create) + .expectNext(BindStagingSecurityGroupResponse.builder() + .boundSpaces(Relationship.builder().id("space-guid1").build()) + .boundSpaces(Relationship.builder().id("space-guid2").build()) + .boundSpaces(Relationship.builder().id("previous-space-guid").build()) + .link("self", Link.builder() + .href("https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/staging_spaces") + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void bindRunningSecurityGroup() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(POST) + .path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/running_spaces") + .payload("fixtures/client/v3/security_groups/bind_running/POST_request.json") + .build()) + .response(TestResponse.builder() + .status(OK) + .payload("fixtures/client/v3/security_groups/bind_running/POST_response.json") + .build()) + .build()); + this.securityGroups.bindRunningSecurityGroup(BindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .boundSpaces(Relationship.builder().id("space-guid1").build()) + .boundSpaces(Relationship.builder().id("space-guid2").build()) + .build()) + .as(StepVerifier::create) + .expectNext(BindRunningSecurityGroupResponse.builder() + .boundSpaces(Relationship.builder().id("space-guid1").build()) + .boundSpaces(Relationship.builder().id("space-guid2").build()) + .boundSpaces(Relationship.builder().id("previous-space-guid").build()) + .link("self", Link.builder() + .href("https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/running_spaces") + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void unbindStagingSecurityGroup() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(DELETE) + .path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/staging_spaces/space-guid-1") + .build()) + .response(TestResponse.builder() + .status(NO_CONTENT) + .build()) + .build()); + this.securityGroups + .unbindStagingSecurityGroup(UnbindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .spaceId("space-guid-1") + .build()) + .as(StepVerifier::create) + .expectNextCount(0) + .verifyComplete(); + } + + @Test + public void unbindRunningSecurityGroup() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(DELETE) + .path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/running_spaces/space-guid-1") + .build()) + .response(TestResponse.builder() + .status(NO_CONTENT) + .build()) + .build()); + this.securityGroups + .unbindRunningSecurityGroup(UnbindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .spaceId("space-guid-1") + .build()) + .as(StepVerifier::create) + .expectNextCount(0) + .verifyComplete(); + } + + @Test + public void listRunning() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(GET) + .path("/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups") + .build()) + .response(TestResponse.builder() + .status(OK) + .payload("fixtures/client/v3/security_groups/GET_running_{id}_response.json") + .build()) + .build()); + + this.securityGroups + .listRunning(ListRunningSecurityGroupsRequest.builder() + .spaceId("c5048979-53b9-4d2a-9fca-78e6bc07c041").build()) + .as(StepVerifier::create) + .expectNext(ListRunningSecurityGroupsResponse.builder() + .pagination(Pagination.builder() + .totalResults(1) + .totalPages(1) + .first(Link.builder() + .href("https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups?page=1&per_page=50") + .build()) + .last(Link.builder() + .href("https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups?page=1&per_page=50") + .build()) + .build()) + .resource(SecurityGroupResource.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() + + .build()) + .runningSpaces(ToManyRelationship + .builder() + .data(Relationship + .builder() + .id("space-guid-1") + .build()) + .data(Relationship + .builder() + .id("space-guid-2") + .build()) + .build()) + .build()) + .link("self", Link.builder() + .href("https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .build()) + .resource(SecurityGroupResource.builder() + .name("my-group1") + .id("a89a788e-671f-4549-814d-e34c1b2f533a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .relationships(Relationships.builder() + .stagingSpaces(ToManyRelationship + .builder().build()) + .runningSpaces(ToManyRelationship + .builder().build()) + + .build()) + .globallyEnabled(GloballyEnabled + .builder() + .staging(true) + .running(true) + .build()) + .globallyEnabled(GloballyEnabled + .builder() + .staging(true) + .running(true) + .build()) + .link("self", Link.builder() + .href("https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a") + .build()) + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void listStaging() { + mockRequest(InteractionContext.builder() + .request(TestRequest.builder() + .method(GET) + .path("/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups") + .build()) + .response(TestResponse.builder() + .status(OK) + .payload("fixtures/client/v3/security_groups/GET_staging_{id}_response.json") + .build()) + .build()); + + this.securityGroups + .listStaging(ListStagingSecurityGroupsRequest.builder() + .spaceId("c5048979-53b9-4d2a-9fca-78e6bc07c041").build()) + .as(StepVerifier::create) + .expectNext(ListStagingSecurityGroupsResponse.builder() + .pagination(Pagination.builder() + .totalResults(1) + .totalPages(1) + .first(Link.builder() + .href("https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups?page=1&per_page=50") + .build()) + .last(Link.builder() + .href("https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups?page=1&per_page=50") + .build()) + .build()) + .resource(SecurityGroupResource.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(true) + .running(false) + .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()) + .resource(SecurityGroupResource.builder() + .name("my-group1") + .id("a89a788e-671f-4549-814d-e34c1b2f533a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .relationships(Relationships.builder() + .stagingSpaces(ToManyRelationship + .builder().build()) + .runningSpaces(ToManyRelationship + .builder().build()) + + .build()) + .globallyEnabled(GloballyEnabled + .builder() + .staging(true) + .running(true) + .build()) + .globallyEnabled(GloballyEnabled + .builder() + .staging(true) + .running(true) + .build()) + .link("self", Link.builder() + .href("https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a") + .build()) + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_response.json new file mode 100644 index 0000000000..9e39d26c2a --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_response.json @@ -0,0 +1,84 @@ +{ + "pagination": { + "total_results": 1, + "total_pages": 1, + "first": { + "href": "https://api.example.org/v3/security_groups?page=1&per_page=50" + }, + "last": { + "href": "https://api.example.org/v3/security_groups?page=1&per_page=50" + }, + "next": null, + "previous": null + }, + "resources": [ + { + "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" + } + } + }, + { + "guid": "a89a788e-671f-4549-814d-e34c1b2f533a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group1", + "globally_enabled": { + "running": true, + "staging": true + }, + "rules": [], + "relationships": { + "staging_spaces": { + "data": [] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a" + } + } + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_running_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_running_{id}_response.json new file mode 100644 index 0000000000..c02b6b9526 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_running_{id}_response.json @@ -0,0 +1,84 @@ +{ + "pagination": { + "total_results": 1, + "total_pages": 1, + "first": { + "href": "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups?page=1&per_page=50" + }, + "last": { + "href": "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups?page=1&per_page=50" + }, + "next": null, + "previous": null + }, + "resources": [ + { + "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": [] + }, + "running_spaces": { + "data": [ + { + "guid": "space-guid-1" + }, + { + "guid": "space-guid-2" + } + ] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a" + } + } + }, + { + "guid": "a89a788e-671f-4549-814d-e34c1b2f533a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group1", + "globally_enabled": { + "running": true, + "staging": true + }, + "rules": [], + "relationships": { + "staging_spaces": { + "data": [] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a" + } + } + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_staging_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_staging_{id}_response.json new file mode 100644 index 0000000000..b9dede1538 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_staging_{id}_response.json @@ -0,0 +1,84 @@ +{ + "pagination": { + "total_results": 1, + "total_pages": 1, + "first": { + "href": "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups?page=1&per_page=50" + }, + "last": { + "href": "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups?page=1&per_page=50" + }, + "next": null, + "previous": null + }, + "resources": [ + { + "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": false, + "staging": true + }, + "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" + } + } + }, + { + "guid": "a89a788e-671f-4549-814d-e34c1b2f533a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group1", + "globally_enabled": { + "running": true, + "staging": true + }, + "rules": [], + "relationships": { + "staging_spaces": { + "data": [] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a" + } + } + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_{id}_response.json new file mode 100644 index 0000000000..5c1290a8e3 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_{id}_response.json @@ -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" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_request.json new file mode 100644 index 0000000000..7b146d9a9b --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_request.json @@ -0,0 +1,20 @@ +{ + "name": "my-group0", + "globally_enabled": { + "running": true + }, + "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" + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_response.json new file mode 100644 index 0000000000..5c1290a8e3 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_response.json @@ -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" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_request.json new file mode 100644 index 0000000000..35e74431db --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_request.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_response.json new file mode 100644 index 0000000000..5c1290a8e3 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_response.json @@ -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" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_request.json new file mode 100644 index 0000000000..eaa31060ca --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_request.json @@ -0,0 +1,10 @@ +{ + "data": [ + { + "guid": "space-guid1" + }, + { + "guid": "space-guid2" + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_response.json new file mode 100644 index 0000000000..35ce11babf --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_response.json @@ -0,0 +1,18 @@ +{ + "data": [ + { + "guid": "space-guid1" + }, + { + "guid": "space-guid2" + }, + { + "guid": "previous-space-guid" + } + ], + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/running_spaces" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_request.json new file mode 100644 index 0000000000..eaa31060ca --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_request.json @@ -0,0 +1,10 @@ +{ + "data": [ + { + "guid": "space-guid1" + }, + { + "guid": "space-guid2" + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_response.json new file mode 100644 index 0000000000..06b4b5914d --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_response.json @@ -0,0 +1,18 @@ +{ + "data": [ + { + "guid": "space-guid1" + }, + { + "guid": "space-guid2" + }, + { + "guid": "previous-space-guid" + } + ], + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/staging_spaces" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java index 04957c0d0c..b691c73958 100644 --- a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java @@ -63,6 +63,7 @@ import org.cloudfoundry.client.v3.resourcematch.ResourceMatchV3; import org.cloudfoundry.client.v3.roles.RolesV3; import org.cloudfoundry.client.v3.routes.RoutesV3; +import org.cloudfoundry.client.v3.securitygroups.SecurityGroupsV3; import org.cloudfoundry.client.v3.serviceinstances.ServiceInstancesV3; import org.cloudfoundry.client.v3.servicebindings.ServiceBindingsV3; import org.cloudfoundry.client.v3.servicebrokers.ServiceBrokersV3; @@ -247,6 +248,11 @@ public interface CloudFoundryClient { */ SecurityGroups securityGroups(); + /** + * Main entry point to the Cloud Foundry Security Groups V3 Client API + */ + SecurityGroupsV3 securityGroupsV3(); + /** * Main entry point to the Cloud Foundry Service Bindings V2 Client API */ @@ -348,7 +354,8 @@ public interface CloudFoundryClient { Tasks tasks(); /** - * Main entry point to the Cloud Foundry User Provided Service Instances Client API + * Main entry point to the Cloud Foundry User Provided Service Instances Client + * API */ UserProvidedServiceInstances userProvidedServiceInstances(); diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupRequest.java new file mode 100644 index 0000000000..1979a6812e --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupRequest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import java.util.List; +import org.cloudfoundry.client.v3.Relationship; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonSerialize +public abstract class AbstractBindSecurityGroupRequest { + + /** + * The Security Group id + */ + @JsonIgnore + abstract String getSecurityGroupId(); + + /** + * A relationship to the spaces where the security_group is applied to + * applications during runtime + */ + @JsonProperty("data") + abstract List getBoundSpaces(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupResponse.java new file mode 100644 index 0000000000..effa617eae --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupResponse.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import java.util.List; +import java.util.Map; +import org.cloudfoundry.AllowNulls; +import org.cloudfoundry.client.v3.Link; +import org.cloudfoundry.client.v3.Relationship; + + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize +public abstract class AbstractBindSecurityGroupResponse { + + /** + * A relationship to the spaces where the security_group is applied to applications during + * runtime + */ + @JsonProperty("data") + abstract List getBoundSpaces(); + + /** + * The links + */ + @AllowNulls + @JsonProperty("links") + public abstract Map getLinks(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractListSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractListSecurityGroupRequest.java new file mode 100644 index 0000000000..b0d6e8e573 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractListSecurityGroupRequest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import java.util.List; + +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v2.PaginatedRequest; +import org.cloudfoundry.client.v3.FilterParameter; +import com.fasterxml.jackson.annotation.JsonIgnore; + +public abstract class AbstractListSecurityGroupRequest extends PaginatedRequest { + + /** + * The Space id + */ + @JsonIgnore + abstract String getSpaceId(); + + /** + * The security group ids filter + */ + @FilterParameter("guids") + @Nullable + abstract List getSecurityGroupIds(); + + /** + * The security group names filter + */ + @FilterParameter("names") + @Nullable + abstract List getNames(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractUnbindSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractUnbindSecurityGroupRequest.java new file mode 100644 index 0000000000..7903a2bdac --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractUnbindSecurityGroupRequest.java @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +public abstract class AbstractUnbindSecurityGroupRequest { + + /** + * The Security Group id + */ + @JsonIgnore + abstract String getSecurityGroupId(); + + /** + * The Space id + */ + @JsonIgnore + abstract String getSpaceId(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/Protocol.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/Protocol.java new file mode 100644 index 0000000000..d855b130e1 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/Protocol.java @@ -0,0 +1,77 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * The protocol of a Security Group + */ +public enum Protocol { + + /** + * All protocols + */ + ALL("all"), + + /** + * ICMP protocol + */ + ICMP("icmp"), + + /** + * TCP protocol + */ + TCP("tcp"), + + /** + * UDP protocol + */ + UDP("udp"); + + private final String value; + + Protocol(String value) { + this.value = value; + } + + @JsonCreator + public static Protocol from(String s) { + switch (s.toLowerCase()) { + case "all": + return ALL; + case "icmp": + return ICMP; + case "tcp": + return TCP; + case "udp": + return UDP; + default: + throw new IllegalArgumentException(String.format("Unknown protocol: %s", s)); + } + } + + @JsonValue + public String getValue() { + return this.value; + } + + @Override + public String toString() { + return getValue(); + } + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroup.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroup.java new file mode 100644 index 0000000000..348e84500b --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroup.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.client.v3.Resource; +import java.util.List; + +/** + * The entity response payload for the Security Group resource + */ +@JsonDeserialize +public abstract class SecurityGroup extends Resource { + + /** + * The name + */ + @JsonProperty("name") + abstract String getName(); + + /** + * The globally enabled + */ + @JsonProperty("globally_enabled") + abstract GloballyEnabled getGloballyEnabled(); + + /** + * The rules + */ + @JsonProperty("rules") + abstract List getRules(); + + /** + * The space relationships + */ + @JsonProperty("relationships") + abstract Relationships getRelationships(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroupsV3.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroupsV3.java new file mode 100644 index 0000000000..e90ca3f43e --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroupsV3.java @@ -0,0 +1,134 @@ +/* + * 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.client.v3.securitygroups; + +import reactor.core.publisher.Mono; + +public interface SecurityGroupsV3 { + + /** + * Makes the Creating + * a Security Group request. + * + * @param request the Create Security Group request + * @return the response from the Create Security Group request + */ + Mono create(CreateSecurityGroupRequest request); + + /** + * Makes the Get + * a Security Group request. + * + * @param request the Get Security Group request + * @return the response from the Get Security Group request + */ + Mono get(GetSecurityGroupRequest request); + + /** + * Makes the List + * Security Groups request + * + * @param request the List Security Group request + * @return the response from the List Security Group request + */ + Mono list(ListSecurityGroupsRequest request); + + /** + * Makes the Update + * Security Groups request + * + * @param request the Update Security Group request + * @return the response from the Update Security Group request + */ + Mono update(UpdateSecurityGroupRequest request); + + /** + * Makes the Delete + * Security Groups request + * + * @param request the Delete Security Group request + * @return the response from the Delete Security Group request + */ + Mono delete(DeleteSecurityGroupRequest request); + + /** + * Makes the Bind + * Staging Security Group request + * + * @param request the Bind Staging Security Group request + * @return the response from the Bind Staging Security Group request + */ + Mono bindStagingSecurityGroup(BindStagingSecurityGroupRequest request); + + /** + * Makes the Bind + * Running Security Group request + * + * @param request the Bind Running Security Group request + * @return the response from the Bind Running Security Group request + */ + Mono bindRunningSecurityGroup(BindRunningSecurityGroupRequest request); + + /** + * Makes the Unbind + * Staging + * Security Group request + * + * @param request the Unbind Staging Security Group request + * @return the response from the Unbind staging Security Group request + */ + Mono unbindStagingSecurityGroup(UnbindStagingSecurityGroupRequest request); + + /** + * Makes the Unbind + * Running + * Security Groups request + * + * @param request the Unbind Staging Running Security Group request + * @return the response from the Unbind Running Security Group request + */ + Mono unbindRunningSecurityGroup(UnbindRunningSecurityGroupRequest request); + + /** + * Makes the List + * Running Security Groups request + * + * @param request the List Staging Security Group request + * @return the response from the List Staging Security Group request + */ + Mono listStaging(ListStagingSecurityGroupsRequest request); + + /** + * Makes the List + * Running Security Groups request + * + * @param request the List Staging Security Group request + * @return the response from the List Running Security Group request + */ + Mono listRunning(ListRunningSecurityGroupsRequest request); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupRequest.java new file mode 100644 index 0000000000..0e14195fc7 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupRequest.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonSerialize +@Value.Immutable +abstract class _BindRunningSecurityGroupRequest extends AbstractBindSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupResponse.java new file mode 100644 index 0000000000..e299671f9a --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupResponse.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize +@Value.Immutable +public abstract class _BindRunningSecurityGroupResponse extends AbstractBindSecurityGroupResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupRequest.java new file mode 100644 index 0000000000..36ce1fcada --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupRequest.java @@ -0,0 +1,24 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonSerialize +@Value.Immutable +abstract class _BindStagingSecurityGroupRequest extends AbstractBindSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupResponse.java new file mode 100644 index 0000000000..920c3eee7d --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupResponse.java @@ -0,0 +1,24 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize +@Value.Immutable +public abstract class _BindStagingSecurityGroupResponse extends AbstractBindSecurityGroupResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupRequest.java new file mode 100644 index 0000000000..e2d6b4f6c0 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupRequest.java @@ -0,0 +1,60 @@ +/* + * 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.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +import java.util.List; + +/** + * The request payload for the Create a Security Group operation + */ +@JsonSerialize +@Value.Immutable +abstract class _CreateSecurityGroupRequest { + + /** + * The security group name + */ + @JsonProperty("name") + abstract String getName(); + + /** + * the security group glbally enabled field + */ + @JsonProperty("globally_enabled") + @Nullable + abstract GloballyEnabled getGloballyEnabled(); + + /** + * The security group rules + */ + @JsonProperty("rules") + @Nullable + abstract List getRules(); + + /** + * The security group relationships + */ + @JsonProperty("relationships") + @Nullable + abstract Relationships getRelationships(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupResponse.java new file mode 100644 index 0000000000..5b7f6f8ccd --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupResponse.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Creating a Security Group operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _CreateSecurityGroupResponse extends SecurityGroup { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_DeleteSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_DeleteSecurityGroupRequest.java new file mode 100644 index 0000000000..48b0e7d20e --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_DeleteSecurityGroupRequest.java @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Delete Security Group operation + */ +@Value.Immutable +abstract class _DeleteSecurityGroupRequest { + + /** + * The Security Group id + */ + @JsonIgnore + abstract String getSecurityGroupId(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupRequest.java new file mode 100644 index 0000000000..e001a6dbf9 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupRequest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Get Security Group operation + */ +@JsonSerialize +@Value.Immutable +abstract class _GetSecurityGroupRequest { + + /** + * The Security Group id + */ + @JsonIgnore + abstract String getSecurityGroupId(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupResponse.java new file mode 100644 index 0000000000..aab7d9d91e --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupResponse.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the get Security Group operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _GetSecurityGroupResponse extends SecurityGroup { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GloballyEnabled.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GloballyEnabled.java new file mode 100644 index 0000000000..bf89201cbb --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GloballyEnabled.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +/** + * Controls if the group is applied globally to the lifecycle of all applications + */ +@JsonDeserialize +@Value.Immutable +abstract class _GloballyEnabled { + + /** + * Specifies whether the group should be applied globally to all running applications + */ + @JsonProperty("running") + @Nullable + abstract Boolean getRunning(); + + /** + * Specifies whether the group should be applied globally to all staging applications + */ + @JsonProperty("staging") + @Nullable + abstract Boolean getStaging(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsRequest.java new file mode 100644 index 0000000000..45e37d9a8f --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsRequest.java @@ -0,0 +1,27 @@ +/* + * 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.client.v3.securitygroups; + +import org.immutables.value.Value; + + +/** + * The request payload for the List running Security Group operation + */ + +@Value.Immutable +abstract class _ListRunningSecurityGroupsRequest extends AbstractListSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsResponse.java new file mode 100644 index 0000000000..0a6ec345a2 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsResponse.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; + +import org.cloudfoundry.client.v3.PaginatedResponse; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * The response payload for the List Security Groups operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListRunningSecurityGroupsResponse extends PaginatedResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsRequest.java new file mode 100644 index 0000000000..2ec1c16369 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsRequest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2023 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.client.v3.securitygroups; + +import org.cloudfoundry.client.v2.PaginatedRequest; +import org.immutables.value.Value; +import org.cloudfoundry.client.v3.FilterParameter; +import org.cloudfoundry.Nullable; +import java.util.List; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +/** + * The request payload for the List Security Group operation + */ +@JsonSerialize +@Value.Immutable +abstract class _ListSecurityGroupsRequest extends PaginatedRequest { + + /** + * The security group ids filter + */ + @FilterParameter("guids") + abstract List getSecurityGroupIds(); + + /** + * The security group names filter + */ + @FilterParameter("names") + abstract List getNames(); + + /** + * the security group globally enabled running filter + */ + @FilterParameter("globally_enabled_running") + @Nullable + abstract Boolean getGloballyEnabledRunning(); + + /** + * the security group globally enabled staging filter + */ + @FilterParameter("globally_enabled_staging") + @Nullable + abstract Boolean getGloballyEnabledStagingBoolean(); + + /** + * the security group running_space_guids filter + */ + @FilterParameter("running_space_guids") + @Nullable + abstract List getRunningSpaceIds(); + + /** + * the security group staging_space_guids filter + */ + @FilterParameter("staging_space_guids") + @Nullable + abstract List getStagingSpaceIds(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsResponse.java new file mode 100644 index 0000000000..f19bfc7613 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsResponse.java @@ -0,0 +1,31 @@ +/* + * 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.client.v3.securitygroups; + +import org.immutables.value.Value; + +import org.cloudfoundry.client.v3.PaginatedResponse; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * The response payload for the List Security Groups operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListSecurityGroupsResponse extends PaginatedResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsRequest.java new file mode 100644 index 0000000000..d85b8c9c01 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsRequest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + + +/** + * The request payload for the List staging Security Group operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListStagingSecurityGroupsRequest extends AbstractListSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsResponse.java new file mode 100644 index 0000000000..1109b7a60a --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsResponse.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; + +import org.cloudfoundry.client.v3.PaginatedResponse; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * The response payload for the List Security Groups operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListStagingSecurityGroupsResponse extends PaginatedResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Relationships.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Relationships.java new file mode 100644 index 0000000000..e9d782cbac --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Relationships.java @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.client.v3.ToManyRelationship; +import org.immutables.value.Value; + +/** + * Holds relationships to running/staging spaces where security groups is + * applied + */ +@JsonDeserialize +@Value.Immutable +abstract class _Relationships { + + /** + * A relationship to the spaces where the security_group is applied to + * applications during runtime + */ + @JsonProperty("running_spaces") + abstract ToManyRelationship getRunningSpaces(); + + /** + * A relationship to the spaces where the security_group is applied to + * applications during runtime + */ + @JsonProperty("staging_spaces") + abstract ToManyRelationship getStagingSpaces(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Rule.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Rule.java new file mode 100644 index 0000000000..b24119e0f8 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Rule.java @@ -0,0 +1,78 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +/** + * A security group rule + */ +@JsonDeserialize +@Value.Immutable +abstract class _Rule { + + /** + * The code control signal for icmp + */ + @JsonProperty("code") + @Nullable + abstract Integer getCode(); + + /** + * The description of the rule + */ + @JsonProperty("description") + @Nullable + abstract String getDescription(); + + /** + * The destination + */ + @JsonProperty("destination") + @Nullable + abstract String getDestination(); + + /** + * Enables logging for the egress rule + */ + @JsonProperty("log") + @Nullable + abstract Boolean getLog(); + + /** + * The ports + */ + @JsonProperty("ports") + @Nullable + abstract String getPorts(); + + /** + * The protocol + */ + @JsonProperty("protocol") + @Nullable + abstract Protocol getProtocol(); + + /** + * The type control signal for icmp + */ + @JsonProperty("type") + @Nullable + abstract Integer getType(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_SecurityGroupResource.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_SecurityGroupResource.java new file mode 100644 index 0000000000..339559f111 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_SecurityGroupResource.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + + +/** + * The Resource response payload for the List SecurityGroups operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _SecurityGroupResource extends SecurityGroup { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindRunningSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindRunningSecurityGroupRequest.java new file mode 100644 index 0000000000..b9666f9042 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindRunningSecurityGroupRequest.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; + +/** + * The request payload for the Unbind Running Security Group operation + */ +@Value.Immutable +abstract class _UnbindRunningSecurityGroupRequest extends AbstractUnbindSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindStagingSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindStagingSecurityGroupRequest.java new file mode 100644 index 0000000000..7c0f3a34b8 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindStagingSecurityGroupRequest.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; + +/** + * The request payload for the Unbind Staging Security Group operation + */ +@Value.Immutable +abstract class _UnbindStagingSecurityGroupRequest extends AbstractUnbindSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupRequest.java new file mode 100644 index 0000000000..a5ce3eed99 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupRequest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.immutables.value.Value; + +import java.util.List; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * The request payload for the Create a Security Group operation + */ +@JsonSerialize +@Value.Immutable +abstract class _UpdateSecurityGroupRequest { + + /** + * Id of the security group + */ + @JsonIgnore + abstract String getSecurityGroupId(); + + /** + * Name of the security group + */ + @JsonProperty("name") + abstract String getName(); + + /** + * Object that controls if the group is applied globally to the lifecycle of all applications + */ + @JsonProperty("globally_enabled") + abstract GloballyEnabled getGloballyEnabled(); + + /** + * Rules that will be applied by this security group + */ + @JsonProperty("rules") + abstract List getRules(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupResponse.java new file mode 100644 index 0000000000..42f5dfa05e --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupResponse.java @@ -0,0 +1,26 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Update a Security Group operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _UpdateSecurityGroupResponse extends SecurityGroup { + +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindRunningSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindRunningSecurityGroupRequestTest.java new file mode 100644 index 0000000000..32d7335b89 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindRunningSecurityGroupRequestTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.cloudfoundry.client.v3.Relationship; +import org.junit.Test; + +public class BindRunningSecurityGroupRequestTest { + + @Test(expected = IllegalStateException.class) + public void noSecurityGroupId() { + BindRunningSecurityGroupRequest.builder().build(); + } + + @Test + public void valid() { + BindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .boundSpaces(Relationship.builder().id("space-guid-1").build()) + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindStagingSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindStagingSecurityGroupRequestTest.java new file mode 100644 index 0000000000..5a8ec2589b --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindStagingSecurityGroupRequestTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.cloudfoundry.client.v3.Relationship; +import org.junit.Test; + +public class BindStagingSecurityGroupRequestTest { + + @Test(expected = IllegalStateException.class) + public void noSecurityGroupId() { + BindStagingSecurityGroupRequest.builder().build(); + } + + @Test + public void valid() { + BindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .boundSpaces(Relationship.builder().id("space-guid-1").build()) + + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/CreateSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/CreateSecurityGroupRequestTest.java new file mode 100644 index 0000000000..7cf4e23066 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/CreateSecurityGroupRequestTest.java @@ -0,0 +1,26 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.junit.Test; + +public class CreateSecurityGroupRequestTest { + + @Test(expected = IllegalStateException.class) + public void noName() { + CreateSecurityGroupRequest.builder().rule(Rule.builder().build()).build(); + } + +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/DeleteSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/DeleteSecurityGroupRequestTest.java new file mode 100644 index 0000000000..9a2b95c3d5 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/DeleteSecurityGroupRequestTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.junit.Test; + +public class DeleteSecurityGroupRequestTest { + + @Test(expected = IllegalStateException.class) + public void noSecurityGroupId() { + DeleteSecurityGroupRequest.builder().build(); + } + + @Test + public void valid() { + DeleteSecurityGroupRequest.builder().securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/GetSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/GetSecurityGroupRequestTest.java new file mode 100644 index 0000000000..d086d9196b --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/GetSecurityGroupRequestTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.junit.Test; + +public class GetSecurityGroupRequestTest { + + @Test(expected = IllegalStateException.class) + public void noSecurityGroupId() { + GetSecurityGroupRequest.builder().build(); + } + + @Test + public void valid() { + GetSecurityGroupRequest.builder().securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListRunningSecurityGroupsRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListRunningSecurityGroupsRequestTest.java new file mode 100644 index 0000000000..f9aeb74f36 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListRunningSecurityGroupsRequestTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.junit.Test; + +public class ListRunningSecurityGroupsRequestTest { + + @Test(expected = IllegalStateException.class) + public void noSpaceID() { + ListRunningSecurityGroupsRequest.builder().build(); + } + + @Test + public void valid() { + ListRunningSecurityGroupsRequest.builder().spaceId("space-giud1").build(); + } + +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListSecurityGroupsRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListSecurityGroupsRequestTest.java new file mode 100644 index 0000000000..0c8e498dc0 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListSecurityGroupsRequestTest.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.junit.Test; + +public class ListSecurityGroupsRequestTest { + + @Test + public void valid() { + ListSecurityGroupsRequest.builder().build(); + } + +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListStagingSecurityGroupsRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListStagingSecurityGroupsRequestTest.java new file mode 100644 index 0000000000..fa591d8121 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListStagingSecurityGroupsRequestTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.junit.Test; + +public class ListStagingSecurityGroupsRequestTest { + + @Test(expected = IllegalStateException.class) + public void noSpaceID() { + ListStagingSecurityGroupsRequest.builder().build(); + } + + @Test + public void valid() { + ListStagingSecurityGroupsRequest.builder().spaceId("space-giud1").build(); + } + +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindRunningSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindRunningSecurityGroupRequestTest.java new file mode 100644 index 0000000000..362f88403b --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindRunningSecurityGroupRequestTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.junit.Test; + +public class UnbindRunningSecurityGroupRequestTest { + + @Test(expected = IllegalStateException.class) + public void noSecurityGroupId() { + UnbindRunningSecurityGroupRequest.builder().build(); + } + + @Test(expected = IllegalStateException.class) + public void noSpaceId() { + UnbindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a").build(); + } + + @Test + public void valid() { + UnbindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .spaceId("space-guid2").build(); + } + +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindStagingSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindStagingSecurityGroupRequestTest.java new file mode 100644 index 0000000000..6396fce0a1 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindStagingSecurityGroupRequestTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.junit.Test; + +public class UnbindStagingSecurityGroupRequestTest { + + @Test(expected = IllegalStateException.class) + public void noSecurityGroupId() { + UnbindStagingSecurityGroupRequest.builder().build(); + } + + @Test(expected = IllegalStateException.class) + public void noSpaceId() { + UnbindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a").build(); + } + + @Test + public void valid() { + UnbindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .spaceId("space-guid2").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UpdateSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UpdateSecurityGroupRequestTest.java new file mode 100644 index 0000000000..e3493e3cf7 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UpdateSecurityGroupRequestTest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2013-2023 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.client.v3.securitygroups; + +import org.junit.Test; + +public class UpdateSecurityGroupRequestTest { + + @Test(expected = IllegalStateException.class) + public void noName() { + UpdateSecurityGroupRequest.builder().build(); + } + + @Test() + public void valid() { + UpdateSecurityGroupRequest.builder().name("my-group0") + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .globallyEnabled(GloballyEnabled.builder().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()) + .build(); + + } + +} diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/SecurityGroupsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/SecurityGroupsTest.java new file mode 100644 index 0000000000..9ff8b69d6b --- /dev/null +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/SecurityGroupsTest.java @@ -0,0 +1,227 @@ +/* + * Copyright 2013-2023 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.client.v3; + +import org.cloudfoundry.AbstractIntegrationTest; +import org.cloudfoundry.client.CloudFoundryClient; +import org.cloudfoundry.client.v3.securitygroups.UnbindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UnbindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.Rule; + +import org.cloudfoundry.client.v3.securitygroups.GloballyEnabled; + +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest; + +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsRequest; + +import org.junit.Test; +import org.junit.Before; +import org.springframework.beans.factory.annotation.Autowired; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import java.time.Duration; +import java.util.Arrays; + +import static org.cloudfoundry.client.v3.securitygroups.Protocol.TCP; + +public final class SecurityGroupsTest extends AbstractIntegrationTest { + + @Autowired + private CloudFoundryClient cloudFoundryClient; + + @Autowired + private Mono spaceId; + private Mono securityGroup; + private String securityGroupName; + + @Before + public void setup() { + this.securityGroupName = this.nameFactory.getSecurityGroupName(); + + this.securityGroup = this.cloudFoundryClient.securityGroupsV3() + .create(CreateSecurityGroupRequest.builder() + .name(this.securityGroupName) + .globallyEnabled(GloballyEnabled.builder() + .staging(true).running(true) + .build()) + .rule(Rule.builder().destination("0.0.0.0/0") + .log(false).ports("2048-3000") + .protocol(TCP).build()) + .build()); + } + + @Test + public void create() { + this.securityGroup.map(securityGroup -> securityGroup.getName()) + .as(StepVerifier::create).expectNext(this.securityGroupName) + .expectComplete().verify(Duration.ofMinutes(5)); + } + + @Test + public void get() { + this.securityGroup + .flatMap(securityGroup -> this.cloudFoundryClient.securityGroupsV3() + .get(GetSecurityGroupRequest.builder() + .securityGroupId(securityGroup + .getId()) + .build()) + .map(sg -> sg.getName())) + .as(StepVerifier::create).expectNext(this.securityGroupName) + .expectComplete().verify(Duration.ofMinutes(5)); + } + + @Test + public void update() { + String newSecurityGroupName = this.nameFactory.getSecurityGroupName(); + this.securityGroup + .flatMap(securityGroup -> this.cloudFoundryClient.securityGroupsV3() + .update(UpdateSecurityGroupRequest.builder() + .securityGroupId(securityGroup + .getId()) + .name(newSecurityGroupName) + .build())) + .map(securityGroup -> securityGroup.getName()) + .as(StepVerifier::create).expectNext(newSecurityGroupName) + .expectComplete().verify(Duration.ofMinutes(5)); + } + + @Test + public void delete() { + this.securityGroup + .flatMap(securityGroup -> this.cloudFoundryClient.securityGroupsV3() + .delete(DeleteSecurityGroupRequest.builder() + .securityGroupId(securityGroup + .getId()) + .build()) + .map(id -> Arrays.asList(id))) + .as(StepVerifier::create).expectNextCount(1).expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void list() { + this.securityGroup + .map(securityGroup -> this.cloudFoundryClient.securityGroupsV3() + .list(ListSecurityGroupsRequest.builder() + .names(Arrays.asList(securityGroup + .getName())) + .build())) + .as(StepVerifier::create).expectNextCount(1).expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void listRunning() { + Mono.zip(this.securityGroup, this.spaceId).flatMap(v -> this.cloudFoundryClient + .securityGroupsV3() + .listRunning(ListRunningSecurityGroupsRequest.builder() + .spaceId(v.getT2()) + .names(Arrays.asList(v.getT1().getName())).build())) + .as(StepVerifier::create).expectNextCount(1).expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void listStaging() { + Mono.zip(this.securityGroup, this.spaceId).flatMap(v -> this.cloudFoundryClient + .securityGroupsV3() + .listStaging(ListStagingSecurityGroupsRequest.builder() + .spaceId(v.getT2()) + .names(Arrays.asList(v.getT1().getName())).build())) + .as(StepVerifier::create).expectNextCount(1).expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void bindStagingSecurityGroup() { + Mono.zip(this.securityGroup, this.spaceId).flatMap(v -> this.cloudFoundryClient + .securityGroupsV3() + .bindStagingSecurityGroup(BindStagingSecurityGroupRequest.builder() + .securityGroupId(v.getT1().getId()) + .boundSpaces(Relationship.builder().id(v.getT2()) + .build()) + .build())) + .as(StepVerifier::create).expectNextCount(1).expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void unbindStagingSecurityGroup() { + Mono.zip(this.securityGroup, this.spaceId).flatMap(v -> this.cloudFoundryClient + .securityGroupsV3() + .bindStagingSecurityGroup(BindStagingSecurityGroupRequest.builder() + .securityGroupId(v.getT1().getId()) + .boundSpaces(Relationship.builder().id(v.getT2()) + .build()) + .build()) + .then(this.cloudFoundryClient.securityGroupsV3() + .unbindStagingSecurityGroup( + UnbindStagingSecurityGroupRequest + .builder() + .securityGroupId(v + .getT1() + .getId()) + .spaceId(v.getT2()) + .build()))) + + .as(StepVerifier::create).expectNextCount(0).expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void bindRunningSecurityGroup() { + Mono.zip(this.securityGroup, this.spaceId).flatMap(v -> this.cloudFoundryClient + .securityGroupsV3() + .bindRunningSecurityGroup(BindRunningSecurityGroupRequest.builder() + .securityGroupId(v.getT1().getId()) + .boundSpaces(Relationship.builder().id(v.getT2()) + .build()) + .build())) + .as(StepVerifier::create).expectNextCount(1).expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void unbindRunnungSecurityGroup() { + Mono.zip(this.securityGroup, this.spaceId).flatMap(v -> this.cloudFoundryClient + .securityGroupsV3() + .bindRunningSecurityGroup(BindRunningSecurityGroupRequest.builder() + .securityGroupId(v.getT1().getId()) + .boundSpaces(Relationship.builder().id(v.getT2()) + .build()) + .build()) + .then(this.cloudFoundryClient.securityGroupsV3() + .unbindRunningSecurityGroup( + UnbindRunningSecurityGroupRequest + .builder() + .securityGroupId(v + .getT1() + .getId()) + .spaceId(v.getT2()) + .build()))) + + .as(StepVerifier::create).expectNextCount(0).expectComplete() + .verify(Duration.ofMinutes(5)); + } +}