Module: Cased
- Defined in:
- lib/cased.rb,
lib/cased/cli.rb,
lib/cased/error.rb,
lib/cased/model.rb,
lib/cased/query.rb,
lib/cased/config.rb,
lib/cased/policy.rb,
lib/cased/cli/log.rb,
lib/cased/clients.rb,
lib/cased/context.rb,
lib/cased/version.rb,
lib/cased/response.rb,
lib/cased/cli/config.rb,
lib/cased/http/error.rb,
lib/cased/cli/session.rb,
lib/cased/http/client.rb,
lib/cased/test_helper.rb,
lib/cased/cli/identity.rb,
lib/cased/cli/recorder.rb,
lib/cased/publishers/base.rb,
lib/cased/rack_middleware.rb,
lib/cased/sensitive/range.rb,
lib/cased/context/expander.rb,
lib/cased/publishers/error.rb,
lib/cased/sensitive/result.rb,
lib/cased/sensitive/string.rb,
lib/cased/sensitive/handler.rb,
lib/cased/cli/asciinema/file.rb,
lib/cased/cli/authentication.rb,
lib/cased/collection_response.rb,
lib/cased/sensitive/processor.rb,
lib/cased/cli/asciinema/writer.rb,
lib/cased/cli/interactive_session.rb,
lib/cased/publishers/http_publisher.rb,
lib/cased/publishers/null_publisher.rb,
lib/cased/publishers/test_publisher.rb,
lib/cased/instrumentation/controller.rb,
lib/cased/instrumentation/log_subscriber.rb,
lib/cased/publishers/active_support_publisher.rb,
lib/cased/integrations/sidekiq/client_middleware.rb,
lib/cased/integrations/sidekiq/server_middleware.rb
Defined Under Namespace
Modules: CLI, HTTP, Instrumentation, Integrations, Model, Publishers, Sensitive, TestHelper Classes: Clients, CollectionResponse, Config, Context, Error, Policy, Query, RackMiddleware, Response
Constant Summary collapse
- VERSION =
'0.8.0'
Class Attribute Summary collapse
-
.publishers ⇒ Array<Cased::Publishers::Base>
The list of publishers that will receive the processed audit event when calling Cased.publish.
Class Method Summary collapse
- .clients ⇒ Object
- .config ⇒ Cased::Config
- .configure(&block) ⇒ void
-
.console(options = {}) ⇒ void
Configures a default context for console sessions.
- .context ⇒ Cased::Context
-
.exception_handler ⇒ Proc?
Applications can determine where they want exceptions generated by Cased to be sent.
-
.exception_handler=(handler) ⇒ void
Sets the system user to be used for Cased events that do not contain an actor.
-
.handle_exception(exception) ⇒ void
The main entry point to handling any exceptions encountered in the event creation lifecycle.
-
.id(model) ⇒ String
Generates Cased compatible resource identifier.
- .policies ⇒ Hash{Symbol => Cased::Policy, nil}
-
.policy ⇒ Cased::Policy?
Helper method for accessing the applications default policy.
- .publish(audit_event) ⇒ Array, false
- .sensitive(label, handler) ⇒ Object
-
.silence ⇒ Object
Don’t send any events to Cased that are created within the lifecycle of the block.
Class Attribute Details
.publishers ⇒ Array<Cased::Publishers::Base>
The list of publishers that will receive the processed audit event when calling Cased.publish.
The desired behavior for Cased.publish should not change based on the order of the publishers.
95 96 97 98 99 100 |
# File 'lib/cased.rb', line 95 def self.publishers @publishers ||= [ Cased::Publishers::HTTPPublisher.new, Cased::Publishers::ActiveSupportPublisher.new, ] end |
Class Method Details
.clients ⇒ Object
102 103 104 |
# File 'lib/cased.rb', line 102 def self.clients @clients ||= Cased::Clients.new end |
.config ⇒ Cased::Config
63 64 65 |
# File 'lib/cased.rb', line 63 def self.config @config ||= Cased::Config.new end |
.configure(&block) ⇒ void
This method returns an undefined value.
73 74 75 |
# File 'lib/cased.rb', line 73 def self.configure(&block) block.call(config) end |
.console(options = {}) ⇒ void
This method returns an undefined value.
Configures a default context for console sessions.
When a console session is started you don’t have the context generated from a typical web request lifecycle where authentication will happen and an IP address is present. This uses the server’s hostname as a standard location for migrations or data transitions.
209 210 211 212 213 |
# File 'lib/cased.rb', line 209 def self.console( = {}) context.merge({ location: Socket.gethostname, }.merge()) end |
.context ⇒ Cased::Context
145 146 147 |
# File 'lib/cased.rb', line 145 def self.context Context.current end |
.exception_handler ⇒ Proc?
Applications can determine where they want exceptions generated by Cased to be sent.
169 170 171 |
# File 'lib/cased.rb', line 169 def self.exception_handler @exception_handler end |
.exception_handler=(handler) ⇒ void
This method returns an undefined value.
Sets the system user to be used for Cased events that do not contain an actor.
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/cased.rb', line 185 def self.exception_handler=(handler) if handler.nil? @exception_handler = nil return elsif !handler.respond_to?(:call) @exception_handler = nil raise ArgumentError, "#{handler.class} does not respond to #call" elsif handler.arity != 1 raise ArgumentError, 'handler does not accept any arguments' end @exception_handler = handler end |
.handle_exception(exception) ⇒ void
This method returns an undefined value.
The main entry point to handling any exceptions encountered in the event creation lifecycle.
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cased.rb', line 155 def self.handle_exception(exception) raise exception if config.raise_on_errors? if exception_handler.nil? warn exception. return end exception_handler.call(exception) end |
.id(model) ⇒ String
Generates Cased compatible resource identifier.
222 223 224 225 226 |
# File 'lib/cased.rb', line 222 def self.id(model) raise Cased::Error::MissingIdentifier unless model.respond_to?(:cased_id) model.cased_id end |
.policies ⇒ Hash{Symbol => Cased::Policy, nil}
37 38 39 40 41 42 43 |
# File 'lib/cased.rb', line 37 def self.policies @policies ||= Hash.new do |hash, name| key = name.to_sym api_key = Cased.config.policy_key(key) hash[key] = Policy.new(api_key: api_key) end end |
.policy ⇒ Cased::Policy?
Helper method for accessing the applications default policy.
58 59 60 |
# File 'lib/cased.rb', line 58 def self.policy policies[:default] end |
.publish(audit_event) ⇒ Array, false
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/cased.rb', line 128 def self.publish(audit_event) return false if config.silence? processed_audit_event = process(audit_event) publishers.each do |publisher| unless publisher.respond_to?(:publish) raise ArgumentError, "#{publisher.class} must implement #{publisher.class}#publish" end publisher.publish(processed_audit_event.dup) rescue StandardError => e handle_exception(e) end end |
.sensitive(label, handler) ⇒ Object
28 29 30 |
# File 'lib/cased.rb', line 28 def self.sensitive(label, handler) Cased::Sensitive::Handler.register(label, handler) end |
.silence ⇒ Object
Don’t send any events to Cased that are created within the lifecycle of the block.
234 235 236 237 238 239 240 |
# File 'lib/cased.rb', line 234 def self.silence original_silence = config.silence? config.silence = true yield ensure config.silence = original_silence end |