From 23410116c6cde619eddd7fc4032d7762177560f8 Mon Sep 17 00:00:00 2001
From: Michael Krotscheck <krotscheck@gmail.com>
Date: Thu, 25 Sep 2014 14:48:51 -0700
Subject: [PATCH] Added CORS configuration to puppet-storyboard

Storyboard will soon support CORS, which is configured via
storyboard.conf. This patch adds the two relevant properties
to the puppet module, and makes them accessible in
storyboard::application.

Depends on https://review.openstack.org/#/c/124163/

Change-Id: I33a33076a18a9192b067a9f6f08d752ff8c22e3b
---
 Modulefile                    |  1 +
 manifests/application.pp      |  8 ++++++++
 templates/storyboard.conf.erb | 12 ++++++++++++
 3 files changed, 21 insertions(+)

diff --git a/Modulefile b/Modulefile
index 26d166d..16647cc 100644
--- a/Modulefile
+++ b/Modulefile
@@ -8,6 +8,7 @@ description 'This module configures StoryBoard either as a standalone, localhost
 project_page 'https://github.com/openstack-ci/puppet-storyboard'
 
 ## Add dependencies, if any:
+dependency 'puppetlabs/stdlib', '= 3.2.0'
 dependency 'puppetlabs/mysql', '= 0.6.1'
 dependency 'puppetlabs/apache', '= 0.0.4'
 dependency 'puppetlabs/rabbitmq', '= 4.0.0'
diff --git a/manifests/application.pp b/manifests/application.pp
index 15d0bdd..f0672ac 100644
--- a/manifests/application.pp
+++ b/manifests/application.pp
@@ -25,6 +25,8 @@ class storyboard::application (
   $www_root               = '/var/lib/storyboard/www',
   $server_admin           = undef,
   $hostname               = $::fqdn,
+  $cors_allowed_origins   = undef,
+  $cors_max_age           = 3600,
 
   # storyboard.conf parameters
   $access_token_ttl       = 3600,
@@ -48,6 +50,12 @@ class storyboard::application (
   $webclient_filename = 'storyboard-webclient-latest.tar.gz'
   $webclient_url = "http://tarballs.openstack.org/storyboard-webclient/${webclient_filename}"
 
+  if $cors_allowed_origins {
+    $cors_allowed_origins_string = join($cors_allowed_origins, ',')
+  } else {
+    $cors_allowed_origins_string = undef
+  }
+
   # Dependencies
   require storyboard::params
   include apache
diff --git a/templates/storyboard.conf.erb b/templates/storyboard.conf.erb
index 8a39660..7797404 100644
--- a/templates/storyboard.conf.erb
+++ b/templates/storyboard.conf.erb
@@ -50,6 +50,18 @@ refresh_token_ttl = <%= @refresh_token_ttl %>
 # and subscriptions.
 enable_notifications = <%= @enable_notifications %>
 
+<% if scope.lookupvar("storyboard::application::cors_allowed_origins_string") != :undef %>
+[cors]
+# W3C CORS configuration. For more information, see http://www.w3.org/TR/cors/
+
+# List of permitted CORS domains.
+allowed_origins = <%= @cors_allowed_origins_string %>
+
+# CORS browser options cache max age (in seconds)
+max_age=<%= @cors_max_age %>
+
+<% end %>
+
 [database]
 # This line MUST be changed to actually run storyboard
 # Example: