summaryrefslogtreecommitdiff
path: root/app/controllers/v1/configs_controller.rb
blob: 0af21d2637c57ef8964e6f22c29adcf0f29c194f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class V1::ConfigsController < ApiController
  include ControllerExtension::JsonFile

  before_filter :require_login, :unless => :anonymous_certs_allowed?
  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 anonymous_certs_allowed?
    APP_CONFIG[:allow_anonymous_certs]
  end

  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? @filename
    @filename = Rails.root.join('public', '1', 'config', @filename)
  end
end