class Cased::Config
Attributes
The Cased
HTTP
API URL. Defaults to api.cased.com
@example
CASED_API_URL="https://api.cased.com" rails server
@example
Cased.configure do |config| config.api_url = "https://api.cased.com" end
@example
Cased.configure do |config| config.cli.metadata = { rails_env: ENV['RAILS_ENV'], heroku_application: ENV['HEROKU_APP_NAME'], git_commit: ENV['GIT_COMMIT'], } end
@example
GUARD_APPLICATION_KEY="guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH" rails server
@example
Cased.configure do |config| config.guard_application_key = "guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH" end
@example
DENY_IF_UNREACHABLE="1" rails server
@example
Cased.configure do |config| config.guard_deny_if_unreachable = true end
@example
GUARD_USER_TOKEN="user_1oFqlROLNRGVLOXJSsHkJiVmylr" rails server
@example
Cased.configure do |config| config.guard_user_token = "user_1oFqlROLNRGVLOXJSsHkJiVmylr" end
The amount of time in seconds to allow the HTTP
client to open a connection.
@example
CASED_HTTP_OPEN_TIMEOUT="5" rails server
@example
Cased.configure do |config| config.http_open_timeout = 5 end
The amount of time in seconds to allow the HTTP
client to read a response from the server before timing out.
@example
CASED_HTTP_READ_TIMEOUT="10" rails server
@example
Cased.configure do |config| config.http_read_timeout = 10 end
@example
CASED_ORGANIZATION_POLICY_KEY="policy_live_1dQpY2mRu3pTCcNGB7a6ewx4WFp" \ CASED_SECURITY_POLICY_KEY="policy_live_1dQpY9Erf3cKUrooz0BQKmCD4Oc" \ CASED_USER_POLICY_KEY="policy_live_1dSHQRbtjj17LanuAgpHd3QKtOO" \ rails server
@example
Cased.configure do |config| config.policy_keys = { organization: "policy_live_1dQpY2mRu3pTCcNGB7a6ewx4WFp", security: "policy_live_1dQpY9Erf3cKUrooz0BQKmCD4Oc", user: "policy_live_1dSHQRbtjj17LanuAgpHd3QKtOO", } end
Publish keys are used to publish to an audit trail.
A publish key is associated with a single audit trail and is required if you intend to publish events to Cased
in your application.
@example
CASED_PUBLISH_KEY="publish_test_5dSfh6xZAuL2Esn3Z2XSM6ReMS21" rails server
@example
Cased.configure do |config| config.publish_key = "publish_test_5dSfh6xZAuL2Esn3Z2XSM6ReMS21" end
The URL to publish audit events to. Defaults to publish.cased.com
@example
CASED_PUBLISH_URL="https://publish.cased.com" rails server
@example
Cased.configure do |config| config.publish_url = "https://publish.cased.com" end
Policy
keys are used to query for events from audit trails.
@example
CASED_POLICY_KEY="policy_live_1dQpY1fUFHzENWhTVMvjCilAKp9" rails server
@example
Cased.configure do |config| config.raise_on_errors = !Rails.env.production? end
Configure whether or not Cased
will attempt to publish any events.
If the CASED_SILENCE environment variable is not nil Cased
will not publish events.
@example
CASED_SILENCE="1" rails server
@example
Cased.configure do |config| config.silence = Rails.env.test? end
@example
Cased.silence do User.create! end
The Cased
HTTP
URL. Defaults to app.cased.com
@example
CASED_URL="https://app.cased.com" rails server
@example
Cased.configure do |config| config.url = "https://app.cased.com" end
@return [String]
Public Class Methods
# File lib/cased/config.rb, line 164 def initialize @http_read_timeout = ENV.fetch('CASED_HTTP_READ_TIMEOUT', 10).to_i @http_open_timeout = ENV.fetch('CASED_HTTP_OPEN_TIMEOUT', 5).to_i @raise_on_errors = !ENV['CASED_RAISE_ON_ERRORS'].nil? @url = ENV.fetch('CASED_URL', 'https://app.cased.com') @api_url = ENV.fetch('CASED_API_URL', 'https://api.cased.com') @publish_url = ENV.fetch('CASED_PUBLISH_URL', 'https://publish.cased.com') @guard_application_key = ENV['GUARD_APPLICATION_KEY'] @guard_user_token = ENV['GUARD_USER_TOKEN'] self.guard_deny_if_unreachable = ENV['DENY_IF_UNREACHABLE'] @publish_key = ENV['CASED_PUBLISH_KEY'] @silence = !ENV['CASED_SILENCE'].nil? @policy_keys = Hash.new do |hash, key| normalized_key = key.to_sym if normalized_key == :default hash[normalized_key] = ENV['CASED_POLICY_KEY'] else env_policy_name = key.to_s.tr(' ', '_').tr('-', '_').upcase api_key = ENV["CASED_#{env_policy_name}_POLICY_KEY"] hash[normalized_key] = api_key if api_key end end @cli = Cased::CLI::Config.new end
Public Instance Methods
# File lib/cased/config.rb, line 229 def guard_deny_if_unreachable=(value) @guard_deny_if_unreachable = parse_bool(value) end
# File lib/cased/config.rb, line 233 def guard_deny_if_unreachable? @guard_deny_if_unreachable end
# File lib/cased/config.rb, line 217 def http_open_timeout=(new_val) @http_open_timeout = new_val.to_i end
# File lib/cased/config.rb, line 213 def http_read_timeout=(new_val) @http_read_timeout = new_val.to_i end
Policy
keys are used to query for events from audit trails.
@param [Symbol] policy name
@example
CASED_POLICY_KEY="policy_live_1dQpY1fUFHzENWhTVMvjCilAKp9" rails server
@example
Cased.configure do |config| config.policy_key = "policy_live_1dQpY1fUFHzENWhTVMvjCilAKp9" end
# File lib/cased/config.rb, line 201 def policy_key(policy = :default) policy_keys[policy.to_sym] end
# File lib/cased/config.rb, line 205 def policy_key=(api_key) policy_keys[:default] = api_key end
# File lib/cased/config.rb, line 209 def raise_on_errors=(new_val) @raise_on_errors = !!new_val end
# File lib/cased/config.rb, line 221 def raise_on_errors? @raise_on_errors end
# File lib/cased/config.rb, line 225 def silence? @silence || !ENV['CASED_SILENCE'].nil? end
Private Instance Methods
# File lib/cased/config.rb, line 239 def parse_bool(val) %w[1 true t].include?(val.to_s&.downcase) end