diff options
author | Jason Goodman <jgoodman@gitlab.com> | 2019-08-16 18:32:12 -0400 |
---|---|---|
committer | Jason Goodman <jgoodman@gitlab.com> | 2019-08-16 18:32:12 -0400 |
commit | 86f7c01121c0374665557d183815717732e01d5e (patch) | |
tree | 801662a5a290524d4477bf17224b433e8af9f6a3 | |
parent | 504ed1c4a44f3b86ce2ce1a545236c8c0f84c17f (diff) | |
download | gitlab-ce-gitlab-unleash-client-57943-spike.tar.gz |
Spike GitLab feature flags clientgitlab-unleash-client-57943-spike
Add Unleash gem
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | app/views/dashboard/_projects_head.html.haml | 2 | ||||
-rw-r--r-- | lib/feature_wrapper.rb | 30 |
4 files changed, 36 insertions, 1 deletions
@@ -441,6 +441,7 @@ gem 'toml-rb', '~> 1.0.0', require: false gem 'flipper', '~> 0.13.0' gem 'flipper-active_record', '~> 0.13.0' gem 'flipper-active_support_cache_store', '~> 0.13.0' +gem 'unleash', '~> 0.1.5' # Structured logging gem 'lograge', '~> 0.5' diff --git a/Gemfile.lock b/Gemfile.lock index fcc0fb64897..9cb89efc669 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -536,6 +536,7 @@ GEM multi_json (1.13.1) multi_xml (0.6.0) multipart-post (2.0.0) + murmurhash3 (0.1.6) mustermann (1.0.3) mustermann-grape (1.0.0) mustermann (~> 1.0.0) @@ -973,6 +974,8 @@ GEM get_process_mem (~> 0) unicorn (>= 4, < 6) uniform_notifier (1.10.0) + unleash (0.1.5) + murmurhash3 (~> 0.1.6) unparser (0.4.5) abstract_type (~> 0.0.7) adamantium (~> 0.2.0) @@ -1253,6 +1256,7 @@ DEPENDENCIES unf (~> 0.1.4) unicorn (~> 5.4.1) unicorn-worker-killer (~> 0.4.4) + unleash (~> 0.1.5) validates_hostname (~> 1.0.6) version_sorter (~> 2.2.4) virtus (~> 1.0.1) diff --git a/app/views/dashboard/_projects_head.html.haml b/app/views/dashboard/_projects_head.html.haml index 97a446dbeec..27924ef7774 100644 --- a/app/views/dashboard/_projects_head.html.haml +++ b/app/views/dashboard/_projects_head.html.haml @@ -9,7 +9,7 @@ - if current_user.can_create_project? .page-title-controls - = link_to _("New project"), new_project_path, class: "btn btn-success" + = link_to _("New project"), new_project_path, class: FeatureWrapper.enabled?(:blue_project_button, user: current_user) ? "btn btn-primary" : "btn btn-success" .top-area.scrolling-tabs-container.inner-page-scroll-tabs .fade-left= icon('angle-left') diff --git a/lib/feature_wrapper.rb b/lib/feature_wrapper.rb new file mode 100644 index 00000000000..b55bfbb423f --- /dev/null +++ b/lib/feature_wrapper.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'unleash' +require 'unleash/context' + +class FeatureWrapper + def self.enabled?(key, user: nil, thing: nil, default_enabled: false) + unleash_server_url = ENV['GITLAB_FEATURE_FLAG_SERVER_URL'] + instance_id = ENV['GITLAB_FEATURE_FLAG_INSTANCE_ID'] + app_name = Rails.env + + if unleash_server_url + key_string = key.to_s + + unleash = Unleash::Client.new({ + url: unleash_server_url, + instance_id: instance_id, + app_name: app_name + }) + + unleash_context = Unleash::Context.new + + unleash_context.user_id = user.email if user + + unleash.is_enabled?(key_string, unleash_context) + else + Feature.enabled?(key, thing, default_enabled: default_enabled) + end + end +end |