Sha256: 6dc374f5c80e36de5b5f100c03294e7c026252dcdfda6479b4d37d135ff13526
Contents?: true
Size: 1.87 KB
Versions: 1
Compression:
Stored size: 1.87 KB
Contents
module Prefab class Client attr_reader :account_id, :shared_cache, :stats, :namespace, :logger, :creds, :channel, :interceptor def initialize(api_key:, logger: nil, stats: nil, # receives increment("prefab.limitcheck", {:tags=>["policy_group:page_view", "pass:true"]}) shared_cache: nil, # Something that quacks like Rails.cache ideally memcached local: false, namespace: "" ) @logger = (logger || Logger.new($stdout)).tap do |log| log.progname = "Prefab" if log.respond_to? :progname= end @stats = (stats || NoopStats.new) @shared_cache = (shared_cache || NoopCache.new) @account_id = api_key.split("|")[0].to_i @namespace = namespace @interceptor = AuthInterceptor.new(api_key) @creds = GRPC::Core::ChannelCredentials.new(ssl_certs) @channel = GRPC::Core::Channel.new('api.prefab.cloud:8443', nil, @creds) if local @channel = GRPC::Core::Channel.new('localhost:8443', nil, :this_channel_is_insecure) end end def config_client(timeout: 5.0) @config_client ||= Prefab::ConfigClient.new(self, timeout) end def ratelimit_client(timeout: 5.0) @ratelimit_client ||= Prefab::RateLimitClient.new(self, timeout) end def feature_flag_client @feature_flag_client ||= Prefab::FeatureFlagClient.new(self) end private def ssl_certs ssl_certs = "" Dir["#{OpenSSL::X509::DEFAULT_CERT_DIR}/*.pem"].each do |cert| ssl_certs << File.open(cert).read end if OpenSSL::X509::DEFAULT_CERT_FILE && File.exists?(OpenSSL::X509::DEFAULT_CERT_FILE) ssl_certs << File.open(OpenSSL::X509::DEFAULT_CERT_FILE).read end ssl_certs rescue => e @logger.warn("Issue loading SSL certs #{e.message}") ssl_certs end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
prefab-cloud-ruby-0.0.9 | lib/prefab/client.rb |