Module: ZeroMcp::Credentials
- Defined in:
- lib/zeromcp/credentials.rb
Class Method Summary collapse
- .resolve(tool_name, config, cache: nil) ⇒ Object
- .resolve_for_ns(ns, source, config, cache) ⇒ Object
- .resolve_source(source) ⇒ Object
Class Method Details
.resolve(tool_name, config, cache: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/zeromcp/credentials.rb', line 9 def resolve(tool_name, config, cache: nil) return nil if config.credentials.empty? config.credentials.each do |ns, source| if tool_name.start_with?("#{ns}_") || tool_name.start_with?("#{ns}#{config.separator}") return resolve_for_ns(ns.to_s, source, config, cache) end end nil end |
.resolve_for_ns(ns, source, config, cache) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/zeromcp/credentials.rb', line 19 def resolve_for_ns(ns, source, config, cache) return resolve_source(source) unless config.cache_credentials return cache[ns] if cache && cache.key?(ns) creds = resolve_source(source) cache[ns] = creds if cache creds end |
.resolve_source(source) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/zeromcp/credentials.rb', line 27 def resolve_source(source) source = source.transform_keys(&:to_s) if source.is_a?(Hash) if source['env'] val = ENV[source['env']] return nil if val.nil? || val.empty? begin; return JSON.parse(val); rescue; return val; end end if source['file'] path = File.(source['file']) return nil unless File.exist?(path) val = File.read(path).strip begin; return JSON.parse(val); rescue; return val; end end nil end |