Class: RosettAi::Mcp::HttpSecurityConfig::AuthConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/mcp/http_security_config.rb

Overview

Authentication sub-configuration.

Constant Summary collapse

DEFAULT_KEYFILE_NAME =
'rosett-ai-mcp-keys.yml'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAuthConfig

Returns a new instance of AuthConfig.



51
52
53
54
55
56
# File 'lib/rosett_ai/mcp/http_security_config.rb', line 51

def initialize
  @type = 'api_key'
  @key_source = 'auto'
  @keyfile_path = DEFAULT_KEYFILE_NAME
  @api_key_env = 'RAI_MCP_API_KEY'
end

Instance Attribute Details

#api_key_envObject

Returns the value of attribute api_key_env.



47
48
49
# File 'lib/rosett_ai/mcp/http_security_config.rb', line 47

def api_key_env
  @api_key_env
end

#key_sourceObject

Returns the value of attribute key_source.



47
48
49
# File 'lib/rosett_ai/mcp/http_security_config.rb', line 47

def key_source
  @key_source
end

#keyfile_pathObject

Returns the value of attribute keyfile_path.



47
48
49
# File 'lib/rosett_ai/mcp/http_security_config.rb', line 47

def keyfile_path
  @keyfile_path
end

#typeObject

Returns the value of attribute type.



47
48
49
# File 'lib/rosett_ai/mcp/http_security_config.rb', line 47

def type
  @type
end

Instance Method Details

#apply(hash) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/rosett_ai/mcp/http_security_config.rb', line 67

def apply(hash)
  return unless hash.is_a?(Hash)

  @type = hash['type'] if hash['type']
  @key_source = hash['key_source'] if hash['key_source']
  @keyfile_path = hash['keyfile_path'] if hash['keyfile_path']
  @api_key_env = hash['api_key_env'] if hash['api_key_env']
end

#resolved_key_sourceString

Resolve the effective key source.

Returns:

  • (String)

    'keyfile' or 'env'



61
62
63
64
65
# File 'lib/rosett_ai/mcp/http_security_config.rb', line 61

def resolved_key_source
  return @key_source unless @key_source == 'auto'

  File.exist?(File.expand_path(@keyfile_path)) ? 'keyfile' : 'env'
end