Class: Conversant::Configuration
- Inherits:
-
Object
- Object
- Conversant::Configuration
- Defined in:
- lib/conversant/configuration.rb
Instance Attribute Summary collapse
-
#cache_ttl ⇒ Object
Returns the value of attribute cache_ttl.
-
#conversant_cdn_api_url ⇒ Object
Returns the value of attribute conversant_cdn_api_url.
-
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
-
#default_content_type ⇒ Object
Returns the value of attribute default_content_type.
-
#default_ua ⇒ Object
Returns the value of attribute default_ua.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#portal_root_hostname ⇒ Object
Returns the value of attribute portal_root_hostname.
-
#portal_sso_hostname ⇒ Object
Returns the value of attribute portal_sso_hostname.
-
#private_cdn_endpoint ⇒ Object
Returns the value of attribute private_cdn_endpoint.
-
#private_lms_endpoint ⇒ Object
Returns the value of attribute private_lms_endpoint.
-
#private_oss_endpoint ⇒ Object
Returns the value of attribute private_oss_endpoint.
-
#private_portal_endpoint ⇒ Object
Returns the value of attribute private_portal_endpoint.
-
#private_sso_endpoint ⇒ Object
Returns the value of attribute private_sso_endpoint.
-
#private_vms_endpoint ⇒ Object
Returns the value of attribute private_vms_endpoint.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#swiftserve_identifier_hash ⇒ Object
Returns the value of attribute swiftserve_identifier_hash.
-
#swiftserve_identifier_id ⇒ Object
Returns the value of attribute swiftserve_identifier_id.
-
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
Class Method Summary collapse
-
.from_env ⇒ Object
Load configuration from environment and validate.
Instance Method Summary collapse
-
#auto_configured? ⇒ Boolean
Check if configuration is loaded from environment.
-
#env_var_name(field) ⇒ Object
Helper to map config field to ENV variable name.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #portal_endpoint ⇒ Object
- #sso_endpoint ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/conversant/configuration.rb', line 24 def initialize # All configuration automatically uses ENV variables as defaults # Users only need to override if they want different values # Portal configuration - defaults from ENV @portal_root_hostname = ENV['PORTAL_ROOT_HOSTNAME'] || 'console.swiftfederation.com' @portal_sso_hostname = ENV['PORTAL_SSO_HOSTNAME'] || 'sso.swiftfederation.com' # API Endpoints - defaults from ENV (matching existing CONVERSANT setup) @private_cdn_endpoint = ENV['PRIVATE_CDN_ENDPOINT'] @private_lms_endpoint = ENV['PRIVATE_LMS_ENDPOINT'] @private_vms_endpoint = ENV['PRIVATE_VMS_ENDPOINT'] @private_oss_endpoint = ENV['PRIVATE_OSS_ENDPOINT'] @private_portal_endpoint = ENV['PRIVATE_PORTAL_ENDPOINT'] || "https://#{@portal_root_hostname}" @private_sso_endpoint = ENV['PRIVATE_SSO_ENDPOINT'] || "https://#{@portal_sso_hostname}" # Authentication - defaults from ENV @swiftserve_identifier_id = ENV['SWIFTSERVE_IDENTIFIER_ID'] @swiftserve_identifier_hash = ENV['SWIFTSERVE_IDENTIFIER_HASH'] # HTTP settings - defaults from ENV @default_ua = ENV['DEFAULT_UA'] || 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36' @default_content_type = ENV['DEFAULT_CONTENT_TYPE'] || 'application/json' # Additional CDN API URL if needed @conversant_cdn_api_url = ENV['CONVERSANT_CDN_API_URL'] # Runtime settings @logger = Logger.new($stdout) @debug_mode = ENV['CONVERSANT_DEBUG'] == 'true' || ENV['DEBUG'] == 'true' @verify_ssl = ENV['RAILS_ENV'] == 'production' @cache_ttl = (ENV['CONVERSANT_CACHE_TTL'] || 1200).to_i # Redis - auto-detect from global $redis or ENV @redis = if defined?($redis) && $redis $redis elsif defined?(::Redis) && ENV['REDIS_URL'] ::Redis.new(url: ENV['REDIS_URL']) elsif defined?(::Redis) ::Redis.new else nil end end |
Instance Attribute Details
#cache_ttl ⇒ Object
Returns the value of attribute cache_ttl.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def cache_ttl @cache_ttl end |
#conversant_cdn_api_url ⇒ Object
Returns the value of attribute conversant_cdn_api_url.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def conversant_cdn_api_url @conversant_cdn_api_url end |
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def debug_mode @debug_mode end |
#default_content_type ⇒ Object
Returns the value of attribute default_content_type.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def default_content_type @default_content_type end |
#default_ua ⇒ Object
Returns the value of attribute default_ua.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def default_ua @default_ua end |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def logger @logger end |
#portal_root_hostname ⇒ Object
Returns the value of attribute portal_root_hostname.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def portal_root_hostname @portal_root_hostname end |
#portal_sso_hostname ⇒ Object
Returns the value of attribute portal_sso_hostname.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def portal_sso_hostname @portal_sso_hostname end |
#private_cdn_endpoint ⇒ Object
Returns the value of attribute private_cdn_endpoint.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def private_cdn_endpoint @private_cdn_endpoint end |
#private_lms_endpoint ⇒ Object
Returns the value of attribute private_lms_endpoint.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def private_lms_endpoint @private_lms_endpoint end |
#private_oss_endpoint ⇒ Object
Returns the value of attribute private_oss_endpoint.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def private_oss_endpoint @private_oss_endpoint end |
#private_portal_endpoint ⇒ Object
Returns the value of attribute private_portal_endpoint.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def private_portal_endpoint @private_portal_endpoint end |
#private_sso_endpoint ⇒ Object
Returns the value of attribute private_sso_endpoint.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def private_sso_endpoint @private_sso_endpoint end |
#private_vms_endpoint ⇒ Object
Returns the value of attribute private_vms_endpoint.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def private_vms_endpoint @private_vms_endpoint end |
#redis ⇒ Object
Returns the value of attribute redis.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def redis @redis end |
#swiftserve_identifier_hash ⇒ Object
Returns the value of attribute swiftserve_identifier_hash.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def swiftserve_identifier_hash @swiftserve_identifier_hash end |
#swiftserve_identifier_id ⇒ Object
Returns the value of attribute swiftserve_identifier_id.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def swiftserve_identifier_id @swiftserve_identifier_id end |
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
5 6 7 |
# File 'lib/conversant/configuration.rb', line 5 def verify_ssl @verify_ssl end |
Class Method Details
.from_env ⇒ Object
Load configuration from environment and validate
126 127 128 129 130 |
# File 'lib/conversant/configuration.rb', line 126 def self.from_env config = new config.validate! config end |
Instance Method Details
#auto_configured? ⇒ Boolean
Check if configuration is loaded from environment
107 108 109 |
# File 'lib/conversant/configuration.rb', line 107 def auto_configured? !@swiftserve_identifier_id.nil? && !@swiftserve_identifier_hash.nil? end |
#env_var_name(field) ⇒ Object
Helper to map config field to ENV variable name
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/conversant/configuration.rb', line 112 def env_var_name(field) case field when :swiftserve_identifier_id then 'SWIFTSERVE_IDENTIFIER_ID' when :swiftserve_identifier_hash then 'SWIFTSERVE_IDENTIFIER_HASH' when :private_cdn_endpoint then 'PRIVATE_CDN_ENDPOINT' when :private_lms_endpoint then 'PRIVATE_LMS_ENDPOINT' when :private_vms_endpoint then 'PRIVATE_VMS_ENDPOINT' when :portal_root_hostname then 'PORTAL_ROOT_HOSTNAME' when :portal_sso_hostname then 'PORTAL_SSO_HOSTNAME' else field.to_s.upcase end end |
#portal_endpoint ⇒ Object
69 70 71 |
# File 'lib/conversant/configuration.rb', line 69 def portal_endpoint @private_portal_endpoint || "https://#{portal_root_hostname}" end |
#sso_endpoint ⇒ Object
73 74 75 |
# File 'lib/conversant/configuration.rb', line 73 def sso_endpoint @private_sso_endpoint || "https://#{portal_sso_hostname}" end |
#validate! ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/conversant/configuration.rb', line 77 def validate! required_fields = [] # Only require credentials if not auto-configured unless auto_configured? required_fields += [ :swiftserve_identifier_id, :swiftserve_identifier_hash ] end # Always require endpoints required_fields += [ :private_cdn_endpoint, :private_lms_endpoint, :private_vms_endpoint, :redis ] missing_fields = required_fields.select { |field| send(field).nil? || send(field).to_s.empty? } if missing_fields.any? raise Error, "Missing required configuration: #{missing_fields.join(', ')}\n" \ "Please set the following environment variables: #{missing_fields.map { |f| env_var_name(f) }.join(', ')}" end true end |