diff options
author | Alejandro RodrÃguez <alejorro70@gmail.com> | 2017-05-31 21:06:01 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-05-31 21:06:01 +0000 |
commit | 671284ba375109becbfa2a288032cdc7301b157b (patch) | |
tree | fc055d19700f433115bbed4f62a86a72c711c56f /lib/api/features.rb | |
parent | 322c9be816cd5cd9747a8737ec04622aa6b81e6b (diff) | |
download | gitlab-ce-671284ba375109becbfa2a288032cdc7301b157b.tar.gz |
Add feature toggles through Flipper
Diffstat (limited to 'lib/api/features.rb')
-rw-r--r-- | lib/api/features.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/api/features.rb b/lib/api/features.rb new file mode 100644 index 00000000000..cff0ba2ddff --- /dev/null +++ b/lib/api/features.rb @@ -0,0 +1,36 @@ +module API + class Features < Grape::API + before { authenticated_as_admin! } + + resource :features do + desc 'Get a list of all features' do + success Entities::Feature + end + get do + features = Feature.all + + present features, with: Entities::Feature, current_user: current_user + end + + desc 'Set the gate value for the given feature' do + success Entities::Feature + end + params do + requires :value, type: String, desc: '`true` or `false` to enable/disable, an integer for percentage of time' + end + post ':name' do + feature = Feature.get(params[:name]) + + if %w(0 false).include?(params[:value]) + feature.disable + elsif params[:value] == 'true' + feature.enable + else + feature.enable_percentage_of_time(params[:value].to_i) + end + + present feature, with: Entities::Feature, current_user: current_user + end + end + end +end |