Module: OllamaChat::Utils::Redact
- Included in:
- Information, Tools::Concern, Fetcher
- Defined in:
- lib/ollama_chat/utils/redact.rb
Overview
Redacts credentials from URLs for safe, user-facing display.
Whenever a URL that may carry a password (e.g.
http://user:secret@host) is about to be printed to the terminal or
echoed back to the model, run it through #redact_password so the
secret is masked as ***.
The module can also be +include+d to gain #redact_password as a private helper on the host class.
Class Method Summary collapse
-
.redact_password(url) ⇒ String
Returns the URL as a string with its password component replaced by
***.
Instance Method Summary collapse
-
#redact_password(url) ⇒ String
private
Returns the URL as a string with its password component replaced by
***.
Class Method Details
.redact_password(url) ⇒ String
Returns the URL as a string with its password component replaced by
***. Accepts a URI or a plain String (parsed on the fly). The
original object is never mutated: a duplicate is redacted and the
result returned as a string. URLs without a password are returned
unchanged.
27 28 29 30 31 |
# File 'lib/ollama_chat/utils/redact.rb', line 27 def redact_password(url) uri = url.is_a?(String) ? URI.parse(url) : url.dup uri.password = '***' if uri.password uri.to_s end |
Instance Method Details
#redact_password(url) ⇒ String (private)
Returns the URL as a string with its password component replaced by
***. Accepts a URI or a plain String (parsed on the fly). The
original object is never mutated: a duplicate is redacted and the
result returned as a string. URLs without a password are returned
unchanged.
27 28 29 30 31 |
# File 'lib/ollama_chat/utils/redact.rb', line 27 def redact_password(url) uri = url.is_a?(String) ? URI.parse(url) : url.dup uri.password = '***' if uri.password uri.to_s end |