Class: RubyCoded::Auth::AuthManager
- Inherits:
-
Object
- Object
- RubyCoded::Auth::AuthManager
- Defined in:
- lib/ruby_coded/auth/auth_manager.rb
Overview
This class is used to manage the authentication process for the different AI providers
Constant Summary collapse
Instance Method Summary collapse
- #authenticated_provider_names ⇒ Object
- #check_authentication ⇒ Object
- #configure_ruby_llm! ⇒ Object
- #configured_providers ⇒ Object
-
#initialize(config_path: UserConfig::CONFIG_PATH) ⇒ AuthManager
constructor
A new instance of AuthManager.
- #login(provider_name) ⇒ Object
- #login_prompt ⇒ Object
- #logout(provider_name) ⇒ Object
Constructor Details
#initialize(config_path: UserConfig::CONFIG_PATH) ⇒ AuthManager
Returns a new instance of AuthManager.
24 25 26 |
# File 'lib/ruby_coded/auth/auth_manager.rb', line 24 def initialize(config_path: UserConfig::CONFIG_PATH) @config_path = config_path end |
Instance Method Details
#authenticated_provider_names ⇒ Object
47 48 49 |
# File 'lib/ruby_coded/auth/auth_manager.rb', line 47 def authenticated_provider_names PROVIDERS.keys.select { |name| credential_store.retrieve(name) } end |
#check_authentication ⇒ Object
51 52 53 54 55 56 |
# File 'lib/ruby_coded/auth/auth_manager.rb', line 51 def check_authentication return if configured_providers.any? { |name| credential_store.retrieve(name) } provider_name = choose_provider login(provider_name) end |
#configure_ruby_llm! ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ruby_coded/auth/auth_manager.rb', line 63 def configure_ruby_llm! RubyLLM.configure do |config| config.max_retries = 1 PROVIDERS.each do |name, provider| credentials = credential_store.retrieve(name) next unless credentials credentials = refresh_if_expired(name, provider, credentials) key = extract_api_key(credentials) config.send("#{provider.ruby_llm_key}=", key) end end end |
#configured_providers ⇒ Object
43 44 45 |
# File 'lib/ruby_coded/auth/auth_manager.rb', line 43 def configured_providers PROVIDERS.keys end |
#login(provider_name) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby_coded/auth/auth_manager.rb', line 28 def login(provider_name) provider = PROVIDERS.fetch(provider_name) strategy = strategy_for(provider) credentials = strategy.authenticate credential_store.store(provider_name, credentials) configure_ruby_llm! print_api_credits_notice(provider) credentials end |
#login_prompt ⇒ Object
58 59 60 61 |
# File 'lib/ruby_coded/auth/auth_manager.rb', line 58 def login_prompt provider_name = choose_provider login(provider_name) end |
#logout(provider_name) ⇒ Object
38 39 40 41 |
# File 'lib/ruby_coded/auth/auth_manager.rb', line 38 def logout(provider_name) credential_store.remove(provider_name) configure_ruby_llm! end |