Skip to content
Permalink
Browse files
JCLOUDS-1149 oneandone-firewallpolicies-api
  • Loading branch information
alibazlamit authored and nacx committed Aug 8, 2016
1 parent d0b07a6 commit 50744595dd89b0cad1d3c5416b60a0520e2dc5e0
Show file tree
Hide file tree
Showing 21 changed files with 1,221 additions and 1 deletion.
@@ -17,6 +17,7 @@
package org.apache.jclouds.oneandone.rest;

import java.io.Closeable;
import org.apache.jclouds.oneandone.rest.features.FirewallPolicyApi;
import org.apache.jclouds.oneandone.rest.features.ImageApi;
import org.apache.jclouds.oneandone.rest.features.ServerApi;
import org.apache.jclouds.oneandone.rest.features.SharedStorageApi;
@@ -32,4 +33,7 @@ public interface OneAndOneApi extends Closeable {

@Delegate
SharedStorageApi sharedStorageApi();

@Delegate
FirewallPolicyApi firewallPolicyApi();
}
@@ -0,0 +1,190 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.jclouds.oneandone.rest.domain;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.apache.jclouds.oneandone.rest.domain.Types.RuleProtocol;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

@AutoValue
public abstract class FirewallPolicy {

public abstract String id();

public abstract String name();

@Nullable
public abstract String description();

@Nullable
public abstract String state();

@Nullable
public abstract String creationDate();

@Nullable
public abstract String defaultState();

public abstract List<Rule> rules();

public abstract List<ServerIp> serverIps();

@Nullable
public abstract String cloudpanelId();

@SerializedNames({"id", "name", "description", "state", "creation_date", "default", "rules", "server_ips", "cloudpanel_id"})
public static FirewallPolicy create(String id, String name, String description, String state, String creationDate, String defaultState, List<Rule> rules, List<ServerIp> serverIps, String cloudpanelId) {
return new AutoValue_FirewallPolicy(id, name, description, state, creationDate, defaultState, rules == null ? ImmutableList.<Rule>of() : ImmutableList.copyOf(rules), serverIps == null ? ImmutableList.<ServerIp>of() : ImmutableList.copyOf(serverIps), cloudpanelId);
}

@AutoValue
public abstract static class CreateFirewallPolicy {

public abstract String name();

@Nullable
public abstract String description();

public abstract List<Rule.CreatePayload> rules();

@SerializedNames({"name", "description", "rules"})
public static CreateFirewallPolicy create(final String name, final String description, List<Rule.CreatePayload> rules) {
return new AutoValue_FirewallPolicy_CreateFirewallPolicy(name, description, rules == null ? ImmutableList.<Rule.CreatePayload>of() : ImmutableList.copyOf(rules));
}
}

@AutoValue
public abstract static class UpdateFirewallPolicy {

@Nullable
public abstract String name();

@Nullable
public abstract String description();

@SerializedNames({"name", "description"})
public static UpdateFirewallPolicy create(final String name, final String description) {
return new AutoValue_FirewallPolicy_UpdateFirewallPolicy(name, description);
}
}

@AutoValue
public abstract static class ServerIp {

public abstract String id();

public abstract String ip();

public abstract String serverName();

@SerializedNames({"id", "ip", "server_name"})
public static ServerIp create(String id, String ip, String serverName) {
return new AutoValue_FirewallPolicy_ServerIp(id, ip, serverName);
}

@AutoValue
public abstract static class CreateServerIp {

public abstract List<String> serverIps();

@SerializedNames({"server_ips"})
public static CreateServerIp create(final List<String> serverIps) {
return new AutoValue_FirewallPolicy_ServerIp_CreateServerIp(serverIps == null ? ImmutableList.<String>of() : ImmutableList.copyOf(serverIps));
}
}
}

@AutoValue
public abstract static class Rule {

public abstract String id();

@Nullable
public abstract RuleProtocol protocol();

@Nullable
public abstract Integer portFrom();

@Nullable
public abstract Integer portTo();

@Nullable
public abstract String source();

@SerializedNames({"id", "protocol", "port_from", "port_to", "source"})
public static Rule create(String id, RuleProtocol protocol, Integer portFrom, Integer portTo, String source) {
return new AutoValue_FirewallPolicy_Rule(id, protocol, portFrom, portTo, source);
}

@AutoValue
public abstract static class CreatePayload {

public abstract RuleProtocol protocol();

@Nullable
public abstract Integer portFrom();

@Nullable
public abstract Integer portTo();

@Nullable
public abstract String source();

@SerializedNames({"protocol", "port_from", "port_to", "source"})
public static CreatePayload create(RuleProtocol protocol, Integer portFrom, Integer portTo, String source) {
return builder()
.portFrom(portFrom)
.portTo(portTo)
.protocol(protocol)
.source(source)
.build();
}

public static Builder builder() {
return new AutoValue_FirewallPolicy_Rule_CreatePayload.Builder();
}

@AutoValue.Builder
public abstract static class Builder {

public abstract Builder protocol(RuleProtocol protocol);

public abstract Builder portFrom(Integer portFrom);

public abstract Builder portTo(Integer portTo);

public abstract Builder source(String source);

public abstract CreatePayload build();
}
}

@AutoValue
public abstract static class AddRule {

public abstract List<CreatePayload> rules();

@SerializedNames({"rules"})
public static AddRule create(List<CreatePayload> rules) {
return new AutoValue_FirewallPolicy_Rule_AddRule(rules == null ? ImmutableList.<CreatePayload>of() : ImmutableList.copyOf(rules));
}
}
}
}
@@ -147,4 +147,18 @@ public static StorageServerRights fromValue(String v) {
return Enums.getIfPresent(StorageServerRights.class, v).or(UNRECOGNIZED);
}
}

public enum RuleProtocol {
TCP,
UDP,
ICMP,
AH,
ESP,
GRE,
UNRECOGNIZED;

public static RuleProtocol fromValue(String v) {
return Enums.getIfPresent(RuleProtocol.class, v).or(UNRECOGNIZED);
}
}
}
@@ -0,0 +1,123 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.jclouds.oneandone.rest.features;

import java.io.Closeable;
import java.util.List;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.apache.jclouds.oneandone.rest.domain.FirewallPolicy;
import org.apache.jclouds.oneandone.rest.domain.options.GenericQueryOptions;
import org.apache.jclouds.oneandone.rest.filters.AuthenticateRequest;
import org.jclouds.Fallbacks;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.binders.BindToJsonPayload;

@Path("/firewall_policies")
@Produces("application/json")
@Consumes("application/json")
@RequestFilters(AuthenticateRequest.class)
public interface FirewallPolicyApi extends Closeable {

@Named("firewallpolicies:list")
@GET
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
List<FirewallPolicy> list();

@Named("firewallpolicies:list")
@GET
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
List<FirewallPolicy> list(GenericQueryOptions options);

@Named("firewallpolicies:get")
@GET
@Path("/{firewallPolicyId}")
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
FirewallPolicy get(@PathParam("firewallPolicyId") String firewallPolicyId);

@Named("firewallpolicies:create")
@POST
FirewallPolicy create(@BinderParam(BindToJsonPayload.class) FirewallPolicy.CreateFirewallPolicy firewallPolicy);

@Named("firewallpolicies:update")
@PUT
@Path("/{firewallPolicyId}")
FirewallPolicy update(@PathParam("firewallPolicyId") String firewallPolicyId, @BinderParam(BindToJsonPayload.class) FirewallPolicy.UpdateFirewallPolicy firewallPolicy);

@Named("firewallpolicies:delete")
@DELETE
@Path("/{firewallPolicyId}")
@MapBinder(BindToJsonPayload.class)
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
FirewallPolicy delete(@PathParam("firewallPolicyId") String firewallPolicyId);

@Named("firewallpolicies:serverips:list")
@GET
@Path("/{firewallPolicyId}/server_ips")
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
List<FirewallPolicy.ServerIp> listServerIps(@PathParam("firewallPolicyId") String firewallPolicyId);

@Named("firewallpolicies:serverips:create")
@POST
@Path("/{firewallPolicyId}/server_ips")
FirewallPolicy assignServerIp(@PathParam("firewallPolicyId") String firewallPolicyId, @BinderParam(BindToJsonPayload.class) FirewallPolicy.ServerIp.CreateServerIp serverIp);

@Named("firewallpolicies:serverips:get")
@GET
@Path("/{firewallPolicyId}/server_ips/{serverIpId}")
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
FirewallPolicy.ServerIp getServerIp(@PathParam("firewallPolicyId") String firewallPolicyId, @PathParam("serverIpId") String serverIpId);

@Named("firewallpolicies:serverips:delete")
@DELETE
@Path("/{firewallPolicyId}/server_ips/{serverIpId}")
@MapBinder(BindToJsonPayload.class)
FirewallPolicy unassignServerIp(@PathParam("firewallPolicyId") String firewallPolicyId, @PathParam("serverIpId") String serverIpId);

@Named("firewallpolicies:rules:list")
@GET
@Path("/{firewallPolicyId}/rules")
@Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
List<FirewallPolicy.Rule> listRules(@PathParam("firewallPolicyId") String firewallPolicyId);

@Named("firewallpolicies:rules:create")
@POST
@Path("/{firewallPolicyId}/rules")
FirewallPolicy addRules(@PathParam("firewallPolicyId") String firewallPolicyId, @BinderParam(BindToJsonPayload.class) FirewallPolicy.Rule.AddRule rule);

@Named("firewallpolicies:rules:get")
@GET
@Path("/{firewallPolicyId}/rules/{ruleId}")
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
FirewallPolicy.Rule getRule(@PathParam("firewallPolicyId") String firewallPolicyId, @PathParam("ruleId") String ruleId);

@Named("firewallpolicies:rules:delete")
@DELETE
@Path("/{firewallPolicyId}/rules/{ruleId}")
@MapBinder(BindToJsonPayload.class)
FirewallPolicy removeRule(@PathParam("firewallPolicyId") String firewallPolicyId, @PathParam("ruleId") String ruleId);
}

0 comments on commit 5074459

Please sign in to comment.