class Flipper::Cloud::Configuration
Constants
- DEFAULT_URL
- VALID_SYNC_METHODS
The set of valid ways that syncing can happpen.
Attributes
Public: IO stream to send debug output too. Off by default.
# for example, this would send all http request information to STDOUT configuration = Flipper::Cloud::Configuration.new configuration.debug_output = STDOUT
Public: Instrumenter to use for the Flipper
instance returned by
Flipper::Cloud.new (default: Flipper::Instrumenters::Noop). # for example, to use active support notifications you could do: configuration = Flipper::Cloud::Configuration.new configuration.instrumenter = ActiveSupport::Notifications
Public: Local adapter that all reads should go to in order to ensure latency is low and resiliency is high. This adapter is automatically kept in sync with cloud.
# for example, to use active record you could do: configuration = Flipper::Cloud::Configuration.new configuration.local_adapter = Flipper::Adapters::ActiveRecord.new
Public: net/http open timeout for all http requests (default: 5).
Public: net/http read timeout for all http requests (default: 5).
Public: The Integer or Float number of seconds between attempts to bring the local in sync with cloud (default: 10).
Public: The secret used to verify if syncs in the middleware should occur or not.
Public: The token corresponding to an environment on flippercloud.io.
Public: The url for http adapter. Really should only be customized for
development work. Feel free to forget you ever saw this.
Public: net/http write timeout for all http requests (default: 5).
Public Class Methods
# File lib/flipper/cloud/configuration.rb, line 66 def initialize(options = {}) @token = options.fetch(:token) { ENV["FLIPPER_CLOUD_TOKEN"] } if @token.nil? raise ArgumentError, "Flipper::Cloud token is missing. Please set FLIPPER_CLOUD_TOKEN or provide the token (e.g. Flipper::Cloud.new(token: 'token'))." end if ENV["FLIPPER_CLOUD_SYNC_METHOD"] warn "FLIPPER_CLOUD_SYNC_METHOD is deprecated and has no effect." end self.sync_method = options[:sync_method] if options[:sync_method] @instrumenter = options.fetch(:instrumenter, Instrumenters::Noop) @read_timeout = options.fetch(:read_timeout) { ENV.fetch("FLIPPER_CLOUD_READ_TIMEOUT", 5).to_f } @open_timeout = options.fetch(:open_timeout) { ENV.fetch("FLIPPER_CLOUD_OPEN_TIMEOUT", 5).to_f } @write_timeout = options.fetch(:write_timeout) { ENV.fetch("FLIPPER_CLOUD_WRITE_TIMEOUT", 5).to_f } @sync_interval = options.fetch(:sync_interval) { ENV.fetch("FLIPPER_CLOUD_SYNC_INTERVAL", 10).to_f } @sync_secret = options.fetch(:sync_secret) { ENV["FLIPPER_CLOUD_SYNC_SECRET"] } @local_adapter = options.fetch(:local_adapter) { Adapters::Memory.new } @debug_output = options[:debug_output] @adapter_block = ->(adapter) { adapter } self.url = options.fetch(:url) { ENV.fetch("FLIPPER_CLOUD_URL", DEFAULT_URL) } end
Public Instance Methods
Public: Read or customize the http adapter. Calling without a block will perform a read. Calling with a block yields the cloud adapter for customization.
# for example, to instrument the http calls, you can wrap the http # adapter with the intsrumented adapter configuration = Flipper::Cloud::Configuration.new configuration.adapter do |adapter| Flipper::Adapters::Instrumented.new(adapter) end
# File lib/flipper/cloud/configuration.rb, line 101 def adapter(&block) if block_given? @adapter_block = block else @adapter_block.call app_adapter end end
# File lib/flipper/cloud/configuration.rb, line 112 def sync Flipper::Adapters::Sync::Synchronizer.new(local_adapter, http_adapter, { instrumenter: instrumenter, interval: sync_interval, }).call end
Public: The method that will be used to synchronize local adapter with cloud. (default: :poll, will be :webhook if sync_secret
is set).
# File lib/flipper/cloud/configuration.rb, line 121 def sync_method sync_secret ? :webhook : :poll end
# File lib/flipper/cloud/configuration.rb, line 125 def sync_method=(_) warn "Flipper::Cloud: sync_method is deprecated and has no effect." end
Private Instance Methods
# File lib/flipper/cloud/configuration.rb, line 131 def app_adapter sync_method == :webhook ? dual_write_adapter : sync_adapter end
# File lib/flipper/cloud/configuration.rb, line 135 def dual_write_adapter Flipper::Adapters::DualWrite.new(local_adapter, http_adapter) end
# File lib/flipper/cloud/configuration.rb, line 146 def http_adapter Flipper::Adapters::Http.new({ url: @url, read_timeout: @read_timeout, open_timeout: @open_timeout, debug_output: @debug_output, headers: { "Flipper-Cloud-Token" => @token, "Feature-Flipper-Token" => @token, "Client-Lang" => "ruby", "Client-Lang-Version" => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})", "Client-Platform" => RUBY_PLATFORM, "Client-Engine" => defined?(RUBY_ENGINE) ? RUBY_ENGINE : "", "Client-Hostname" => Socket.gethostname, }, }) end
# File lib/flipper/cloud/configuration.rb, line 139 def sync_adapter Flipper::Adapters::Sync.new(local_adapter, http_adapter, { instrumenter: instrumenter, interval: sync_interval, }) end