Module: PgSqlTriggers::KillSwitchProtection
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/controllers/concerns/pg_sql_triggers/kill_switch_protection.rb
Instance Method Summary collapse
-
#check_kill_switch(operation:, confirmation: nil) ⇒ true
Checks kill switch before executing a dangerous operation.
-
#current_environment ⇒ String
Returns the current environment.
-
#expected_confirmation_text(operation) ⇒ String
Returns the expected confirmation text for an operation (for use in views).
-
#kill_switch_active? ⇒ Boolean
Checks if kill switch is active for the current environment.
-
#require_kill_switch_override(operation, confirmation: nil) ⇒ Object
Before action to require kill switch override for an action.
Instance Method Details
#check_kill_switch(operation:, confirmation: nil) ⇒ true
Checks kill switch before executing a dangerous operation. Raises KillSwitchError if the operation is blocked.
26 27 28 29 30 31 32 33 |
# File 'app/controllers/concerns/pg_sql_triggers/kill_switch_protection.rb', line 26 def check_kill_switch(operation:, confirmation: nil) PgSqlTriggers::SQL::KillSwitch.check!( operation: operation, environment: current_environment, confirmation: confirmation, actor: current_actor ) end |
#current_environment ⇒ String
Returns the current environment.
62 63 64 |
# File 'app/controllers/concerns/pg_sql_triggers/kill_switch_protection.rb', line 62 def current_environment Rails.env end |
#expected_confirmation_text(operation) ⇒ String
Returns the expected confirmation text for an operation (for use in views).
50 51 52 53 54 55 56 57 |
# File 'app/controllers/concerns/pg_sql_triggers/kill_switch_protection.rb', line 50 def expected_confirmation_text(operation) if PgSqlTriggers.respond_to?(:kill_switch_confirmation_pattern) && PgSqlTriggers.kill_switch_confirmation_pattern.respond_to?(:call) PgSqlTriggers.kill_switch_confirmation_pattern.call(operation) else "EXECUTE #{operation.to_s.upcase}" end end |
#kill_switch_active? ⇒ Boolean
Checks if kill switch is active for the current environment.
15 16 17 |
# File 'app/controllers/concerns/pg_sql_triggers/kill_switch_protection.rb', line 15 def kill_switch_active? PgSqlTriggers::SQL::KillSwitch.active?(environment: current_environment) end |
#require_kill_switch_override(operation, confirmation: nil) ⇒ Object
Before action to require kill switch override for an action. Add to specific controller actions that need protection:
before_action -> { require_kill_switch_override(:operation_name) }, only: [:dangerous_action]
42 43 44 |
# File 'app/controllers/concerns/pg_sql_triggers/kill_switch_protection.rb', line 42 def require_kill_switch_override(operation, confirmation: nil) check_kill_switch(operation: operation, confirmation: confirmation) end |