auth-sanitizer 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a459f96a2569fc0a45f1f0fcc919d6324f64902e4ed7364a617aebed42b6936a
4
- data.tar.gz: 7e27c3b29c2f47b0afcf740098f14472f3f936828df479e4a3e808d8259523ad
3
+ metadata.gz: fe6ea000d97d7116cf66f7a69b7c8f7d4ea7dc6e1dbdc7df6f073a79841c8513
4
+ data.tar.gz: 77955bc562916c9de289b05111325bcc5b42d40633747f241e5c33a82d99ad1a
5
5
  SHA512:
6
- metadata.gz: 86ea9c3a4721881b599ba6e63a50cc0d9f4b5a9d5c8dbe1c7bd140ce802c4d28d1df0278b4f16aee472c7feabe34e30c6d16dc5943c12a4c6a9a429519de9e82
7
- data.tar.gz: 381e1f25c5bd0301f3d1ba91f6f20a6370e6d6158a87270f166e85a84abc556dc865b0c1a2f8d449ba7b08b82ad34b8c4589601bb8ff09bfc72c96c4ef14b2e0
6
+ metadata.gz: 31f37a6ccaa844c1de2b88e0f80b3bf361dd73be273dd1a7825464c5c1f1b9a80a7740e75e8a4654e1ba036a8e1d4597aa527f6b853306cf605d2bf99312618a
7
+ data.tar.gz: a6317b6c5419c44f15be4d53c858d54a233b892f9f0a52324d8620e1d2037d1494190cebcab91d44ba223805b35326cdc563d5b2d1bdbe39c422b35df6d3f33a
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -30,6 +30,18 @@ Please file a bug if you notice a violation of semantic versioning.
30
30
 
31
31
  ### Security
32
32
 
33
+ ## [0.1.3] - 2026-05-20
34
+
35
+ - TAG: [v0.1.3][0.1.3t]
36
+ - COVERAGE: 100.00% -- 135/135 lines in 6 files
37
+ - BRANCH COVERAGE: 100.00% -- 28/28 branches in 6 files
38
+ - 84.62% documented
39
+
40
+ ### Added
41
+
42
+ - Add `AuthSanitizer::Loader.load_isolated` for isolated loading without defining top-level `Auth`
43
+ - Document zero-top-level-namespace loading for consumers that need to avoid defining `Auth` or `AuthSanitizer`
44
+
33
45
  ## [0.1.2] - 2026-05-15
34
46
 
35
47
  - TAG: [v0.1.2][0.1.2t]
@@ -67,7 +79,9 @@ Please file a bug if you notice a violation of semantic versioning.
67
79
 
68
80
  - Initial release
69
81
 
70
- [Unreleased]: https://github.com//ruby-oauth/auth-sanitizer/compare/v0.1.2...HEAD
82
+ [Unreleased]: https://github.com//ruby-oauth/auth-sanitizer/compare/v0.1.3...HEAD
83
+ [0.1.3]: https://github.com//ruby-oauth/auth-sanitizer/compare/v0.1.2...v0.1.3
84
+ [0.1.3t]: https://github.com//ruby-oauth/auth-sanitizer/releases/tag/v0.1.3
71
85
  [0.1.2]: https://github.com//ruby-oauth/auth-sanitizer/compare/v0.1.1...v0.1.2
72
86
  [0.1.2t]: https://github.com//ruby-oauth/auth-sanitizer/releases/tag/v0.1.2
73
87
  [0.1.1]: https://github.com//ruby-oauth/auth-sanitizer/compare/v0.1.0...v0.1.1
data/README.md CHANGED
@@ -58,6 +58,25 @@ a provider, or per logger by passing `label:` to `Auth::Sanitizer::SanitizedLogg
58
58
  The library snapshots filter configuration when a redacting object is initialized. That keeps already-created objects
59
59
  and logger wrappers stable even if a host application changes its configuration later.
60
60
 
61
+ Consumers that need to avoid defining the generic top-level `Auth` namespace can use the isolated loader:
62
+
63
+ ```ruby
64
+ require "auth_sanitizer/loader"
65
+
66
+ AUTH_SANITIZER = AuthSanitizer::Loader.load_isolated
67
+ ```
68
+
69
+ The returned module is an anonymously namespaced `Auth::Sanitizer`, suitable for internal assignment in host gems.
70
+ Use `require: false` in gems that want to avoid every new top-level namespace, including `AuthSanitizer`; see
71
+ [Zero Top-Level Namespace Additions](#zero-top-level-namespace-additions).
72
+
73
+ This gem is used by the following libraries to ensure clean output:
74
+
75
+ - oauth
76
+ - oauth-tty
77
+ - oauth2
78
+ - omniauth-ldap
79
+
61
80
  ## 💡 Info you can shake a stick at
62
81
 
63
82
  | Tokens to Remember | [![Gem name][⛳️name-img]][⛳️gem-name] [![Gem namespace][⛳️namespace-img]][⛳️gem-namespace] |
@@ -176,6 +195,107 @@ NOTE: Be prepared to track down certs for signed gems and add them the same way
176
195
  Most applications can use the defaults. Configuration is available when a host gem or application wants to align
177
196
  redaction with its own logging conventions.
178
197
 
198
+ ### Loading Mode
199
+
200
+ This gem has two supported loading modes.
201
+
202
+ The direct API defines the top-level `Auth` namespace:
203
+
204
+ ```ruby
205
+ require "auth/sanitizer"
206
+
207
+ class TokenResponse
208
+ include Auth::Sanitizer::FilteredAttributes
209
+ end
210
+ ```
211
+
212
+ This is convenient for applications that already own or intentionally use `Auth`.
213
+
214
+ Libraries and applications that need to avoid the generic top-level `Auth` namespace should use the isolated loader:
215
+
216
+ ```ruby
217
+ require "auth_sanitizer/loader"
218
+
219
+ AUTH_SANITIZER = AuthSanitizer::Loader.load_isolated
220
+
221
+ class TokenResponse
222
+ include AUTH_SANITIZER::FilteredAttributes
223
+ end
224
+ ```
225
+
226
+ `AuthSanitizer::Loader.load_isolated` evaluates the sanitizer implementation inside an anonymous module and returns that
227
+ module's `Auth::Sanitizer` constant. Assign the returned module to a constant owned by your library or application, then
228
+ include from that constant.
229
+
230
+ When declaring the dependency in a Gemfile, prefer one of these explicit forms:
231
+
232
+ ```ruby
233
+ gem "auth-sanitizer", require: false
234
+ ```
235
+
236
+ or:
237
+
238
+ ```ruby
239
+ gem "auth-sanitizer", require: "auth_sanitizer/loader"
240
+ ```
241
+
242
+ Use `require: false` when the consuming library will decide which loading mode to use internally. Use
243
+ `require: "auth_sanitizer/loader"` when Bundler should make the isolated loader available during `Bundler.require`.
244
+
245
+ #### Zero Top-Level Namespace Additions
246
+
247
+ A gem that needs zero new top-level namespaces from this dependency can load the loader itself inside an anonymous
248
+ namespace. On Ruby 3.1+, use `Kernel.load(path, module)`:
249
+
250
+ ```ruby
251
+ auth_sanitizer_spec = Gem.loaded_specs["auth-sanitizer"] ||
252
+ Gem::Specification.find_by_name("auth-sanitizer")
253
+ auth_sanitizer_loader_path = File.join(
254
+ auth_sanitizer_spec.full_gem_path,
255
+ "lib/auth_sanitizer/loader.rb",
256
+ )
257
+
258
+ auth_sanitizer_loader_namespace = Module.new
259
+ Kernel.load(auth_sanitizer_loader_path, auth_sanitizer_loader_namespace)
260
+
261
+ AUTH_SANITIZER = auth_sanitizer_loader_namespace
262
+ .const_get(:AuthSanitizer)
263
+ .const_get(:Loader)
264
+ .load_isolated
265
+ ```
266
+
267
+ That pattern leaves both `Auth` and `AuthSanitizer` undefined at top level. The consuming gem should assign the returned
268
+ module under its own namespace and use that internal constant.
269
+
270
+ <details markdown="1">
271
+ <summary>Ruby 2.2-compatible zero-top-level loading</summary>
272
+
273
+ Ruby 2.2 through Ruby 3.0 do not support `Kernel.load(path, module)`. For those versions, evaluate the loader source
274
+ inside an anonymous namespace with `Module#module_eval`:
275
+
276
+ ```ruby
277
+ auth_sanitizer_spec = Gem.loaded_specs["auth-sanitizer"] ||
278
+ Gem::Specification.find_by_name("auth-sanitizer")
279
+ auth_sanitizer_loader_path = File.join(
280
+ auth_sanitizer_spec.full_gem_path,
281
+ "lib/auth_sanitizer/loader.rb",
282
+ )
283
+
284
+ auth_sanitizer_loader_namespace = Module.new
285
+ auth_sanitizer_loader_namespace.module_eval(
286
+ File.read(auth_sanitizer_loader_path),
287
+ auth_sanitizer_loader_path,
288
+ 1,
289
+ )
290
+
291
+ AUTH_SANITIZER = auth_sanitizer_loader_namespace
292
+ .const_get(:AuthSanitizer)
293
+ .const_get(:Loader)
294
+ .load_isolated
295
+ ```
296
+
297
+ </details>
298
+
179
299
  ### Filtered Label
180
300
 
181
301
  The default replacement label is:
@@ -293,6 +413,19 @@ Require the gem:
293
413
  require "auth/sanitizer"
294
414
  ```
295
415
 
416
+ Or load it without defining top-level `Auth`. This still defines top-level `AuthSanitizer`; see
417
+ [Zero Top-Level Namespace Additions](#zero-top-level-namespace-additions) for the stricter loading pattern.
418
+
419
+ ```ruby
420
+ require "auth_sanitizer/loader"
421
+
422
+ AUTH_SANITIZER = AuthSanitizer::Loader.load_isolated
423
+
424
+ class TokenResponse
425
+ include AUTH_SANITIZER::FilteredAttributes
426
+ end
427
+ ```
428
+
296
429
  ### Redact `#inspect`
297
430
 
298
431
  Use `Auth::Sanitizer::FilteredAttributes` for objects that may appear in exception messages, console sessions, or debug
@@ -767,7 +900,7 @@ Thanks for RTFM. ☺️
767
900
  [📌gitmoji]: https://gitmoji.dev
768
901
  [📌gitmoji-img]: https://img.shields.io/badge/gitmoji_commits-%20%F0%9F%98%9C%20%F0%9F%98%8D-34495e.svg?style=flat-square
769
902
  [🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
770
- [🧮kloc-img]: https://img.shields.io/badge/KLOC-0.134-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
903
+ [🧮kloc-img]: https://img.shields.io/badge/KLOC-0.135-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
771
904
  [🔐security]: SECURITY.md
772
905
  [🔐security-img]: https://img.shields.io/badge/security-policy-259D6C.svg?style=flat
773
906
  [📄copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
data/REEK CHANGED
@@ -1,2 +1,2 @@
1
- Error: No such file - is
2
- Error: No such file - empty
1
+ ./reek: 1: Error:: not found
2
+ ./reek: 2: Error:: not found
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "version_gem"
4
+
5
+ Auth::Sanitizer::Version.class_eval do
6
+ extend VersionGem::Basic
7
+ end
8
+
9
+ module Auth
10
+ module Sanitizer
11
+ class Error < StandardError; end
12
+
13
+ # Default keys filtered from debug log output.
14
+ DEFAULT_FILTERED_KEYS = %w[
15
+ access_token
16
+ refresh_token
17
+ id_token
18
+ client_secret
19
+ assertion
20
+ code_verifier
21
+ token
22
+ ].freeze
23
+
24
+ # Default replacement label for redacted values.
25
+ DEFAULT_FILTERED_LABEL = "[FILTERED]"
26
+
27
+ # Default callable used to provide the filtered replacement label.
28
+ DEFAULT_FILTERED_LABEL_PROVIDER = -> { DEFAULT_FILTERED_LABEL }
29
+
30
+ filtered_label_provider = DEFAULT_FILTERED_LABEL_PROVIDER
31
+ filtered_label_provider_mutex = Mutex.new
32
+
33
+ # Returns the current filtered label by calling the installed provider.
34
+ #
35
+ # Host gems may install a provider that reads from their own config by
36
+ # calling {filtered_label_provider=}.
37
+ #
38
+ # @return [String]
39
+ define_singleton_method(:filtered_label) do
40
+ filtered_label_provider_mutex.synchronize { filtered_label_provider }.call
41
+ end
42
+
43
+ # Install a custom provider for the filtered label.
44
+ #
45
+ # The provider is called each time a new {FilteredAttributes}- or
46
+ # {SanitizedLogger}-bearing object is initialized, allowing the label to
47
+ # track a host gem's live configuration while still being snapshotted per
48
+ # object instance.
49
+ #
50
+ # @example Delegate to a host gem's config
51
+ # Auth::Sanitizer.filtered_label_provider = -> { MyGem.config[:filtered_label] }
52
+ #
53
+ # @param [#call] provider A callable that returns the label string
54
+ # @return [void]
55
+ define_singleton_method(:filtered_label_provider=) do |provider|
56
+ filtered_label_provider_mutex.synchronize do
57
+ filtered_label_provider = provider
58
+ end
59
+ end
60
+
61
+ class << self
62
+ # Returns the default set of key names filtered from debug log output.
63
+ #
64
+ # Host gems may override this by passing `filtered_keys:` directly to
65
+ # {SanitizedLogger#initialize}.
66
+ #
67
+ # @return [Array<String>]
68
+ def default_filtered_keys
69
+ DEFAULT_FILTERED_KEYS
70
+ end
71
+ end
72
+ end
73
+ end
@@ -3,7 +3,7 @@
3
3
  module Auth
4
4
  module Sanitizer
5
5
  module Version
6
- VERSION = "0.1.2"
6
+ VERSION = "0.1.3"
7
7
  end
8
8
  VERSION = Version::VERSION # Traditional Constant Location
9
9
  end
@@ -1,77 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "version_gem"
4
3
  require_relative "sanitizer/version"
5
4
  require_relative "sanitizer/thing_filter"
5
+ require_relative "sanitizer/core"
6
6
  require_relative "sanitizer/filtered_attributes"
7
7
  require_relative "sanitizer/sanitized_logger"
8
-
9
- Auth::Sanitizer::Version.class_eval do
10
- extend VersionGem::Basic
11
- end
12
-
13
- module Auth
14
- module Sanitizer
15
- class Error < StandardError; end
16
-
17
- # Default keys filtered from debug log output.
18
- DEFAULT_FILTERED_KEYS = %w[
19
- access_token
20
- refresh_token
21
- id_token
22
- client_secret
23
- assertion
24
- code_verifier
25
- token
26
- ].freeze
27
-
28
- # Default replacement label for redacted values.
29
- DEFAULT_FILTERED_LABEL = "[FILTERED]"
30
-
31
- # Default callable used to provide the filtered replacement label.
32
- DEFAULT_FILTERED_LABEL_PROVIDER = -> { DEFAULT_FILTERED_LABEL }
33
-
34
- filtered_label_provider = DEFAULT_FILTERED_LABEL_PROVIDER
35
- filtered_label_provider_mutex = Mutex.new
36
-
37
- # Returns the current filtered label by calling the installed provider.
38
- #
39
- # Host gems may install a provider that reads from their own config by
40
- # calling {filtered_label_provider=}.
41
- #
42
- # @return [String]
43
- define_singleton_method(:filtered_label) do
44
- filtered_label_provider_mutex.synchronize { filtered_label_provider }.call
45
- end
46
-
47
- # Install a custom provider for the filtered label.
48
- #
49
- # The provider is called each time a new {FilteredAttributes}- or
50
- # {SanitizedLogger}-bearing object is initialized, allowing the label to
51
- # track a host gem's live configuration while still being snapshotted per
52
- # object instance.
53
- #
54
- # @example Delegate to a host gem's config
55
- # Auth::Sanitizer.filtered_label_provider = -> { MyGem.config[:filtered_label] }
56
- #
57
- # @param [#call] provider A callable that returns the label string
58
- # @return [void]
59
- define_singleton_method(:filtered_label_provider=) do |provider|
60
- filtered_label_provider_mutex.synchronize do
61
- filtered_label_provider = provider
62
- end
63
- end
64
-
65
- class << self
66
- # Returns the default set of key names filtered from debug log output.
67
- #
68
- # Host gems may override this by passing `filtered_keys:` directly to
69
- # {SanitizedLogger#initialize}.
70
- #
71
- # @return [Array<String>]
72
- def default_filtered_keys
73
- DEFAULT_FILTERED_KEYS
74
- end
75
- end
76
- end
77
- end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AuthSanitizer
4
+ # Loader for consumers that need Auth::Sanitizer without defining a top-level
5
+ # Auth constant in the host application.
6
+ module Loader
7
+ FILES = %w[
8
+ auth/sanitizer/version.rb
9
+ auth/sanitizer/thing_filter.rb
10
+ auth/sanitizer/core.rb
11
+ auth/sanitizer/filtered_attributes.rb
12
+ auth/sanitizer/sanitized_logger.rb
13
+ ].freeze
14
+
15
+ class << self
16
+ # Load Auth::Sanitizer into an anonymous namespace and return the
17
+ # nested Auth::Sanitizer module from that namespace.
18
+ #
19
+ # This uses Module#module_eval with explicit file and line metadata so it
20
+ # works on Ruby 2.2+, where Kernel.load(path, module) is unavailable.
21
+ #
22
+ # @return [Module] isolated Auth::Sanitizer module
23
+ def load_isolated
24
+ namespace = Module.new
25
+ FILES.each do |relative_path|
26
+ path = File.expand_path("../#{relative_path}", __dir__)
27
+ namespace.module_eval(File.read(path), path, 1)
28
+ end
29
+ namespace.const_get(:Auth).const_get(:Sanitizer)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -4,3 +4,11 @@ module Auth
4
4
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
5
  end
6
6
  end
7
+
8
+ module AuthSanitizer
9
+ module Loader
10
+ FILES: Array[String]
11
+
12
+ def self.load_isolated: () -> Module
13
+ end
14
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth-sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter H. Boling
@@ -239,20 +239,22 @@ files:
239
239
  - RUBOCOP.md
240
240
  - SECURITY.md
241
241
  - lib/auth/sanitizer.rb
242
+ - lib/auth/sanitizer/core.rb
242
243
  - lib/auth/sanitizer/filtered_attributes.rb
243
244
  - lib/auth/sanitizer/sanitized_logger.rb
244
245
  - lib/auth/sanitizer/thing_filter.rb
245
246
  - lib/auth/sanitizer/version.rb
247
+ - lib/auth_sanitizer/loader.rb
246
248
  - sig/auth/sanitizer.rbs
247
249
  homepage: https://github.com/ruby-oauth/auth-sanitizer
248
250
  licenses:
249
251
  - MIT
250
252
  metadata:
251
253
  homepage_uri: https://auth-sanitizer.galtzo.com/
252
- source_code_uri: https://github.com/ruby-oauth/auth-sanitizer/tree/v0.1.2
253
- changelog_uri: https://github.com/ruby-oauth/auth-sanitizer/blob/v0.1.2/CHANGELOG.md
254
+ source_code_uri: https://github.com/ruby-oauth/auth-sanitizer/tree/v0.1.3
255
+ changelog_uri: https://github.com/ruby-oauth/auth-sanitizer/blob/v0.1.3/CHANGELOG.md
254
256
  bug_tracker_uri: https://github.com/ruby-oauth/auth-sanitizer/issues
255
- documentation_uri: https://www.rubydoc.info/gems/auth-sanitizer/0.1.2
257
+ documentation_uri: https://www.rubydoc.info/gems/auth-sanitizer/0.1.3
256
258
  funding_uri: https://github.com/sponsors/pboling
257
259
  wiki_uri: https://github.com/ruby-oauth/auth-sanitizer/wiki
258
260
  news_uri: https://www.railsbling.com/tags/auth-sanitizer
metadata.gz.sig CHANGED
Binary file