Commit 81299210 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Move Entities::Runner classes under Ci namespace

Move `Runner`, `Runner::Details`, and `RunnerRegistrationDetails` under
`Entities::Ci::` namespace.
parent 336089c0
......@@ -2202,8 +2202,8 @@ Cop/UserAdmin:
- 'ee/lib/ee/gitlab/git_access.rb'
- 'lib/api/award_emoji.rb'
- 'lib/api/ci/runners.rb'
- 'lib/api/entities/runner_details.rb'
- 'lib/api/entities/user_safe.rb'
- 'lib/api/entities/ci/runner_details.rb'
- 'lib/api/entities/ci/user_safe.rb'
- 'lib/api/groups.rb'
- 'lib/api/helpers.rb'
- 'lib/api/personal_access_tokens.rb'
......
......@@ -11,7 +11,7 @@ module API
resource :runners do
desc 'Registers a new Runner' do
success Entities::RunnerRegistrationDetails
success Entities::Ci::RunnerRegistrationDetails
http_codes [[201, 'Runner was created'], [403, 'Forbidden']]
end
params do
......@@ -47,7 +47,7 @@ module API
@runner = ::Ci::Runner.create(attributes)
if @runner.persisted?
present @runner, with: Entities::RunnerRegistrationDetails
present @runner, with: Entities::Ci::RunnerRegistrationDetails
else
render_validation_error!(@runner)
end
......
......@@ -11,7 +11,7 @@ module API
resource :runners do
desc 'Get runners available for user' do
success Entities::Runner
success Entities::Ci::Runner
end
params do
optional :scope, type: String, values: ::Ci::Runner::AVAILABLE_STATUSES,
......@@ -30,11 +30,11 @@ module API
runners = filter_runners(runners, params[:status], allowed_scopes: ::Ci::Runner::AVAILABLE_STATUSES)
runners = runners.tagged_with(params[:tag_list]) if params[:tag_list]
present paginate(runners), with: Entities::Runner
present paginate(runners), with: Entities::Ci::Runner
end
desc 'Get all runners - shared and specific' do
success Entities::Runner
success Entities::Ci::Runner
end
params do
optional :scope, type: String, values: ::Ci::Runner::AVAILABLE_SCOPES,
......@@ -55,11 +55,11 @@ module API
runners = filter_runners(runners, params[:status], allowed_scopes: ::Ci::Runner::AVAILABLE_STATUSES)
runners = runners.tagged_with(params[:tag_list]) if params[:tag_list]
present paginate(runners), with: Entities::Runner
present paginate(runners), with: Entities::Ci::Runner
end
desc "Get runner's details" do
success Entities::RunnerDetails
success Entities::Ci::RunnerDetails
end
params do
requires :id, type: Integer, desc: 'The ID of the runner'
......@@ -68,11 +68,11 @@ module API
runner = get_runner(params[:id])
authenticate_show_runner!(runner)
present runner, with: Entities::RunnerDetails, current_user: current_user
present runner, with: Entities::Ci::RunnerDetails, current_user: current_user
end
desc "Update runner's details" do
success Entities::RunnerDetails
success Entities::Ci::RunnerDetails
end
params do
requires :id, type: Integer, desc: 'The ID of the runner'
......@@ -92,14 +92,14 @@ module API
update_service = ::Ci::UpdateRunnerService.new(runner)
if update_service.update(declared_params(include_missing: false))
present runner, with: Entities::RunnerDetails, current_user: current_user
present runner, with: Entities::Ci::RunnerDetails, current_user: current_user
else
render_validation_error!(runner)
end
end
desc 'Remove a runner' do
success Entities::Runner
success Entities::Ci::Runner
end
params do
requires :id, type: Integer, desc: 'The ID of the runner'
......@@ -139,7 +139,7 @@ module API
before { authorize_admin_project }
desc 'Get runners available for project' do
success Entities::Runner
success Entities::Ci::Runner
end
params do
optional :scope, type: String, values: ::Ci::Runner::AVAILABLE_SCOPES,
......@@ -158,11 +158,11 @@ module API
runners = filter_runners(runners, params[:scope])
runners = apply_filter(runners, params)
present paginate(runners), with: Entities::Runner
present paginate(runners), with: Entities::Ci::Runner
end
desc 'Enable a runner for a project' do
success Entities::Runner
success Entities::Ci::Runner
end
params do
requires :runner_id, type: Integer, desc: 'The ID of the runner'
......@@ -172,14 +172,14 @@ module API
authenticate_enable_runner!(runner)
if runner.assign_to(user_project)
present runner, with: Entities::Runner
present runner, with: Entities::Ci::Runner
else
render_validation_error!(runner)
end
end
desc "Disable project's runner" do
success Entities::Runner
success Entities::Ci::Runner
end
params do
requires :runner_id, type: Integer, desc: 'The ID of the runner'
......@@ -204,7 +204,7 @@ module API
before { authorize_admin_group }
desc 'Get runners available for group' do
success Entities::Runner
success Entities::Ci::Runner
end
params do
optional :type, type: String, values: ::Ci::Runner::AVAILABLE_TYPES,
......@@ -218,7 +218,7 @@ module API
runners = ::Ci::Runner.belonging_to_group(user_group.id, include_ancestors: true)
runners = apply_filter(runners, params)
present paginate(runners), with: Entities::Runner
present paginate(runners), with: Entities::Ci::Runner
end
end
......
......@@ -7,7 +7,7 @@ module API
# artifacts_file is included in job_artifacts, but kept for backward compatibility (remove in api/v5)
expose :artifacts_file, using: ::API::Entities::Ci::JobArtifactFile, if: -> (job, opts) { job.artifacts? }
expose :job_artifacts, as: :artifacts, using: ::API::Entities::Ci::JobArtifact
expose :runner, with: ::API::Entities::Runner
expose :runner, with: ::API::Entities::Ci::Runner
expose :artifacts_expire_at
expose :tag_list do |job|
job.tags.map(&:name).sort
......
# frozen_string_literal: true
module API
module Entities
module Ci
class Runner < Grape::Entity
expose :id
expose :description
expose :ip_address
expose :active
expose :instance_type?, as: :is_shared
expose :runner_type
expose :name
expose :online?, as: :online
expose :status
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Ci
class RunnerDetails < Runner
expose :tag_list
expose :run_untagged
expose :locked
expose :maximum_timeout
expose :access_level
expose :version, :revision, :platform, :architecture
expose :contacted_at
# rubocop: disable CodeReuse/ActiveRecord
expose :projects, with: Entities::BasicProjectDetails do |runner, options|
if options[:current_user].admin? # rubocop: disable Cop/UserAdmin
runner.projects
else
options[:current_user].authorized_projects.where(id: runner.projects)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
expose :groups, with: Entities::BasicGroupDetails do |runner, options|
if options[:current_user].admin? # rubocop: disable Cop/UserAdmin
runner.groups
else
options[:current_user].authorized_groups.where(id: runner.groups)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end
......@@ -2,8 +2,10 @@
module API
module Entities
class RunnerRegistrationDetails < Grape::Entity
expose :id, :token
module Ci
class RunnerRegistrationDetails < Grape::Entity
expose :id, :token
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class Runner < Grape::Entity
expose :id
expose :description
expose :ip_address
expose :active
expose :instance_type?, as: :is_shared
expose :runner_type
expose :name
expose :online?, as: :online
expose :status
end
end
end
# frozen_string_literal: true
module API
module Entities
class RunnerDetails < Runner
expose :tag_list
expose :run_untagged
expose :locked
expose :maximum_timeout
expose :access_level
expose :version, :revision, :platform, :architecture
expose :contacted_at
# rubocop: disable CodeReuse/ActiveRecord
expose :projects, with: Entities::BasicProjectDetails do |runner, options|
if options[:current_user].admin?
runner.projects
else
options[:current_user].authorized_projects.where(id: runner.projects)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
expose :groups, with: Entities::BasicGroupDetails do |runner, options|
if options[:current_user].admin?
runner.groups
else
options[:current_user].authorized_groups.where(id: runner.groups)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment