Skip to content

Commit

Permalink
adding security groups v3 create api
Browse files Browse the repository at this point in the history
adding create security group impl and tests

adding get security group api and tests

adding get security group impl + test

adding list security groups impl + api

adding update security group api

adding update security group api v3 impl

adding security groups delete api v3 impl and tests

adding bind running/staging security group v3 api

adding bind impl

adding unbind security group

adding list running/staging api and tests

adding create security group test

adding integration tests

adding integration tests

fixing setup/teardown

fixing integration tests

refactoring integration tests
  • Loading branch information
radoslav-tomov authored and anthonydahanne committed Feb 9, 2024
1 parent 4a8295b commit 198c709
Show file tree
Hide file tree
Showing 58 changed files with 3,186 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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<String, String> getRequestTags() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> root,
TokenProvider tokenProvider, Map<String, String> requestTags) {
super(connectionContext, root, tokenProvider, requestTags);
}

@Override
public Mono<CreateSecurityGroupResponse> create(CreateSecurityGroupRequest request) {
return post(request, CreateSecurityGroupResponse.class,
builder -> builder.pathSegment("security_groups")).checkpoint();

}

@Override
public Mono<GetSecurityGroupResponse> get(GetSecurityGroupRequest request) {
return get(request, GetSecurityGroupResponse.class, builder -> builder
.pathSegment("security_groups", request.getSecurityGroupId()))
.checkpoint();

}

@Override
public Mono<ListSecurityGroupsResponse> list(ListSecurityGroupsRequest request) {
return get(request, ListSecurityGroupsResponse.class,
builder -> builder.pathSegment("security_groups")).checkpoint();
}

@Override
public Mono<UpdateSecurityGroupResponse> update(UpdateSecurityGroupRequest request) {
return patch(request, UpdateSecurityGroupResponse.class, builder -> builder
.pathSegment("security_groups", request.getSecurityGroupId()))
.checkpoint();
}

@Override
public Mono<String> delete(DeleteSecurityGroupRequest request) {
return delete(request, builder -> builder.pathSegment("security_groups",
request.getSecurityGroupId())).checkpoint();

}

@Override
public Mono<BindRunningSecurityGroupResponse> bindRunningSecurityGroup(
BindRunningSecurityGroupRequest request) {
return post(request, BindRunningSecurityGroupResponse.class,
builder -> builder.pathSegment("security_groups",
request.getSecurityGroupId(), "relationships",
"running_spaces")).checkpoint();
}

@Override
public Mono<BindStagingSecurityGroupResponse> bindStagingSecurityGroup(
BindStagingSecurityGroupRequest request) {
return post(request, BindStagingSecurityGroupResponse.class,
builder -> builder.pathSegment("security_groups",
request.getSecurityGroupId(), "relationships",
"staging_spaces")).checkpoint();
}

@Override
public Mono<Void> unbindStagingSecurityGroup(UnbindStagingSecurityGroupRequest request) {
return delete(request, Void.class,
builder -> builder.pathSegment("security_groups",
request.getSecurityGroupId(), "relationships",
"staging_spaces", request.getSpaceId()))
.checkpoint();
}

@Override
public Mono<Void> unbindRunningSecurityGroup(UnbindRunningSecurityGroupRequest request) {
return delete(request, Void.class,
builder -> builder.pathSegment("security_groups",
request.getSecurityGroupId(), "relationships",
"running_spaces", request.getSpaceId()))
.checkpoint();
}

@Override
public Mono<ListRunningSecurityGroupsResponse> listRunning(
ListRunningSecurityGroupsRequest request) {
return get(request, ListRunningSecurityGroupsResponse.class,
builder -> builder.pathSegment("spaces", request.getSpaceId(),
"running_security_groups")).checkpoint();
}

@Override
public Mono<ListStagingSecurityGroupsResponse> listStaging(
ListStagingSecurityGroupsRequest request) {
return get(request, ListStagingSecurityGroupsResponse.class,
builder -> builder.pathSegment("spaces", request.getSpaceId(),
"staging_security_groups")).checkpoint();
}
}
Loading

0 comments on commit 198c709

Please sign in to comment.