Class: Graphql::Dashboard::Limiters::LimitersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Graphql::Dashboard::Limiters::LimitersController
- Includes:
- Installable
- Defined in:
- lib/graphql/dashboard/limiters.rb
Constant Summary collapse
- FALLBACK_CSP_NONCE_GENERATOR =
->(_req) { SecureRandom.hex(32) }
Instance Method Summary collapse
Methods included from Installable
Methods inherited from ApplicationController
Instance Method Details
#show ⇒ Object
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 39 40 |
# File 'lib/graphql/dashboard/limiters.rb', line 10 def show name = params[:name] @title = case name when "runtime" "Runtime Limiter" when "active_operations" "Active Operation Limiter" when "mutations" "Mutation Limiter" else raise ArgumentError, "Unknown limiter name: #{name}" end limiter = limiter_for(name) if limiter.nil? @install_path = "http://graphql-ruby.org/limiters/#{name}" else @chart_mode = params[:chart] || "day" @current_soft = limiter.soft_limit_enabled? @histogram = limiter.dashboard_histogram(@chart_mode) # These configs may have already been defined by the application; provide overrides here if not. request.content_security_policy_nonce_generator ||= FALLBACK_CSP_NONCE_GENERATOR nonce_dirs = request.content_security_policy_nonce_directives || [] if !nonce_dirs.include?("style-src") nonce_dirs += ["style-src"] request.content_security_policy_nonce_directives = nonce_dirs end @csp_nonce = request.content_security_policy_nonce end end |
#update ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/graphql/dashboard/limiters.rb', line 42 def update name = params[:name] limiter = limiter_for(name) if limiter limiter.toggle_soft_limit flash[:success] = if limiter.soft_limit_enabled? "Enabled soft limiting -- over-limit traffic will be logged but not rejected." else "Disabled soft limiting -- over-limit traffic will be rejected." end else flash[:warning] = "No limiter configured for #{name.inspect}" end redirect_to graphql_dashboard.limiters_limiter_path(name, chart: params[:chart]) end |