From 297b42cd7557a7508cdbf091163da48bbd52a79a Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 28 Jul 2014 09:52:47 +0200 Subject: use ApiController#anonymous_access_allowed? There are some places where we only want to require login unless you can use EIP anonymously. So far we had an anonymous_certs_allowed? method in all these controllers. Now it's replaced with ApiController#anonymous_access_allowed?. The naming better reflects that there might be other services that allow anonymous use at some point. This also fixed a typo name -> @filename that broke the ConfigsController. --- app/controllers/v1/configs_controller.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'app/controllers/v1/configs_controller.rb') diff --git a/app/controllers/v1/configs_controller.rb b/app/controllers/v1/configs_controller.rb index 9c01605..b050f0a 100644 --- a/app/controllers/v1/configs_controller.rb +++ b/app/controllers/v1/configs_controller.rb @@ -1,7 +1,7 @@ class V1::ConfigsController < ApiController include ControllerExtension::JsonFile - before_filter :require_login, :unless => :anonymous_certs_allowed? + before_filter :require_login, :unless => :anonymous_access_allowed? before_filter :sanitize_filename, only: :show before_filter :fetch_file, only: :show @@ -21,10 +21,6 @@ class V1::ConfigsController < ApiController protected - def anonymous_certs_allowed? - APP_CONFIG[:allow_anonymous_certs] - end - def service_paths Hash[SERVICES.map{|k,v| [k,"/1/configs/#{v}"] } ] end @@ -32,7 +28,7 @@ class V1::ConfigsController < ApiController def sanitize_filename @filename = params[:id].downcase @filename += '.json' unless @filename.ends_with?('.json') - access_denied unless SERVICES.values.include? name + access_denied unless SERVICES.values.include? @filename @filename = Rails.root.join('public', '1', 'config', @filename) end end -- cgit v1.2.3 From 1092bbc337edc5973fad63bea559ecc2a3a5b896 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 28 Jul 2014 11:05:46 +0200 Subject: features for anonymous use and service endpoint Also moved the location of the config files into a configuration setting. --- app/controllers/v1/configs_controller.rb | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'app/controllers/v1/configs_controller.rb') diff --git a/app/controllers/v1/configs_controller.rb b/app/controllers/v1/configs_controller.rb index b050f0a..4a6f455 100644 --- a/app/controllers/v1/configs_controller.rb +++ b/app/controllers/v1/configs_controller.rb @@ -2,7 +2,8 @@ class V1::ConfigsController < ApiController include ControllerExtension::JsonFile before_filter :require_login, :unless => :anonymous_access_allowed? - before_filter :sanitize_filename, only: :show + before_filter :sanitize_id, only: :show + before_filter :lookup_file, only: :show before_filter :fetch_file, only: :show def index @@ -13,22 +14,26 @@ class V1::ConfigsController < ApiController send_file end - SERVICES = { - soledad: "soledad-service.json", - eip: "eip-service.json", - smtp: "smtp-service.json" - } - protected + SERVICE_IDS = { + soledad: "soledad-service", + eip: "eip-service", + smtp: "smtp-service" + } + def service_paths - Hash[SERVICES.map{|k,v| [k,"/1/configs/#{v}"] } ] + Hash[SERVICE_IDS.map{|k,v| [k,"/1/configs/#{v}.json"] } ] + end + + def sanitize_id + @id = params[:id].downcase + access_denied unless SERVICE_IDS.values.include? @id end - def sanitize_filename - @filename = params[:id].downcase - @filename += '.json' unless @filename.ends_with?('.json') - access_denied unless SERVICES.values.include? @filename - @filename = Rails.root.join('public', '1', 'config', @filename) + def lookup_file + path = APP_CONFIG[:config_file_paths][@id] + not_found if path.blank? + @filename = Rails.root.join path end end -- cgit v1.2.3