From f0d0400d0be6948f769c8733386ed765a04d23b2 Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Wed, 6 Jun 2018 15:55:14 +0200 Subject: add Ci::Runner.offline scope to API --- lib/api/runners.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/api/runners.rb b/lib/api/runners.rb index 51242341dba..bf9cd6234a3 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -9,12 +9,12 @@ module API success Entities::Runner end params do - optional :scope, type: String, values: %w[active paused online], + optional :scope, type: String, values: %w[active paused online offline], desc: 'The scope of specific runners to show' use :pagination end get do - runners = filter_runners(current_user.ci_owned_runners, params[:scope], without: %w(specific shared)) + runners = filter_runners(current_user.ci_owned_runners, params[:scope], only: Ci::Runner::AVAILABLE_STATUSES) present paginate(runners), with: Entities::Runner end @@ -22,7 +22,7 @@ module API success Entities::Runner end params do - optional :scope, type: String, values: %w[active paused online specific shared], + optional :scope, type: String, values: %w[active paused online offline specific shared], desc: 'The scope of specific runners to show' use :pagination end @@ -114,7 +114,7 @@ module API success Entities::Runner end params do - optional :scope, type: String, values: %w[active paused online specific shared], + optional :scope, type: String, values: %w[active paused online offline specific shared], desc: 'The scope of specific runners to show' use :pagination end @@ -158,15 +158,12 @@ module API end helpers do - def filter_runners(runners, scope, options = {}) + def filter_runners(runners, scope, only: nil) return runners unless scope.present? - available_scopes = ::Ci::Runner::AVAILABLE_SCOPES - if options[:without] - available_scopes = available_scopes - options[:without] - end + available_scopes = only || ::Ci::Runner::AVAILABLE_SCOPES - if (available_scopes & [scope]).empty? + unless available_scopes.include?(scope) render_api_error!('Scope contains invalid value', 400) end -- cgit v1.2.1 From bbc305b1a24785d780fe0672d9e49f2c53af463b Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Thu, 7 Jun 2018 17:43:23 +0200 Subject: dry up available scopes to constants --- lib/api/runners.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/api/runners.rb b/lib/api/runners.rb index bf9cd6234a3..3ddf6694e57 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -9,7 +9,7 @@ module API success Entities::Runner end params do - optional :scope, type: String, values: %w[active paused online offline], + optional :scope, type: String, values: Ci::Runner::AVAILABLE_STATUSES, desc: 'The scope of specific runners to show' use :pagination end @@ -22,7 +22,7 @@ module API success Entities::Runner end params do - optional :scope, type: String, values: %w[active paused online offline specific shared], + optional :scope, type: String, values: Ci::Runner::AVAILABLE_SCOPES, desc: 'The scope of specific runners to show' use :pagination end @@ -114,7 +114,7 @@ module API success Entities::Runner end params do - optional :scope, type: String, values: %w[active paused online offline specific shared], + optional :scope, type: String, values: Ci::Runner::AVAILABLE_SCOPES, desc: 'The scope of specific runners to show' use :pagination end -- cgit v1.2.1 From b4e2cc4421c8a836ae26867ac3eec35be079590a Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Wed, 12 Sep 2018 20:14:49 +0200 Subject: replace cond. assignment by default param value --- lib/api/runners.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/api/runners.rb b/lib/api/runners.rb index 3ddf6694e57..fad7f5f0483 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -14,7 +14,7 @@ module API use :pagination end get do - runners = filter_runners(current_user.ci_owned_runners, params[:scope], only: Ci::Runner::AVAILABLE_STATUSES) + runners = filter_runners(current_user.ci_owned_runners, params[:scope], allowed_scopes: Ci::Runner::AVAILABLE_STATUSES) present paginate(runners), with: Entities::Runner end @@ -158,12 +158,10 @@ module API end helpers do - def filter_runners(runners, scope, only: nil) + def filter_runners(runners, scope, allowed_scopes: ::Ci::Runner::AVAILABLE_SCOPES) return runners unless scope.present? - available_scopes = only || ::Ci::Runner::AVAILABLE_SCOPES - - unless available_scopes.include?(scope) + unless allowed_scopes.include?(scope) render_api_error!('Scope contains invalid value', 400) end -- cgit v1.2.1