Module: Wurk::Redact
- Defined in:
- lib/wurk/redact.rb
Overview
Display-side argument redaction. A host sets
config.redact_args = ->(job) { [job['args'].first, '[FILTERED]'] }
and every surface that SHOWS a job's arguments — the job logger's args
context (when listed in logged_job_attributes) and JobRecord#display_args,
which feeds the dashboard JSON, search and the /v1 API — shows the returned
array instead. The payload in Redis, and the args
perform receives, are never touched: the hook gets a deep copy, so even a
hook that mutates its argument cannot reach the real job.
nil (the default) leaves every surface exactly as it was. The hook runs on encrypted jobs too: Encryption hides only the trailing ciphertext argument, and the plaintext ones before it are what a host usually needs to filter.
Constant Summary collapse
- FAILED =
Fail closed: a hook that raises must not fall back to showing the args it was installed to hide.
['[REDACTED: redact_args raised]'].freeze
- UNPARSEABLE =
'[REDACTED: unparseable job]'
Class Method Summary collapse
-
.args(job, hook) ⇒ Object
The args to display for
job(a parsed payload Hash) underhook. - .hook(config = Wurk.configuration) ⇒ Object
-
.jobstr(raw, hook) ⇒ Object
A raw payload string, with its args replaced.
Class Method Details
.args(job, hook) ⇒ Object
The args to display for job (a parsed payload Hash) under hook.
44 45 46 47 48 49 |
# File 'lib/wurk/redact.rb', line 44 def args(job, hook) result = hook.call(::JSON.parse(::JSON.generate(job))) result.is_a?(Array) ? result : [result] rescue StandardError FAILED end |
.hook(config = Wurk.configuration) ⇒ Object
28 29 30 |
# File 'lib/wurk/redact.rb', line 28 def hook(config = Wurk.configuration) config.redact_args end |
.jobstr(raw, hook) ⇒ Object
A raw payload string, with its args replaced. Anything that does not parse to a job, or to JSON at all, could be holding the args in any shape: it is dropped.
34 35 36 37 38 39 40 41 |
# File 'lib/wurk/redact.rb', line 34 def jobstr(raw, hook) job = ::JSON.parse(raw) return UNPARSEABLE unless job.is_a?(::Hash) ::JSON.generate(job.merge('args' => args(job, hook))) rescue ::JSON::ParserError, ::EncodingError, ::TypeError UNPARSEABLE end |