Class: RosettAi::Mcp::Settings::TrustManager
- Inherits:
-
Object
- Object
- RosettAi::Mcp::Settings::TrustManager
- Defined in:
- lib/rosett_ai/mcp/settings/trust_manager.rb
Overview
Manages trust sources for MCP server installation.
Trust sources define which domains are approved for MCP server installation. Prevents untrusted servers from being silently added to configuration.
Constant Summary collapse
- CONFIG_DIR =
Returns Configuration directory path.
'.config/rosett-ai/mcp'- USER_TRUST_FILE =
Returns Filename for user trust configuration.
'user_trust.yml'
Instance Method Summary collapse
-
#add_trust(domain, description: 'User-trusted domain') ⇒ void
Adds a user-trusted domain.
-
#initialize(config_dir: nil, defaults_path: nil) ⇒ TrustManager
constructor
A new instance of TrustManager.
-
#list ⇒ Array<Hash>
Lists all trusted sources (default + user-added).
-
#remove_trust(domain) ⇒ Boolean
Removes a user-trusted domain.
-
#trusted?(domain) ⇒ Boolean
Checks whether a domain is trusted.
-
#validate_uri(uri) ⇒ Hash
Validates whether a URI originates from a trusted source.
Constructor Details
#initialize(config_dir: nil, defaults_path: nil) ⇒ TrustManager
Returns a new instance of TrustManager.
26 27 28 29 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 26 def initialize(config_dir: nil, defaults_path: nil) @config_dir = config_dir || Pathname.new(Dir.home).join(CONFIG_DIR) @defaults_path = defaults_path || RosettAi.root.join('conf', 'mcp', 'trust.yml') end |
Instance Method Details
#add_trust(domain, description: 'User-trusted domain') ⇒ void
This method returns an undefined value.
Adds a user-trusted domain.
67 68 69 70 71 72 73 74 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 67 def add_trust(domain, description: 'User-trusted domain') sources = user_sources normalized = normalize_domain(domain) return if sources.any? { |s| normalize_domain(s[:domain]) == normalized } sources << { domain: normalized, type: 'user', description: description } write_user_sources(sources) end |
#list ⇒ Array<Hash>
Lists all trusted sources (default + user-added).
34 35 36 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 34 def list default_sources + user_sources end |
#remove_trust(domain) ⇒ Boolean
Removes a user-trusted domain.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 80 def remove_trust(domain) # rubocop:disable Naming/PredicateMethod -- destructive action, not a predicate sources = user_sources normalized = normalize_domain(domain) original_size = sources.size sources.reject! { |s| normalize_domain(s[:domain]) == normalized } return false if sources.size == original_size write_user_sources(sources) true end |
#trusted?(domain) ⇒ Boolean
Checks whether a domain is trusted.
42 43 44 45 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 42 def trusted?(domain) normalized = normalize_domain(domain) list.any? { |source| normalize_domain(source[:domain]) == normalized } end |
#validate_uri(uri) ⇒ Hash
Validates whether a URI originates from a trusted source.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rosett_ai/mcp/settings/trust_manager.rb', line 51 def validate_uri(uri) domain = extract_domain(uri) source = find_source(domain) if source { trusted: true, domain: domain, source_type: source[:type] } else { trusted: false, domain: domain, source_type: nil } end end |