Class: Cased::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cased/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# 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

Instance Attribute Details

#api_urlObject

The Cased HTTP API URL. Defaults to api.cased.com

Examples:

CASED_API_URL="https://api.cased.com" rails server
Cased.configure do |config|
  config.api_url = "https://api.cased.com"
end


53
54
55
# File 'lib/cased/config.rb', line 53

def api_url
  @api_url
end

#cliObject (readonly)

Examples:

Cased.configure do |config|
  config.cli. = {
    rails_env: ENV['RAILS_ENV'],
    heroku_application: ENV['HEROKU_APP_NAME'],
    git_commit: ENV['GIT_COMMIT'],
  }
end


162
163
164
# File 'lib/cased/config.rb', line 162

def cli
  @cli
end

#guard_application_keyObject

Examples:

GUARD_APPLICATION_KEY="guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH" rails server
Cased.configure do |config|
  config.guard_application_key = "guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH"
end


62
63
64
# File 'lib/cased/config.rb', line 62

def guard_application_key
  @guard_application_key
end

#guard_deny_if_unreachableObject

Examples:

DENY_IF_UNREACHABLE="1" rails server
Cased.configure do |config|
  config.guard_deny_if_unreachable = true
end


80
81
82
# File 'lib/cased/config.rb', line 80

def guard_deny_if_unreachable
  @guard_deny_if_unreachable
end

#guard_user_tokenObject

Examples:

GUARD_USER_TOKEN="user_1oFqlROLNRGVLOXJSsHkJiVmylr" rails server
Cased.configure do |config|
  config.guard_user_token = "user_1oFqlROLNRGVLOXJSsHkJiVmylr"
end


71
72
73
# File 'lib/cased/config.rb', line 71

def guard_user_token
  @guard_user_token
end

#http_open_timeoutObject

The amount of time in seconds to allow the HTTP client to open a connection.

Examples:

CASED_HTTP_OPEN_TIMEOUT="5" rails server
Cased.configure do |config|
  config.http_open_timeout = 5
end


17
18
19
# File 'lib/cased/config.rb', line 17

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

The amount of time in seconds to allow the HTTP client to read a response from the server before timing out.

Examples:

CASED_HTTP_READ_TIMEOUT="10" rails server
Cased.configure do |config|
  config.http_read_timeout = 10
end


29
30
31
# File 'lib/cased/config.rb', line 29

def http_read_timeout
  @http_read_timeout
end

#policy_keysObject (readonly)

Examples:

CASED_ORGANIZATION_POLICY_KEY="policy_live_1dQpY2mRu3pTCcNGB7a6ewx4WFp" \
CASED_SECURITY_POLICY_KEY="policy_live_1dQpY9Erf3cKUrooz0BQKmCD4Oc" \
CASED_USER_POLICY_KEY="policy_live_1dSHQRbtjj17LanuAgpHd3QKtOO" \
  rails server
Cased.configure do |config|
  config.policy_keys = {
    organization: "policy_live_1dQpY2mRu3pTCcNGB7a6ewx4WFp",
    security: "policy_live_1dQpY9Erf3cKUrooz0BQKmCD4Oc",
    user: "policy_live_1dSHQRbtjj17LanuAgpHd3QKtOO",
  }
end


122
123
124
# File 'lib/cased/config.rb', line 122

def policy_keys
  @policy_keys
end

#publish_keyObject

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.

Examples:

CASED_PUBLISH_KEY="publish_test_5dSfh6xZAuL2Esn3Z2XSM6ReMS21" rails server
Cased.configure do |config|
  config.publish_key = "publish_test_5dSfh6xZAuL2Esn3Z2XSM6ReMS21"
end


105
106
107
# File 'lib/cased/config.rb', line 105

def publish_key
  @publish_key
end

#publish_urlObject

The URL to publish audit events to. Defaults to publish.cased.com

Examples:

CASED_PUBLISH_URL="https://publish.cased.com" rails server
Cased.configure do |config|
  config.publish_url = "https://publish.cased.com"
end


91
92
93
# File 'lib/cased/config.rb', line 91

def publish_url
  @publish_url
end

#raise_on_errorsObject

Policy keys are used to query for events from audit trails.

Examples:

CASED_POLICY_KEY="policy_live_1dQpY1fUFHzENWhTVMvjCilAKp9" rails server
Cased.configure do |config|
  config.raise_on_errors = !Rails.env.production?
end


133
134
135
# File 'lib/cased/config.rb', line 133

def raise_on_errors
  @raise_on_errors
end

#silence=(value) ⇒ Object (writeonly)

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.

Examples:

CASED_SILENCE="1" rails server
Cased.configure do |config|
  config.silence = Rails.env.test?
end
Cased.silence do
  User.create!
end


152
153
154
# File 'lib/cased/config.rb', line 152

def silence=(value)
  @silence = value
end

#urlString

The Cased HTTP URL. Defaults to app.cased.com

Examples:

CASED_URL="https://app.cased.com" rails server
Cased.configure do |config|
  config.url = "https://app.cased.com"
end

Returns:

  • (String)


42
43
44
# File 'lib/cased/config.rb', line 42

def url
  @url
end

Instance Method Details

#guard_deny_if_unreachable?Boolean

Returns:

  • (Boolean)


233
234
235
# File 'lib/cased/config.rb', line 233

def guard_deny_if_unreachable?
  @guard_deny_if_unreachable
end

#policy_key(policy = :default) ⇒ Object

Policy keys are used to query for events from audit trails.

Examples:

CASED_POLICY_KEY="policy_live_1dQpY1fUFHzENWhTVMvjCilAKp9" rails server
Cased.configure do |config|
  config.policy_key = "policy_live_1dQpY1fUFHzENWhTVMvjCilAKp9"
end

Parameters:

  • policy (Symbol) (defaults to: :default)

    name



201
202
203
# File 'lib/cased/config.rb', line 201

def policy_key(policy = :default)
  policy_keys[policy.to_sym]
end

#policy_key=(api_key) ⇒ Object



205
206
207
# File 'lib/cased/config.rb', line 205

def policy_key=(api_key)
  policy_keys[:default] = api_key
end

#raise_on_errors?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/cased/config.rb', line 221

def raise_on_errors?
  @raise_on_errors
end

#silence?Boolean

Returns:

  • (Boolean)


225
226
227
# File 'lib/cased/config.rb', line 225

def silence?
  @silence || !ENV['CASED_SILENCE'].nil?
end