feature-flag-monitor 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/console +24 -0
- data/bin/setup +8 -0
- data/feature-flag-monitor.gemspec +44 -0
- data/lib/feature_flag_monitor/configuration.rb +17 -0
- data/lib/feature_flag_monitor/consul_key.rb +27 -0
- data/lib/feature_flag_monitor/refinements/attemptable.rb +19 -0
- data/lib/feature_flag_monitor/refinements/hash_extensions.rb +15 -0
- data/lib/feature_flag_monitor/refinements/yield_self.rb +10 -0
- data/lib/feature_flag_monitor/refinements.rb +8 -0
- data/lib/feature_flag_monitor/test/helpers.rb +26 -0
- data/lib/feature_flag_monitor/utils/restricted_hash.rb +81 -0
- data/lib/feature_flag_monitor/utils.rb +75 -0
- data/lib/feature_flag_monitor/version.rb +3 -0
- data/lib/feature_flag_monitor.rb +188 -0
- metadata +207 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5e773ef74c79cae366fa0b71a9e098bc3415cfa099fc1dd6189fdf607ad1b8ad
|
4
|
+
data.tar.gz: 43d43aa07978605dcbff6558427417f208b40e473dbe1fe22c57f896cf7b9bbf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a5313c13aaf5a3b937179aea4b6c80dbf646790275ee2e36f61d33117feda60d76d0f0075519de0523d38748365d97b3003bfa2e061d01d58c59910907b1c15c
|
7
|
+
data.tar.gz: 969331464add408e28b500eba3ee7545edb7e60f52272a85be7d49d27f4fdf864a3552d582c8f7eb52c857f13b559f102ff239a58d5ae823ab012f9c0de232d6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Feature Flag Monitor Gem
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/feature_flag_monitor`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'feature_flag_monitor'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install feature_flag_monitor
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/feature_flag_monitor.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "feature_flag_monitor"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
FFM = FeatureFlagMonitor
|
14
|
+
FeatureFlagMonitor.configure do |config|
|
15
|
+
config.consul_uri = 'http://localhost:8500'
|
16
|
+
config.feature_flag_monitor_uri = 'http://localhost:1255'
|
17
|
+
end
|
18
|
+
|
19
|
+
def authorization
|
20
|
+
{ 'Authorization' => "Basic #{Base64.encode64("#{ENV['SUPERADMIN_USER']}:#{ENV['SUPERADMIN_PASS']}")}" }
|
21
|
+
end
|
22
|
+
|
23
|
+
require "irb"
|
24
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "feature_flag_monitor/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "feature-flag-monitor"
|
8
|
+
spec.version = FeatureFlagMonitor::VERSION
|
9
|
+
spec.authors = ["Michael Chui"]
|
10
|
+
spec.email = ["michael.chui@socrata.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Summary'
|
13
|
+
#spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
#spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "byebug", "~> 11.0"
|
33
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
35
|
+
spec.add_development_dependency 'simplecov'
|
36
|
+
spec.add_development_dependency 'simplecov-cobertura'
|
37
|
+
spec.add_development_dependency 'webmock'
|
38
|
+
|
39
|
+
spec.add_runtime_dependency "activesupport", ">= 5.2", "< 8.0"
|
40
|
+
spec.add_runtime_dependency "diplomat", ">= 0"
|
41
|
+
spec.add_runtime_dependency "httparty", "~> 0.13"
|
42
|
+
spec.add_runtime_dependency "request_store", ">= 1.3"
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FeatureFlagMonitor
|
2
|
+
class ConsulKey
|
3
|
+
def self.by_id(id)
|
4
|
+
self.new(:i, id)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.by_cname(cname)
|
8
|
+
self.new(:n, cname)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.for_types
|
12
|
+
self.new(:m, 'types').to_key
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(key_type, identifier)
|
16
|
+
@key_parts = ['ffm', key_type, identifier]
|
17
|
+
end
|
18
|
+
|
19
|
+
def for_domain
|
20
|
+
to_key
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_key
|
24
|
+
@key_parts.join('/') << '?stale'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FeatureFlagMonitor::Refinements::Attemptable
|
2
|
+
refine Object do
|
3
|
+
def attempt(message, *args, &block)
|
4
|
+
(respond_to?(message) && public_send(message, *args, &block)) || self
|
5
|
+
end
|
6
|
+
|
7
|
+
def blank?
|
8
|
+
nil? || (respond_to?(:empty?) && empty?)
|
9
|
+
end
|
10
|
+
|
11
|
+
def present?
|
12
|
+
!blank?
|
13
|
+
end
|
14
|
+
|
15
|
+
def property_present?(message)
|
16
|
+
respond_to?(message) && public_send(message).present?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FeatureFlagMonitor::Refinements::HashExtensions
|
2
|
+
refine Hash do
|
3
|
+
def slice(*keys)
|
4
|
+
keys.each_with_object({}) { |key, hash| hash[key] = self[key] }
|
5
|
+
end
|
6
|
+
|
7
|
+
def compact
|
8
|
+
reject { |_, value| value.nil? }
|
9
|
+
end
|
10
|
+
|
11
|
+
def map_values(&block)
|
12
|
+
keys.zip(values.map(&block)).to_h
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative '../utils/restricted_hash'
|
2
|
+
|
3
|
+
module FeatureFlagMonitor
|
4
|
+
module Test
|
5
|
+
module Helpers
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module FeatureFlagMonitor::Test::Helpers
|
11
|
+
class << self
|
12
|
+
attr_accessor :defaults, :wrapper_class
|
13
|
+
end
|
14
|
+
@defaults = {}
|
15
|
+
|
16
|
+
def stub_feature_flags(flags = {})
|
17
|
+
flags = FeatureFlagMonitor::Utils.wrapper_class.new(FeatureFlagMonitor::Test::Helpers.defaults.merge(flags))
|
18
|
+
|
19
|
+
allow(FeatureFlagMonitor).to receive(:list).
|
20
|
+
and_return(flags.transform_values { { description: '' } })
|
21
|
+
allow(FeatureFlagMonitor).to receive(:type_data).
|
22
|
+
and_return(flags.transform_values { %w(boolean integer string) }) # don't try to be smart; presume all types are acceptable
|
23
|
+
allow(FeatureFlagMonitor).to receive(:flag) { |name:, on_domain:| flags[name] }
|
24
|
+
allow(FeatureFlagMonitor).to receive(:flags_on).and_return(flags)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# A restricted hash is an immutable Hash that only comprehends the keys that it already knows.
|
2
|
+
# If a key it does not know is requested, it will raise FeatureFlagMonitor::FlagNotFound, as this
|
3
|
+
# exists in the context of the FeatureFlagMonitor gem.
|
4
|
+
#
|
5
|
+
# It bears some similarities with https://github.com/intridea/hashie#dash but is pointedly
|
6
|
+
# much less flexible.
|
7
|
+
#
|
8
|
+
# There is an additional goal of having full compatibility (to the extent immutability
|
9
|
+
# allows) with ActiveSupport core extensions, i.e. monkeypatches. I won't guarantee complete
|
10
|
+
# support with the first iteration; it is a moving target, and we don't use all of it
|
11
|
+
# anyways.
|
12
|
+
#
|
13
|
+
# #compact, #deep_merge, #except, and #slice should all work.
|
14
|
+
|
15
|
+
require 'active_support/hash_with_indifferent_access'
|
16
|
+
|
17
|
+
module FeatureFlagMonitor
|
18
|
+
module Utils
|
19
|
+
class RestrictedHash < ActiveSupport::HashWithIndifferentAccess
|
20
|
+
|
21
|
+
class MutationNotAllowed < NoMethodError; end
|
22
|
+
|
23
|
+
# There are more, but I am lazy.
|
24
|
+
MUTATION_METHODS = %i([]= compact! delete merge! reject! replace select! store update)
|
25
|
+
|
26
|
+
def initialize(hash = {}, when_not_found = FeatureFlagMonitor::FlagNotFound)
|
27
|
+
super()
|
28
|
+
merge!(hash)
|
29
|
+
|
30
|
+
@key_not_found = when_not_found
|
31
|
+
|
32
|
+
each_key do |flag|
|
33
|
+
singleton_class.class_eval do
|
34
|
+
define_method(flag) { fetch(flag) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
singleton_class.class_eval do
|
39
|
+
MUTATION_METHODS.each do |_method|
|
40
|
+
define_method(_method) { |*args, &block| raise MutationNotAllowed }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def [](key)
|
46
|
+
raise @key_not_found.new(key) unless key?(key)
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
def fetch(key, *args, &block)
|
51
|
+
begin
|
52
|
+
super
|
53
|
+
rescue KeyError
|
54
|
+
raise @key_not_found.new(key)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def method_missing(id, *args, &block)
|
59
|
+
raise @key_not_found.new(id)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Methods for compatibility.
|
63
|
+
|
64
|
+
# Many non-mutation methods work by creating a duplicate version first, so
|
65
|
+
# implementing this fixes them all nicely.
|
66
|
+
def dup
|
67
|
+
self.class.superclass.new(self)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Necessary because the ActiveSupport implementation relies on self.class.new.
|
71
|
+
#
|
72
|
+
# Stolen from: https://github.com/rails/rails/blob/ac717d65a31d05458588b78ea7719b79f8ea69e5/activesupport/lib/active_support/core_ext/hash/slice.rb#L23-L26
|
73
|
+
def slice(*keys)
|
74
|
+
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
|
75
|
+
keys.each_with_object(self.class.superclass.new) do |k, hash|
|
76
|
+
hash[k] = self[k] if has_key?(k)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require_relative 'utils/restricted_hash'
|
2
|
+
|
3
|
+
module FeatureFlagMonitor
|
4
|
+
module Utils
|
5
|
+
using Refinements::YieldSelf
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def derive(*sources, specs: FeatureFlagMonitor.type_data, processor: method(:process_value))
|
9
|
+
sources.compact.inject({}) do |memo, source|
|
10
|
+
merge(memo, source, specs: specs, processor: processor)
|
11
|
+
end.yield_self(&wrapper_class.method(:new))
|
12
|
+
end
|
13
|
+
|
14
|
+
def merge(base, other,
|
15
|
+
specs: FeatureFlagMonitor.type_data, processor: method(:process_value))
|
16
|
+
specs.each_with_object({}) do |(flag, spec), flags|
|
17
|
+
flags[flag] = processor.call(
|
18
|
+
if valid_value?(other[flag], spec) then other[flag]
|
19
|
+
else base[flag]
|
20
|
+
end)
|
21
|
+
end.yield_self(&wrapper_class.method(:new))
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_value?(unprocessed_value, spec)
|
25
|
+
value = process_value(unprocessed_value)
|
26
|
+
valid_classes = []
|
27
|
+
valid_values = []
|
28
|
+
|
29
|
+
boolean = [TrueClass, FalseClass]
|
30
|
+
parse_classes = lambda do |parseable_spec|
|
31
|
+
valid_classes.concat(boolean) if parseable_spec.include?('boolean')
|
32
|
+
valid_classes << Numeric if parseable_spec.include?('integer')
|
33
|
+
valid_classes << String if parseable_spec.include?('string')
|
34
|
+
end
|
35
|
+
|
36
|
+
case spec
|
37
|
+
# No type defined. Therefore boolean.
|
38
|
+
when NilClass then valid_classes.concat(boolean)
|
39
|
+
when Array, String
|
40
|
+
parseable_spec = spec.kind_of?(String) ? spec.split(/\s+/).reject(&:empty?) : spec
|
41
|
+
valid_values = parseable_spec - %w(boolean string integer)
|
42
|
+
valid_values = valid_values.first if valid_values.first.is_a?(Array)
|
43
|
+
parse_classes.call(parseable_spec)
|
44
|
+
when Hash
|
45
|
+
parse_classes.call(spec['anyOf']) if spec.key?('anyOf')
|
46
|
+
valid_classes.any?(&value.method(:kind_of?))
|
47
|
+
end
|
48
|
+
|
49
|
+
unless valid_values.nil? || valid_values.empty?
|
50
|
+
return true if valid_values.include?(value)
|
51
|
+
return false if valid_classes.empty?
|
52
|
+
end
|
53
|
+
valid_classes.any?(&value.method(:kind_of?))
|
54
|
+
end
|
55
|
+
|
56
|
+
def process_value(value)
|
57
|
+
return nil if value.nil?
|
58
|
+
|
59
|
+
begin
|
60
|
+
JSON.parse("{\"valueString\": #{value}}")['valueString']
|
61
|
+
rescue JSON::ParserError # This means it's a string!
|
62
|
+
value
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# This is a helper function to allow frontend to wrap in a Hashie::Mash instead,
|
67
|
+
# entirely so that I can be lazy and not deal with all the tests that expect an
|
68
|
+
# unrestricted hash.
|
69
|
+
attr_writer :wrapper_class
|
70
|
+
def wrapper_class
|
71
|
+
@wrapper_class ||= RestrictedHash
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'diplomat'
|
2
|
+
require 'httparty'
|
3
|
+
require 'request_store'
|
4
|
+
|
5
|
+
require 'feature_flag_monitor/configuration'
|
6
|
+
require 'feature_flag_monitor/consul_key'
|
7
|
+
require 'feature_flag_monitor/refinements'
|
8
|
+
require "feature_flag_monitor/utils"
|
9
|
+
require "feature_flag_monitor/version"
|
10
|
+
|
11
|
+
module FeatureFlagMonitor
|
12
|
+
using Refinements::Attemptable
|
13
|
+
using Refinements::HashExtensions
|
14
|
+
|
15
|
+
class FlagNotFound < StandardError; end
|
16
|
+
class GenericError < StandardError; end
|
17
|
+
class << self; attr_accessor :request_id; end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
return if Configuration.done?
|
21
|
+
yield(Configuration) if block_given?
|
22
|
+
|
23
|
+
error_msg = lambda do |type|
|
24
|
+
lambda do |uri|
|
25
|
+
raise Configuration::Error.new("#{type} URI not configured") if uri.nil?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
const_set(:FFM,
|
30
|
+
Configuration.feature_flag_monitor_uri.tap(&error_msg.call('Feature Flag Monitor')))
|
31
|
+
Diplomat.configure do |config|
|
32
|
+
config.url = Configuration.consul_uri.tap(&error_msg.call('Consul'))
|
33
|
+
end
|
34
|
+
|
35
|
+
Configuration.done!
|
36
|
+
end
|
37
|
+
|
38
|
+
IS_A_CNAME = [String, ->(domain) { domain.property_present?(:cname) }]
|
39
|
+
IS_AN_ID = [Numeric, ->(domain) { domain.property_present?(:id) }]
|
40
|
+
|
41
|
+
def self.list(with_descriptions: false)
|
42
|
+
request_store[:"list_#{with_descriptions}"] ||=
|
43
|
+
case with_descriptions
|
44
|
+
when TrueClass
|
45
|
+
headers = { 'X-Socrata-RequestId' => request_id }.compact
|
46
|
+
JSON.parse(HTTParty.get(URI.join(FFM, 'describe.json'), headers: headers).body)
|
47
|
+
when FalseClass
|
48
|
+
type_data.map_values { |type| { 'type' => type } }
|
49
|
+
end.map_values do |config|
|
50
|
+
# Entirely for backwards compatibility with Signaller's config format.
|
51
|
+
config['disableTrueFalse'] = true unless config['type'].include?('boolean')
|
52
|
+
(config['type'] - [ 'boolean', 'integer', 'string' ]).tap do |expected_values|
|
53
|
+
config['expectedValues'] = expected_values.join(' ') unless expected_values.empty?
|
54
|
+
end
|
55
|
+
config
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.domains
|
60
|
+
headers = { 'X-Socrata-RequestId' => request_id }.compact
|
61
|
+
endpoint = 'domains.json'
|
62
|
+
request_store[:domains] ||=
|
63
|
+
JSON.parse(HTTParty.get(URI.join(FFM, endpoint), headers: headers).body)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.type_data
|
67
|
+
request_store[:type_data] ||= fetch(ConsulKey.for_types)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.flags_on(domain:)
|
71
|
+
request_store[:"flags_on_#{domain}"] ||=
|
72
|
+
fetch(
|
73
|
+
case domain
|
74
|
+
when *IS_A_CNAME then ConsulKey.by_cname(domain.attempt(:cname))
|
75
|
+
when *IS_AN_ID then ConsulKey.by_id(domain.attempt(:id))
|
76
|
+
end.for_domain
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.flag(name:, on_domain:)
|
81
|
+
flags_on(domain: on_domain)[name.to_s]
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.report(for_flag:)
|
85
|
+
headers = { 'X-Socrata-RequestId' => request_id }.compact
|
86
|
+
endpoint = [ 'report', for_flag ].join('/') << '.json'
|
87
|
+
request_store[:"report_#{for_flag}"] ||=
|
88
|
+
JSON.parse(HTTParty.get(URI.join(FFM, endpoint), headers: headers).body)
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.set(flag:, value:, domain: nil, authorization:)
|
92
|
+
domain = extract_cname(domain)
|
93
|
+
headers = {
|
94
|
+
'X-Socrata-Host' => domain,
|
95
|
+
'X-Socrata-RequestId' => request_id,
|
96
|
+
'Content-Type' => 'application/json',
|
97
|
+
}.merge(authorization).compact
|
98
|
+
|
99
|
+
endpoint = flag_endpoint(flag, domain)
|
100
|
+
HTTParty.put(URI.join(FFM, endpoint), body: value.to_json, headers: headers).
|
101
|
+
tap(&method(:raise_errors_on_non_success))
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.set_multiple(flags:, domain: nil, authorization:)
|
105
|
+
domain = extract_cname(domain)
|
106
|
+
headers = {
|
107
|
+
'X-Socrata-Host' => domain,
|
108
|
+
'X-Socrata-RequestId' => request_id,
|
109
|
+
'Content-Type' => 'application/json',
|
110
|
+
}.merge(authorization).compact
|
111
|
+
|
112
|
+
endpoint = domain_endpoint(domain)
|
113
|
+
HTTParty.send(:patch, URI.join(FFM, endpoint), body: flags.to_json, headers: headers).
|
114
|
+
tap(&method(:raise_errors_on_non_success))
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.bulk_write(flags:, domains: nil, cohort: nil, exceptions: {}, authorization:)
|
118
|
+
raise ArgumentError, 'Must provide either domains or cohort.' if domains.nil? && cohort.nil?
|
119
|
+
|
120
|
+
headers = {
|
121
|
+
'X-Socrata-RequestId' => request_id,
|
122
|
+
'Content-Type' => 'application/json',
|
123
|
+
}.merge(authorization).compact
|
124
|
+
|
125
|
+
payload = {
|
126
|
+
flags: flags,
|
127
|
+
domains: domains,
|
128
|
+
cohort: cohort,
|
129
|
+
except: exceptions
|
130
|
+
}
|
131
|
+
HTTParty.send(:patch, URI.join(FFM, bulk_endpoint), body: payload.to_json, headers: headers).
|
132
|
+
tap(&method(:raise_errors_on_non_success))
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.reset(flag:, domain: nil, authorization:)
|
136
|
+
domain = extract_cname(domain)
|
137
|
+
headers = {
|
138
|
+
'X-Socrata-Host' => domain,
|
139
|
+
'X-Socrata-RequestId' => request_id,
|
140
|
+
'Content-Type' => 'application/json',
|
141
|
+
}.merge(authorization).compact
|
142
|
+
|
143
|
+
endpoint = flag_endpoint(flag, domain)
|
144
|
+
HTTParty.delete(URI.join(FFM, endpoint), headers: headers).
|
145
|
+
tap(&method(:raise_errors_on_non_success))
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
def self.fetch(key)
|
150
|
+
begin
|
151
|
+
Diplomat::Kv.get(key, http_addr: Configuration.consul_uri)
|
152
|
+
rescue Diplomat::KeyNotFound
|
153
|
+
Diplomat::Kv.get(key, http_addr: Configuration.feature_flag_monitor_uri)
|
154
|
+
end.yield_self(&JSON.method(:parse))
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.flag_endpoint(flag, domain)
|
158
|
+
if domain.nil? then [ 'env_state', flag ]
|
159
|
+
else [ 'flag', flag, domain ]
|
160
|
+
end.join('/') << '.json'
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.domain_endpoint(domain)
|
164
|
+
if domain.nil? then [ 'env_state' ]
|
165
|
+
else [ 'domain', domain ]
|
166
|
+
end.join('/') << '.json'
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.bulk_endpoint
|
170
|
+
'bulk.json'
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.extract_cname(domain)
|
174
|
+
domain.attempt(:cname)
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.request_store
|
178
|
+
RequestStore[:feature_flag_monitor] ||= {}
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.raise_errors_on_non_success(response)
|
182
|
+
return if (200..299).include?(response.code)
|
183
|
+
message = response.parsed_response['message']
|
184
|
+
message << '. '
|
185
|
+
message << response.parsed_response['data'].to_json
|
186
|
+
raise GenericError.new(message)
|
187
|
+
end
|
188
|
+
end
|
metadata
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: feature-flag-monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Chui
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '11.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov-cobertura
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.2'
|
104
|
+
- - "<"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '8.0'
|
107
|
+
type: :runtime
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '5.2'
|
114
|
+
- - "<"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '8.0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: diplomat
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :runtime
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: httparty
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0.13'
|
138
|
+
type: :runtime
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0.13'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: request_store
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '1.3'
|
152
|
+
type: :runtime
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '1.3'
|
159
|
+
description:
|
160
|
+
email:
|
161
|
+
- michael.chui@socrata.com
|
162
|
+
executables: []
|
163
|
+
extensions: []
|
164
|
+
extra_rdoc_files: []
|
165
|
+
files:
|
166
|
+
- ".gitignore"
|
167
|
+
- ".rspec"
|
168
|
+
- Gemfile
|
169
|
+
- README.md
|
170
|
+
- Rakefile
|
171
|
+
- bin/console
|
172
|
+
- bin/setup
|
173
|
+
- feature-flag-monitor.gemspec
|
174
|
+
- lib/feature_flag_monitor.rb
|
175
|
+
- lib/feature_flag_monitor/configuration.rb
|
176
|
+
- lib/feature_flag_monitor/consul_key.rb
|
177
|
+
- lib/feature_flag_monitor/refinements.rb
|
178
|
+
- lib/feature_flag_monitor/refinements/attemptable.rb
|
179
|
+
- lib/feature_flag_monitor/refinements/hash_extensions.rb
|
180
|
+
- lib/feature_flag_monitor/refinements/yield_self.rb
|
181
|
+
- lib/feature_flag_monitor/test/helpers.rb
|
182
|
+
- lib/feature_flag_monitor/utils.rb
|
183
|
+
- lib/feature_flag_monitor/utils/restricted_hash.rb
|
184
|
+
- lib/feature_flag_monitor/version.rb
|
185
|
+
homepage:
|
186
|
+
licenses: []
|
187
|
+
metadata: {}
|
188
|
+
post_install_message:
|
189
|
+
rdoc_options: []
|
190
|
+
require_paths:
|
191
|
+
- lib
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
requirements: []
|
203
|
+
rubygems_version: 3.4.19
|
204
|
+
signing_key:
|
205
|
+
specification_version: 4
|
206
|
+
summary: Summary
|
207
|
+
test_files: []
|