summaryrefslogtreecommitdiff
path: root/app/controllers/v1/configs_controller.rb
diff options
context:
space:
mode:
authorazul <azul@leap.se>2014-07-17 12:16:07 +0200
committerazul <azul@leap.se>2014-07-17 12:16:07 +0200
commitade74d8a9091ae607586d7b287a0579a2ee7af8e (patch)
tree74273b8ba7e35d0fb3c96aa79e63c93086d15146 /app/controllers/v1/configs_controller.rb
parent952bc18e8333ca5c3e6e16f8059f84a1414d5f6f (diff)
parente86cccb4b89540f3bd403110d051b2723be781b9 (diff)
Merge pull request #176 from azul/feature/api-authenticated-configs
API: Authenticated access to config settings
Diffstat (limited to 'app/controllers/v1/configs_controller.rb')
-rw-r--r--app/controllers/v1/configs_controller.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/controllers/v1/configs_controller.rb b/app/controllers/v1/configs_controller.rb
new file mode 100644
index 0000000..accdf5a
--- /dev/null
+++ b/app/controllers/v1/configs_controller.rb
@@ -0,0 +1,34 @@
+class V1::ConfigsController < ApiController
+ include ControllerExtension::JsonFile
+
+ before_filter :require_login
+ before_filter :sanitize_filename, only: :show
+ before_filter :fetch_file, only: :show
+
+ def index
+ render json: {services: service_paths}
+ end
+
+ def show
+ send_file
+ end
+
+ SERVICES = {
+ soledad: "soledad-service.json",
+ eip: "eip-service.json",
+ smtp: "smtp-service.json"
+ }
+
+ protected
+
+ def service_paths
+ Hash[SERVICES.map{|k,v| [k,"/1/configs/#{v}"] } ]
+ end
+
+ def sanitize_filename
+ @filename = params[:id].downcase
+ @filename += '.json' unless @filename.ends_with?('.json')
+ access_denied unless SERVICES.values.include? name
+ @filename = Rails.root.join('public', '1', 'config', @filename)
+ end
+end