Class: Langfuse::CLI::Config
- Inherits:
-
Object
- Object
- Langfuse::CLI::Config
- Defined in:
- lib/langfuse/cli/config.rb
Constant Summary collapse
- DEFAULT_HOST =
'https://cloud.langfuse.com'- DEFAULT_OUTPUT_FORMAT =
'table'- DEFAULT_PAGE_LIMIT =
50- CONFIG_DIR =
File.('~/.langfuse')
- CONFIG_FILE =
File.join(CONFIG_DIR, 'config.yml')
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#output_format ⇒ Object
Returns the value of attribute output_format.
-
#page_limit ⇒ Object
Returns the value of attribute page_limit.
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Class Method Summary collapse
-
.load(profile = nil) ⇒ Object
Load a specific profile.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
-
#load_config ⇒ Object
Load configuration from file and environment variables Priority: passed options > ENV vars > config file > defaults.
-
#load_from_env ⇒ Object
Load configuration from environment variables.
-
#load_from_file ⇒ Object
Load configuration from YAML file.
-
#merge_options(options) ⇒ Object
Merge passed options (highest priority).
-
#missing_fields ⇒ Object
Get list of missing required fields.
-
#save(profile_name = nil) ⇒ Object
Save current configuration to file.
-
#to_h ⇒ Object
Get configuration as a hash.
-
#valid? ⇒ Boolean
Validate that required configuration is present.
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 |
# File 'lib/langfuse/cli/config.rb', line 15 def initialize( = {}) @profile = [:profile] || ENV['LANGFUSE_PROFILE'] || 'default' load_config () end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/langfuse/cli/config.rb', line 7 def host @host end |
#output_format ⇒ Object
Returns the value of attribute output_format.
7 8 9 |
# File 'lib/langfuse/cli/config.rb', line 7 def output_format @output_format end |
#page_limit ⇒ Object
Returns the value of attribute page_limit.
7 8 9 |
# File 'lib/langfuse/cli/config.rb', line 7 def page_limit @page_limit end |
#profile ⇒ Object
Returns the value of attribute profile.
7 8 9 |
# File 'lib/langfuse/cli/config.rb', line 7 def profile @profile end |
#public_key ⇒ Object
Returns the value of attribute public_key.
7 8 9 |
# File 'lib/langfuse/cli/config.rb', line 7 def public_key @public_key end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
7 8 9 |
# File 'lib/langfuse/cli/config.rb', line 7 def secret_key @secret_key end |
Class Method Details
.load(profile = nil) ⇒ Object
Load a specific profile
119 120 121 |
# File 'lib/langfuse/cli/config.rb', line 119 def self.load(profile = nil) new(profile: profile) end |
Instance Method Details
#load_config ⇒ Object
Load configuration from file and environment variables Priority: passed options > ENV vars > config file > defaults
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/langfuse/cli/config.rb', line 23 def load_config # Start with defaults @host = DEFAULT_HOST @output_format = DEFAULT_OUTPUT_FORMAT @page_limit = DEFAULT_PAGE_LIMIT @public_key = nil @secret_key = nil # Load from config file if it exists if File.exist?(CONFIG_FILE) load_from_file end # Override with environment variables load_from_env end |
#load_from_env ⇒ Object
Load configuration from environment variables
57 58 59 60 61 |
# File 'lib/langfuse/cli/config.rb', line 57 def load_from_env @public_key = ENV['LANGFUSE_PUBLIC_KEY'] if ENV['LANGFUSE_PUBLIC_KEY'] @secret_key = ENV['LANGFUSE_SECRET_KEY'] if ENV['LANGFUSE_SECRET_KEY'] @host = ENV['LANGFUSE_HOST'] if ENV['LANGFUSE_HOST'] end |
#load_from_file ⇒ Object
Load configuration from YAML file
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/langfuse/cli/config.rb', line 41 def load_from_file config_data = YAML.load_file(CONFIG_FILE) # Load profile-specific config profile_config = config_data.dig('profiles', @profile) || config_data['default'] || {} @public_key = profile_config['public_key'] if profile_config['public_key'] @secret_key = profile_config['secret_key'] if profile_config['secret_key'] @host = profile_config['host'] if profile_config['host'] @output_format = profile_config['output_format'] if profile_config['output_format'] @page_limit = profile_config['page_limit'] if profile_config['page_limit'] rescue => e warn "Warning: Error loading config file: #{e.}" end |
#merge_options(options) ⇒ Object
Merge passed options (highest priority)
64 65 66 67 68 69 70 |
# File 'lib/langfuse/cli/config.rb', line 64 def () @public_key = [:public_key] if [:public_key] @secret_key = [:secret_key] if [:secret_key] @host = [:host] if [:host] @output_format = [:format] if [:format] @page_limit = [:limit] if [:limit] end |
#missing_fields ⇒ Object
Get list of missing required fields
78 79 80 81 82 83 84 |
# File 'lib/langfuse/cli/config.rb', line 78 def missing_fields fields = [] fields << 'public_key' if @public_key.nil? fields << 'secret_key' if @secret_key.nil? fields << 'host' if @host.nil? fields end |
#save(profile_name = nil) ⇒ Object
Save current configuration to file
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/langfuse/cli/config.rb', line 87 def save(profile_name = nil) profile_name ||= @profile # Ensure config directory exists FileUtils.mkdir_p(CONFIG_DIR) # Load existing config or create new config_data = File.exist?(CONFIG_FILE) ? YAML.load_file(CONFIG_FILE) : {} config_data['profiles'] ||= {} # Update profile config_data['profiles'][profile_name] = { 'public_key' => @public_key, 'secret_key' => @secret_key, 'host' => @host, 'output_format' => @output_format, 'page_limit' => @page_limit } # Write to file File.write(CONFIG_FILE, config_data.to_yaml) # Set restrictive permissions File.chmod(0600, CONFIG_FILE) true rescue => e warn "Error saving config: #{e.}" false end |
#to_h ⇒ Object
Get configuration as a hash
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/langfuse/cli/config.rb', line 124 def to_h { public_key: @public_key, secret_key: @secret_key, host: @host, profile: @profile, output_format: @output_format, page_limit: @page_limit } end |
#valid? ⇒ Boolean
Validate that required configuration is present
73 74 75 |
# File 'lib/langfuse/cli/config.rb', line 73 def valid? !@public_key.nil? && !@secret_key.nil? && !@host.nil? end |