ask-auth 0.1.0 → 0.1.2

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: b1cfb133ab080dc2840a380b4039d783fa982a676c05b3b10cb597264d0da899
4
- data.tar.gz: 042e1afabf24c3543eef2cab5e54c8918e97c5bbccf489c8af4f1fd1211e3739
3
+ metadata.gz: d839820898bcd001809176b196900faf071717a66b53d70ac4a9605b31b3aa1f
4
+ data.tar.gz: dc3b21d1e383b5c7ee08d9b3798bb966d828b5f8e245c5cd5be036931092c823
5
5
  SHA512:
6
- metadata.gz: ee48024db5d7ffaf38afa8244017202c42b917aa8233bd600f0895bc100e32ac5d1089067666eb6ee8fb159d59c88e31236daf9fdca4ef085078a2ecb0f07e9e
7
- data.tar.gz: 9d6ba6e6f408b522f57da8793638812105dd3c0b691f24a98ff29ff316e31b82078d9ea84f77a1a71be48e8f360b1edb22f07b674138b29c1aa227e0b585c33d
6
+ metadata.gz: a092a91d436da5623755ca25116c28510921fad524fc7a562305fba76b94e2ec1d273d65264a847454e9e60813c742c930b2710545315c0b8e8790d303a10689
7
+ data.tar.gz: a0e8feee12cadfb082abac95349febe768b8f67e0697a9287dceee9b4a4feacf1d6fcbe141969196afd23055c47675e4cadacc17a285212700f1fb6c55a732f7
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ ## [0.1.1] - 2026-06-25
2
+
3
+ ### Changed
4
+ - Infrastructure: rubocop, overcommit, bin/setup, CI matrix, gemspec test, SimpleCov, .minitest config.
5
+ # Changelog
6
+
7
+ ## [0.1.0] — 2026-06-09
8
+
9
+ Initial release of `ask-auth`, the credential resolution gem for the ask-rb ecosystem.
10
+
11
+ ### Added
12
+
13
+ - **Configuration system** — `Ask::Auth.configure` with block-based config and frozen post-boot safety
14
+ - **Resolution chain** — `Ask::Auth.resolve(name, user: nil)` walks providers in order, returns first non-nil
15
+ - **Blank normalization** — empty string and whitespace-only values normalize to `nil`
16
+ - **Error classes** — `MissingCredential` and `InvalidCredential` with actionable messages
17
+ - **Env provider** — resolves from `ENV` by convention (`GITHUB_TOKEN`, `GITHUBTOKEN`, `github_token`)
18
+ - **File provider** — reads `~/.ask/credentials.yml` with configurable path and Symbol-safe YAML loading
19
+ - **RailsCredentials provider** — wraps `Rails.application.credentials` with safe nil when Rails not loaded
20
+ - **Database provider** — ActiveRecord-backed per-user token storage with automatic expiry + refresh
21
+ - **OAuth provider** — PKCE interface with `authorize_url` and `authorize!` methods (full flow deferred)
22
+ - **Test suite** — 45 tests, 99%+ coverage across all providers and the resolution chain
23
+ - **Thread safety** — configuration is frozen after `configure` completes
@@ -5,16 +5,48 @@ module Ask
5
5
  module Providers
6
6
  # Resolves credentials from Rails encrypted credentials.
7
7
  #
8
- # Convention: +resolve(:github_token)+ looks up +Rails.application.credentials.github.token+
9
- # (dot-separated path from the credential name).
8
+ # Convention: +resolve(:github_token)+ looks up multiple paths in order:
9
+ #
10
+ # 1. Full name as a single top-level key (flat layout):
11
+ # +Rails.application.credentials.github_token+
12
+ #
13
+ # 2. First segment as namespace, joined rest as sub-key (nested layout):
14
+ # +Rails.application.credentials.github.token+
15
+ #
16
+ # 3. Fully split path (deeply nested layout):
17
+ # +Rails.application.credentials.github.api.key+
18
+ #
19
+ # Strategy 2 handles compound key names like +api_key+ correctly.
20
+ # For +resolve(:opencode_api_key)+, it looks up:
21
+ # +Rails.application.credentials.opencode.api_key+
22
+ # instead of breaking +api_key+ into +api+ and +key+.
10
23
  #
11
24
  # Safely returns nil when Rails is not loaded.
12
25
  class RailsCredentials
13
26
  def call(name, user: nil)
14
27
  return nil unless defined?(::Rails) && ::Rails.application.respond_to?(:credentials)
15
28
 
16
- parts = name.to_s.split("_")
17
- value = parts.reduce(::Rails.application.credentials) do |obj, part|
29
+ creds = ::Rails.application.credentials
30
+ s = name.to_s
31
+ parts = s.split("_")
32
+
33
+ # 1. Full name as a single top-level key
34
+ return creds.public_send(s) if creds.respond_to?(s)
35
+
36
+ # 2. First segment as namespace, joined rest as sub-key
37
+ # e.g., opencode_api_key → credentials.opencode.api_key
38
+ if parts.length >= 2
39
+ first = parts.first
40
+ rest = parts.drop(1).join("_")
41
+ if creds.respond_to?(first)
42
+ obj = creds.public_send(first)
43
+ return obj.public_send(rest) if obj.respond_to?(rest)
44
+ end
45
+ end
46
+
47
+ # 3. Fully split path (original behavior)
48
+ # e.g., opencode.go.api_key → credentials.opencode.go.api_key
49
+ value = parts.reduce(creds) do |obj, part|
18
50
  break nil unless obj.respond_to?(part)
19
51
  obj.public_send(part)
20
52
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ask
4
4
  module Auth
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - CHANGELOG.md
76
77
  - LICENSE
77
78
  - README.md
78
79
  - lib/ask-auth.rb
@@ -86,7 +87,10 @@ files:
86
87
  homepage: https://github.com/ask-rb/ask-auth
87
88
  licenses:
88
89
  - MIT
89
- metadata: {}
90
+ metadata:
91
+ homepage_uri: https://github.com/ask-rb/ask-auth
92
+ source_code_uri: https://github.com/ask-rb/ask-auth
93
+ changelog_uri: https://github.com/ask-rb/ask-auth/blob/master/CHANGELOG.md
90
94
  rdoc_options: []
91
95
  require_paths:
92
96
  - lib