summaryrefslogtreecommitdiff
path: root/app/controllers/v1
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-07-14 13:04:30 +0200
committerAzul <azul@leap.se>2014-07-14 13:04:30 +0200
commitf07c952c870bfb8634ef0d80737b67a1eec760f6 (patch)
treeba6945d4ceb7ef1adfff92c9de89482e345c6838 /app/controllers/v1
parentb80be9832526ee956b3a73a634896c6cd8d2914e (diff)
send config files from ConfigsController
Diffstat (limited to 'app/controllers/v1')
-rw-r--r--app/controllers/v1/configs_controller.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/app/controllers/v1/configs_controller.rb b/app/controllers/v1/configs_controller.rb
index 537123f..0b2a64a 100644
--- a/app/controllers/v1/configs_controller.rb
+++ b/app/controllers/v1/configs_controller.rb
@@ -1,20 +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: CONFIGS
+ render json: {services: service_paths}
end
def show
+ send_file
end
- CONFIGS = {
- services: {
- soledad: "/1/configs/soledad-service.json",
- eip: "/1/configs/eip-service.json",
- smtp: "/1/configs/smtp-service.json"
- }
+ 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/#{str}"] } ]
+ 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