You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2016/06/22 09:14:15 UTC

jclouds-labs-openstack git commit: Added Origin Host header management

Repository: jclouds-labs-openstack
Updated Branches:
  refs/heads/master 18e50b60b -> f831f59a1


Added Origin Host header management


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/commit/f831f59a
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/tree/f831f59a
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/diff/f831f59a

Branch: refs/heads/master
Commit: f831f59a1df246a9f6c20fc9b458d4ae971ef8ef
Parents: 18e50b6
Author: Agnello Staibano <a....@shaa.it>
Authored: Tue Jun 21 16:36:11 2016 +0200
Committer: Ignasi Barrera <na...@apache.org>
Committed: Wed Jun 22 11:12:29 2016 +0200

----------------------------------------------------------------------
 .../poppy/v1/domain/HostHeaderType.java         | 50 ++++++++++++++++++
 .../openstack/poppy/v1/domain/Origin.java       | 55 ++++++++++++++++++--
 .../poppy/v1/features/ServiceApiLiveTest.java   |  2 +
 .../poppy/v1/features/ServiceApiMockTest.java   |  4 +-
 .../resources/poppy_service_create_request.json |  1 +
 .../resources/poppy_service_get_response.json   |  1 +
 .../resources/poppy_service_list_response.json  |  3 ++
 .../poppy_service_list_response_paged1.json     |  4 ++
 .../poppy_service_list_response_paged2.json     |  3 ++
 9 files changed, 119 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/f831f59a/openstack-poppy/src/main/java/org/jclouds/openstack/poppy/v1/domain/HostHeaderType.java
----------------------------------------------------------------------
diff --git a/openstack-poppy/src/main/java/org/jclouds/openstack/poppy/v1/domain/HostHeaderType.java b/openstack-poppy/src/main/java/org/jclouds/openstack/poppy/v1/domain/HostHeaderType.java
new file mode 100644
index 0000000..f108342
--- /dev/null
+++ b/openstack-poppy/src/main/java/org/jclouds/openstack/poppy/v1/domain/HostHeaderType.java
@@ -0,0 +1,50 @@
+/*
+ * 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.jclouds.openstack.poppy.v1.domain;
+
+/**
+ * Specifies the "Host" header type used to access the resources on the origin. Only "domain", "origin" or "custom" are currently allowed.
+ * If "custom" the header value must also be specified.
+ * Defaults to domain.
+ */
+public enum HostHeaderType {
+   DOMAIN,
+   ORIGIN,
+   CUSTOM;
+
+   @Override
+   public String toString() {
+      return name().toLowerCase();
+   }
+
+   /*
+    * This provides GSON enum support in jclouds.
+    * @param name The string representation of this enum value.
+    * @return The corresponding enum value.
+    */
+   public static HostHeaderType fromValue(String name) {
+      if (name != null) {
+         for (HostHeaderType value : HostHeaderType.values()) {
+            if (name.equalsIgnoreCase(value.name())) {
+               return value;
+            }
+         }
+      }
+      return null;
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/f831f59a/openstack-poppy/src/main/java/org/jclouds/openstack/poppy/v1/domain/Origin.java
----------------------------------------------------------------------
diff --git a/openstack-poppy/src/main/java/org/jclouds/openstack/poppy/v1/domain/Origin.java b/openstack-poppy/src/main/java/org/jclouds/openstack/poppy/v1/domain/Origin.java
index afc2505..900480f 100644
--- a/openstack-poppy/src/main/java/org/jclouds/openstack/poppy/v1/domain/Origin.java
+++ b/openstack-poppy/src/main/java/org/jclouds/openstack/poppy/v1/domain/Origin.java
@@ -30,6 +30,16 @@ import com.google.common.collect.ImmutableList;
 @AutoValue
 public abstract class Origin {
    /**
+    * @see Builder#hostHeaderType(HostHeaderType)
+    */
+   public abstract HostHeaderType getHostHeaderType();
+   
+   /**
+    * @see Builder#hostHeaderValue(String)
+    */
+   @Nullable public abstract String getHostHeaderValue();
+   
+   /**
     * @see Builder#origin(String)
     */
    public abstract String getOrigin();
@@ -49,9 +59,9 @@ public abstract class Origin {
     */
    @Nullable public abstract List<CachingRule> getRules();
 
-   @SerializedNames({ "origin", "port", "ssl", "rules" })
-   private static Origin create(String origin, int port, boolean sslEnabled, List<CachingRule> rules) {
-      return builder().origin(origin).port(port).sslEnabled(sslEnabled)
+   @SerializedNames({ "hostheadertype", "hostheadervalue", "origin", "port", "ssl", "rules" })
+   private static Origin create(HostHeaderType hostHeaderType, String hostHeaderValue, String origin, int port, boolean sslEnabled, List<CachingRule> rules) {
+      return builder().hostHeaderType(hostHeaderType).hostHeaderValue(hostHeaderValue).origin(origin).port(port).sslEnabled(sslEnabled)
             .rules(rules).build();
    }
 
@@ -60,6 +70,8 @@ public abstract class Origin {
    }
    public Builder toBuilder() {
       return builder()
+            .hostHeaderType(getHostHeaderType())
+            .hostHeaderValue(getHostHeaderValue())
             .origin(getOrigin())
             .port(getPort())
             .sslEnabled(getSslEnabled())
@@ -67,6 +79,8 @@ public abstract class Origin {
    }
 
    public static final class Builder {
+      private HostHeaderType hostHeaderType;
+      private String hostHeaderValue;
       private String origin;
       private Integer port;
       private Boolean sslEnabled;
@@ -74,6 +88,8 @@ public abstract class Origin {
       Builder() {
       }
       Builder(Origin source) {
+         hostHeaderType(source.getHostHeaderType());
+         hostHeaderValue(source.getHostHeaderValue());
          origin(source.getOrigin());
          port(source.getPort());
          sslEnabled(source.getSslEnabled());
@@ -82,6 +98,29 @@ public abstract class Origin {
 
       /**
        * Required.
+       * @param hostHeaderType Specifies the type of Host header type to use. "origin" will set the value of
+       *                       Host header type to the origin URL, "domain" will set the value of Host header
+       *                       type to the domain URL, "custom" will set the value of Host header type to the
+       *                       value of {@link #hostHeaderValue}.
+       * @return The Origin builder.
+       */
+      public Origin.Builder hostHeaderType(HostHeaderType hostHeaderType) {
+         this.hostHeaderType = hostHeaderType;
+         return this;
+      }
+      
+      /**
+       * Optional.
+       * @param hostHeaderValue Specifies the value of Host header to use when type is set to "custom".
+       * @return The Origin builder.
+       */
+      public Origin.Builder hostHeaderValue(String hostHeaderValue) {
+         this.hostHeaderValue = hostHeaderValue;
+         return this;
+      }
+      
+      /**
+       * Required.
        * @param origin Specifies the URL or IP address from which to pull origin content. The minimum length for
        *               origin is 3. The maximum length is 253.
        * @return The Origin builder.
@@ -126,6 +165,14 @@ public abstract class Origin {
 
       public Origin build() {
          String missing = "";
+         if (hostHeaderType == null) {
+            missing += " hostHeaderType";
+         }
+         else {
+            if (HostHeaderType.CUSTOM.equals(hostHeaderType) && hostHeaderValue == null) {
+               missing += " hostHeaderValue";
+            }
+         }
          if (origin == null) {
             missing += " origin";
          }
@@ -133,6 +180,8 @@ public abstract class Origin {
             throw new IllegalStateException("Missing required properties:" + missing);
          }
          Origin result = new AutoValue_Origin(
+               this.hostHeaderType,
+               this.hostHeaderValue,
                this.origin,
                this.port,
                this.sslEnabled,

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/f831f59a/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiLiveTest.java b/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiLiveTest.java
index 0c75a80..aeafa82 100644
--- a/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiLiveTest.java
+++ b/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiLiveTest.java
@@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
 import org.jclouds.openstack.poppy.v1.domain.Caching;
 import org.jclouds.openstack.poppy.v1.domain.CreateService;
 import org.jclouds.openstack.poppy.v1.domain.Domain;
+import org.jclouds.openstack.poppy.v1.domain.HostHeaderType;
 import org.jclouds.openstack.poppy.v1.domain.LogDelivery;
 import org.jclouds.openstack.poppy.v1.domain.Origin;
 import org.jclouds.openstack.poppy.v1.domain.Restriction;
@@ -61,6 +62,7 @@ public class ServiceApiLiveTest extends BasePoppyApiLiveTest {
                                  Domain.builder().domain("www.example" + UUID.randomUUID() + ".com").build()))
                      .origins(ImmutableList.of(
                            Origin.builder()
+                                 .hostHeaderType(HostHeaderType.ORIGIN)
                                  .origin("jclouds123456123456.com")
                                  .port(80)
                                  .sslEnabled(false)

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/f831f59a/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiMockTest.java
----------------------------------------------------------------------
diff --git a/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiMockTest.java b/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiMockTest.java
index dca0932..dda91d6 100644
--- a/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiMockTest.java
+++ b/openstack-poppy/src/test/java/org/jclouds/openstack/poppy/v1/features/ServiceApiMockTest.java
@@ -30,6 +30,7 @@ import org.jclouds.openstack.poppy.v1.PoppyApi;
 import org.jclouds.openstack.poppy.v1.domain.Caching;
 import org.jclouds.openstack.poppy.v1.domain.CreateService;
 import org.jclouds.openstack.poppy.v1.domain.Domain;
+import org.jclouds.openstack.poppy.v1.domain.HostHeaderType;
 import org.jclouds.openstack.poppy.v1.domain.LogDelivery;
 import org.jclouds.openstack.poppy.v1.domain.Origin;
 import org.jclouds.openstack.poppy.v1.domain.Restriction;
@@ -68,7 +69,8 @@ public class ServiceApiMockTest extends BasePoppyApiMockTest {
                      Domain.builder().domain("www.mywebsite.com").build(),
                      Domain.builder().domain("blog.mywebsite.com").build()))
                .origins(ImmutableList.of(
-                     Origin.builder().origin("mywebsite.com").port(80).sslEnabled(false).build()))
+                     Origin.builder().hostHeaderType(HostHeaderType.DOMAIN).origin("mywebsite.com").port(80)
+                           .sslEnabled(false).build()))
                .restrictions(ImmutableList.of(
                      Restriction.builder()
                            .name("website only")

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/f831f59a/openstack-poppy/src/test/resources/poppy_service_create_request.json
----------------------------------------------------------------------
diff --git a/openstack-poppy/src/test/resources/poppy_service_create_request.json b/openstack-poppy/src/test/resources/poppy_service_create_request.json
index 1f745ba..77f5fbc 100644
--- a/openstack-poppy/src/test/resources/poppy_service_create_request.json
+++ b/openstack-poppy/src/test/resources/poppy_service_create_request.json
@@ -10,6 +10,7 @@
     ],
     "origins": [
         {
+            "hostheadertype": "domain",
             "origin": "mywebsite.com",
             "port": 80,
             "ssl": false

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/f831f59a/openstack-poppy/src/test/resources/poppy_service_get_response.json
----------------------------------------------------------------------
diff --git a/openstack-poppy/src/test/resources/poppy_service_get_response.json b/openstack-poppy/src/test/resources/poppy_service_get_response.json
index f893053..8f65b73 100644
--- a/openstack-poppy/src/test/resources/poppy_service_get_response.json
+++ b/openstack-poppy/src/test/resources/poppy_service_get_response.json
@@ -9,6 +9,7 @@
   ],
   "origins": [
     {
+      "hostheadertype": "origin",
       "origin": "mywebsite.com",
       "port": 80,
       "ssl": false,

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/f831f59a/openstack-poppy/src/test/resources/poppy_service_list_response.json
----------------------------------------------------------------------
diff --git a/openstack-poppy/src/test/resources/poppy_service_list_response.json b/openstack-poppy/src/test/resources/poppy_service_list_response.json
index 7b8caac..4d652c6 100644
--- a/openstack-poppy/src/test/resources/poppy_service_list_response.json
+++ b/openstack-poppy/src/test/resources/poppy_service_list_response.json
@@ -16,6 +16,7 @@
       ],
       "origins": [
         {
+          "hostheadertype": "domain",
           "origin": "mywebsite.com",
           "port": 80,
           "ssl": false
@@ -86,6 +87,8 @@
       ],
       "origins": [
         {
+          "hostheadertype": "custom",
+          "hostheadervalue": "www.mywebsite.com",
           "origin": "44.33.22.11",
           "port": 80,
           "ssl": false

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/f831f59a/openstack-poppy/src/test/resources/poppy_service_list_response_paged1.json
----------------------------------------------------------------------
diff --git a/openstack-poppy/src/test/resources/poppy_service_list_response_paged1.json b/openstack-poppy/src/test/resources/poppy_service_list_response_paged1.json
index d1dcfe5..f513dfb 100644
--- a/openstack-poppy/src/test/resources/poppy_service_list_response_paged1.json
+++ b/openstack-poppy/src/test/resources/poppy_service_list_response_paged1.json
@@ -20,6 +20,8 @@
       ],
       "origins": [
         {
+          "hostheadertype": "custom",
+          "hostheadervalue": "yourwebsite.com",
           "origin": "mywebsite.com",
           "port": 80,
           "ssl": false
@@ -94,11 +96,13 @@
       ],
       "origins": [
         {
+          "hostheadertype": "domain",
           "origin": "44.33.22.11",
           "port": 80,
           "ssl": false
         },
         {
+          "hostheadertype": "domain",
           "origin": "77.66.55.44",
           "port": 80,
           "ssl": false,

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/f831f59a/openstack-poppy/src/test/resources/poppy_service_list_response_paged2.json
----------------------------------------------------------------------
diff --git a/openstack-poppy/src/test/resources/poppy_service_list_response_paged2.json b/openstack-poppy/src/test/resources/poppy_service_list_response_paged2.json
index bc580f3..6032b18 100644
--- a/openstack-poppy/src/test/resources/poppy_service_list_response_paged2.json
+++ b/openstack-poppy/src/test/resources/poppy_service_list_response_paged2.json
@@ -16,6 +16,7 @@
       ],
       "origins": [
         {
+          "hostheadertype": "origin",
           "origin": "mywebsite.com",
           "port": 80,
           "ssl": false
@@ -90,11 +91,13 @@
       ],
       "origins": [
         {
+          "hostheadertype": "domain",
           "origin": "44.33.22.11",
           "port": 80,
           "ssl": false
         },
         {
+          "hostheadertype": "origin",
           "origin": "77.66.55.44",
           "port": 80,
           "ssl": false,