diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/boards.rb | 1 | ||||
-rw-r--r-- | lib/api/entities.rb | 18 | ||||
-rw-r--r-- | lib/api/pipelines.rb | 2 | ||||
-rw-r--r-- | lib/api/runner.rb | 19 | ||||
-rw-r--r-- | lib/api/runners.rb | 9 |
5 files changed, 34 insertions, 15 deletions
diff --git a/lib/api/boards.rb b/lib/api/boards.rb index 6c706b2b4e1..086d39d5070 100644 --- a/lib/api/boards.rb +++ b/lib/api/boards.rb @@ -33,6 +33,7 @@ module API success Entities::Board end get '/:board_id' do + authorize!(:read_board, user_project) present board, with: Entities::Board end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index bb48a86fe9e..3a6e707fd5b 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -769,28 +769,33 @@ module API class Todo < Grape::Entity expose :id - expose :project, using: Entities::BasicProjectDetails + expose :project, using: Entities::ProjectIdentity, if: -> (todo, _) { todo.project_id } + expose :group, using: 'API::Entities::NamespaceBasic', if: -> (todo, _) { todo.group_id } expose :author, using: Entities::UserBasic expose :action_name expose :target_type expose :target do |todo, options| - Entities.const_get(todo.target_type).represent(todo.target, options) + todo_target_class(todo.target_type).represent(todo.target, options) end expose :target_url do |todo, options| target_type = todo.target_type.underscore - target_url = "namespace_project_#{target_type}_url" + target_url = "#{todo.parent.class.to_s.underscore}_#{target_type}_url" target_anchor = "note_#{todo.note_id}" if todo.note_id? Gitlab::Routing .url_helpers - .public_send(target_url, todo.project.namespace, todo.project, todo.target, anchor: target_anchor) # rubocop:disable GitlabSecurity/PublicSend + .public_send(target_url, todo.parent, todo.target, anchor: target_anchor) # rubocop:disable GitlabSecurity/PublicSend end expose :body expose :state expose :created_at + + def todo_target_class(target_type) + ::API::Entities.const_get(target_type) + end end class NamespaceBasic < Grape::Entity @@ -1010,7 +1015,7 @@ module API expose :description expose :ip_address expose :active - expose :is_shared + expose :instance_type?, as: :is_shared expose :name expose :online?, as: :online expose :status @@ -1024,7 +1029,7 @@ module API expose :access_level expose :version, :revision, :platform, :architecture expose :contacted_at - expose :token, if: lambda { |runner, options| options[:current_user].admin? || !runner.is_shared? } + expose :token, if: lambda { |runner, options| options[:current_user].admin? || !runner.instance_type? } expose :projects, with: Entities::BasicProjectDetails do |runner, options| if options[:current_user].admin? runner.projects @@ -1198,6 +1203,7 @@ module API class RunnerInfo < Grape::Entity expose :metadata_timeout, as: :timeout + expose :runner_session_url end class Step < Grape::Entity diff --git a/lib/api/pipelines.rb b/lib/api/pipelines.rb index 8374a57edfa..5d33a13d035 100644 --- a/lib/api/pipelines.rb +++ b/lib/api/pipelines.rb @@ -31,7 +31,7 @@ module API get ':id/pipelines' do authorize! :read_pipeline, user_project - pipelines = PipelinesFinder.new(user_project, params).execute + pipelines = PipelinesFinder.new(user_project, current_user, params).execute present paginate(pipelines), with: Entities::PipelineBasic end diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 96a02914faa..d0cc0945a5f 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -24,13 +24,13 @@ module API attributes = if runner_registration_token_valid? # Create shared runner. Requires admin access - attributes.merge(is_shared: true, runner_type: :instance_type) + attributes.merge(runner_type: :instance_type) elsif project = Project.find_by(runners_token: params[:token]) # Create a specific runner for the project - attributes.merge(is_shared: false, runner_type: :project_type, projects: [project]) + attributes.merge(runner_type: :project_type, projects: [project]) elsif group = Group.find_by(runners_token: params[:token]) # Create a specific runner for the group - attributes.merge(is_shared: false, runner_type: :group_type, groups: [group]) + attributes.merge(runner_type: :group_type, groups: [group]) else forbidden! end @@ -81,6 +81,11 @@ module API requires :token, type: String, desc: %q(Runner's authentication token) optional :last_update, type: String, desc: %q(Runner's queue last_update token) optional :info, type: Hash, desc: %q(Runner's metadata) + optional :session, type: Hash, desc: %q(Runner's session data) do + optional :url, type: String, desc: %q(Session's url) + optional :certificate, type: String, desc: %q(Session's certificate) + optional :authorization, type: String, desc: %q(Session's authorization) + end end post '/request' do authenticate_runner! @@ -90,14 +95,16 @@ module API break no_content! end - if current_runner.runner_queue_value_latest?(params[:last_update]) - header 'X-GitLab-Last-Update', params[:last_update] + runner_params = declared_params(include_missing: false) + + if current_runner.runner_queue_value_latest?(runner_params[:last_update]) + header 'X-GitLab-Last-Update', runner_params[:last_update] Gitlab::Metrics.add_event(:build_not_found_cached) break no_content! end new_update = current_runner.ensure_runner_queue_value - result = ::Ci::RegisterJobService.new(current_runner).execute + result = ::Ci::RegisterJobService.new(current_runner).execute(runner_params) if result.valid? if result.build diff --git a/lib/api/runners.rb b/lib/api/runners.rb index 2b78075ddbf..2071c5a62c1 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -119,7 +119,7 @@ module API use :pagination end get ':id/runners' do - runners = filter_runners(Ci::Runner.owned_or_shared(user_project.id), params[:scope]) + runners = filter_runners(Ci::Runner.owned_or_instance_wide(user_project.id), params[:scope]) present paginate(runners), with: Entities::Runner end @@ -170,6 +170,11 @@ module API render_api_error!('Scope contains invalid value', 400) end + # Support deprecated scopes + if runners.respond_to?("deprecated_#{scope}") + scope = "deprecated_#{scope}" + end + runners.public_send(scope) # rubocop:disable GitlabSecurity/PublicSend end @@ -180,7 +185,7 @@ module API end def authenticate_show_runner!(runner) - return if runner.is_shared || current_user.admin? + return if runner.instance_type? || current_user.admin? forbidden!("No access granted") unless can?(current_user, :read_runner, runner) end |