ask-auth 0.1.1 → 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: 4f788282e5d4084f09abe670765dbe0fab939ae87e1e7d2ec60b905c13a97085
4
- data.tar.gz: 500ce5057d6a97cb72e559c69bbddda3ba5cebf21d771fcb8f6837ba63d5a510
3
+ metadata.gz: f8535335b52d412f3c6cd8cb70de3547d5872c21e0aac5465c1bac88a5446847
4
+ data.tar.gz: 1072dfab33c51e9ab57b6ccd928f97f9f55a947dd27d542696dece9330fa0326
5
5
  SHA512:
6
- metadata.gz: 448a0bb43bbbd3935a3b0f728e1e251721256e75b995d6b5f673627c7661dbacb43e594c898e1563773c63f90f8a12ec3d93fdb6577e78d6a0441fa0fa1b8f98
7
- data.tar.gz: 402ea9c20b006bbdb8166899f7f908cd3e77b729f715b5f0ceb62673a4a78a42f752162bb35e84ba796bc66185a5af227f5a8cb4e2de2c03460ab1db95426594
6
+ metadata.gz: 349a4863d2061377b373402ea937e9fbaf15a8928662ec3af72e7754fc3e87542bf2e62e9355fbe90140e1a61c4d5e77985b1c87a706eddda8cf8abcd4599fe2
7
+ data.tar.gz: b01eabafd424f1bf3348b55f05678b6ff6aeb20b805e870cf975631d400915e992d05f64799c74e9cc53a0a37e16db332b1a9bac096be25fd413df0acd8bb100
@@ -5,16 +5,52 @@ 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 (e.g., credentials.opencode_api_key)
34
+ # Must check the returned value, not just respond_to?, because
35
+ # ActiveSupport::OrderedOptions#respond_to? returns true for any
36
+ # method name even when the key doesn't exist in the hash.
37
+ val = creds.public_send(s) rescue nil
38
+ return val if val
39
+
40
+ # 2. First segment as namespace, joined rest as sub-key
41
+ # e.g., opencode_api_key → credentials.opencode.api_key
42
+ if parts.length >= 2
43
+ first = parts.first
44
+ rest = parts.drop(1).join("_")
45
+ if creds.respond_to?(first)
46
+ obj = creds.public_send(first)
47
+ return obj.public_send(rest) if obj.respond_to?(rest)
48
+ end
49
+ end
50
+
51
+ # 3. Fully split path (original behavior)
52
+ # e.g., opencode.go.api_key → credentials.opencode.go.api_key
53
+ value = parts.reduce(creds) do |obj, part|
18
54
  break nil unless obj.respond_to?(part)
19
55
  obj.public_send(part)
20
56
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ask
4
4
  module Auth
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.3"
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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto