Add support for defining s3/swift endpoints
diff --git a/README.rst b/README.rst
index 300c3e5..6321347 100644
--- a/README.rst
+++ b/README.rst
@@ -66,6 +66,20 @@
               Version: GnuPG v1
               ...
 
+Define s3 endpoint:
+
+.. code-block:: yaml
+
+    parameters:
+      aptly:
+        server:
+          endpoint:
+            mys3endpoint:
+              engine: s3
+              awsAccessKeyID: xxxx
+              awsSecretAccessKey: xxxx
+              bucket: test
+
 Example pillar
 ==============
 
diff --git a/aptly/files/aptly.conf b/aptly/files/aptly.conf
index 71c206f..b96db5b 100644
--- a/aptly/files/aptly.conf
+++ b/aptly/files/aptly.conf
@@ -7,6 +7,30 @@
   "dependencyFollowRecommends": false,
   "dependencyFollowAllVariants": false,
   "dependencyFollowSource": false,
+  {%- if server.endpoint is defined %}
+  "S3PublishEndpoints": {
+    {%- for name, endpoint in server.endpoint.iteritems %}
+    {%- if endpoint.engine == 's3' %}
+    "{{ name }}": {
+      {%- for key, value in endpoint.iteritems() %}
+      "{{ key }}": "{{ value }}"{% if not loop.last %},{% endif %}
+      {%- endfor %}
+    }
+    {%- endif %}
+    {%- endfor %}
+  },
+  "SwiftPublishEndpoints": {
+    {%- for name, endpoint in server.endpoint.iteritems %}
+    {%- if endpoint.engine == 'swift' %}
+    "{{ name }}": {
+      {%- for key, value in endpoint.iteritems() %}
+      "{{ key }}": "{{ value }}"{% if not loop.last %},{% endif %}
+      {%- endfor %}
+    }
+    {%- endif %}
+    {%- endfor %}
+  }
+  {%- endif %}
   {%- if server.secure %}
   "gpgDisableSign": false,
   "gpgDisableVerify": false,