Class: SolidAgent::AgentManifest::Registry::Auth
- Inherits:
-
Object
- Object
- SolidAgent::AgentManifest::Registry::Auth
- Defined in:
- lib/solid_agent/agent_manifest/registry/auth.rb
Overview
Auth handles token management for the ActiveAgents registry.
Tokens are stored in ~/.activeagent/token by default. Can also be configured via environment variable.
Constant Summary collapse
- TOKEN_PATH =
File.("~/.activeagent/token")
- TOKEN_ENV_VAR =
"ACTIVEAGENT_TOKEN"
Class Method Summary collapse
-
.auth_header ⇒ Hash
Get authorization header for API requests.
-
.clear_token ⇒ Boolean
Clear the saved token.
-
.logged_in? ⇒ Boolean
Check if user is logged in.
-
.require_token! ⇒ String
Require authentication, raising if not logged in.
-
.save_token(new_token) ⇒ Boolean
Save a token to the token file.
-
.token ⇒ String?
Get the current authentication token.
Class Method Details
.auth_header ⇒ Hash
Get authorization header for API requests
93 94 95 96 97 98 |
# File 'lib/solid_agent/agent_manifest/registry/auth.rb', line 93 def auth_header t = token return {} unless t { "Authorization" => "Bearer #{t}" } end |
.clear_token ⇒ Boolean
Clear the saved token
63 64 65 66 67 68 69 70 |
# File 'lib/solid_agent/agent_manifest/registry/auth.rb', line 63 def clear_token return true unless File.exist?(TOKEN_PATH) File.delete(TOKEN_PATH) true rescue StandardError => e raise RegistryError, "Failed to clear token: #{e.}" end |
.logged_in? ⇒ Boolean
Check if user is logged in
75 76 77 |
# File 'lib/solid_agent/agent_manifest/registry/auth.rb', line 75 def logged_in? token.present? end |
.require_token! ⇒ String
Require authentication, raising if not logged in
83 84 85 86 87 88 |
# File 'lib/solid_agent/agent_manifest/registry/auth.rb', line 83 def require_token! t = token raise RegistryError, "Not authenticated. Run 'activeagent login' or set #{TOKEN_ENV_VAR}" unless t t end |
.save_token(new_token) ⇒ Boolean
Save a token to the token file
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/solid_agent/agent_manifest/registry/auth.rb', line 47 def save_token(new_token) # Ensure directory exists FileUtils.mkdir_p(File.dirname(TOKEN_PATH)) # Write token with secure permissions File.write(TOKEN_PATH, new_token.strip) File.chmod(0o600, TOKEN_PATH) true rescue StandardError => e raise RegistryError, "Failed to save token: #{e.}" end |
.token ⇒ String?
Get the current authentication token
Checks in order:
- Environment variable (ACTIVEAGENT_TOKEN)
- Token file (~/.activeagent/token)
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/solid_agent/agent_manifest/registry/auth.rb', line 32 def token # Check environment variable first env_token = ENV[TOKEN_ENV_VAR] return env_token if env_token.present? # Check token file return nil unless File.exist?(TOKEN_PATH) File.read(TOKEN_PATH).strip.presence end |