Module: PromptSanitizer::Audit
- Defined in:
- lib/prompt_sanitizer/audit/base.rb,
lib/prompt_sanitizer/audit/memory_audit_log.rb
Defined Under Namespace
Classes: AuditEvent, Base, MemoryAuditLog
Class Method Summary collapse
-
.hash_value(value) ⇒ Object
Compute a SHA-256 prefix hash of a PII value for safe audit storage.
-
.now_iso ⇒ Object
Return the current UTC time as an ISO-8601 string.
-
.parse_since(since) ⇒ Object
Parse a "since" argument into a comparable UTC Time.
Class Method Details
.hash_value(value) ⇒ Object
Compute a SHA-256 prefix hash of a PII value for safe audit storage.
29 30 31 |
# File 'lib/prompt_sanitizer/audit/base.rb', line 29 def self.hash_value(value) Digest::SHA256.hexdigest(value.to_s)[0, 16] end |
.now_iso ⇒ Object
Return the current UTC time as an ISO-8601 string.
34 35 36 |
# File 'lib/prompt_sanitizer/audit/base.rb', line 34 def self.now_iso Time.now.utc.iso8601 end |
.parse_since(since) ⇒ Object
Parse a "since" argument into a comparable UTC Time.
Accepts:
nil→ no cutoff- Integer → seconds ago
- "7d" → 7 days ago
- "12h" → 12 hours ago
- Time → as-is
- ISO-8601 String → parsed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/prompt_sanitizer/audit/base.rb', line 47 def self.parse_since(since) return nil if since.nil? return since if since.is_a?(Time) if since.is_a?(String) if since =~ /\A(\d+)d\z/ Time.now.utc - (Regexp.last_match(1).to_i * 86_400) - 1 elsif since =~ /\A(\d+)h\z/ Time.now.utc - (Regexp.last_match(1).to_i * 3_600) - 1 else Time.parse(since).utc end elsif since.is_a?(Integer) Time.now.utc - since end end |