Class: HatiConfig::RemoteLoader
- Inherits:
-
Object
- Object
- HatiConfig::RemoteLoader
- Defined in:
- lib/hati_config/remote_loader.rb
Overview
RemoteLoader handles loading configurations from remote sources like HTTP, S3, and Redis. It supports automatic refresh and caching of configurations.
Class Method Summary collapse
-
.from_http(url:, headers: {}) ⇒ Hash
Loads configuration from an HTTP endpoint.
-
.from_redis(host:, key:, port: 6379, db: 0) ⇒ Hash
Loads configuration from Redis.
-
.from_s3(bucket:, key:, region:) ⇒ Hash
Loads configuration from an S3 bucket.
Class Method Details
.from_http(url:, headers: {}) ⇒ Hash
Loads configuration from an HTTP endpoint
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hati_config/remote_loader.rb', line 21 def from_http(url:, headers: {}) uri = URI(url) request = Net::HTTP::Get.new(uri) headers.each { |key, value| request[key] = value } response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end parse_response(response.body, File.extname(uri.path)) rescue StandardError => e raise LoadDataError, "Failed to load configuration from HTTP: #{e.}" end |
.from_redis(host:, key:, port: 6379, db: 0) ⇒ Hash
Loads configuration from Redis
60 61 62 63 64 65 66 67 68 |
# File 'lib/hati_config/remote_loader.rb', line 60 def from_redis(host:, key:, port: 6379, db: 0) redis = Redis.new(host: host, port: port, db: db) data = redis.get(key) raise LoadDataError, "Key '#{key}' not found in Redis" unless data parse_response(data) rescue Redis::BaseError => e raise LoadDataError, "Failed to load configuration from Redis: #{e.}" end |
.from_s3(bucket:, key:, region:) ⇒ Hash
Loads configuration from an S3 bucket
43 44 45 46 47 48 49 |
# File 'lib/hati_config/remote_loader.rb', line 43 def from_s3(bucket:, key:, region:) s3 = Aws::S3::Client.new(region: region) response = s3.get_object(bucket: bucket, key: key) parse_response(response.body.read, File.extname(key)) rescue Aws::S3::Errors::ServiceError => e raise LoadDataError, "Failed to load configuration from S3: #{e.}" end |