2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Ci
|
|
|
|
class ResourceGroups < ::API::Base
|
2022-07-16 23:28:13 +05:30
|
|
|
include PaginationParams
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
ci_resource_groups_tags = %w[ci_resource_groups]
|
|
|
|
|
|
|
|
RESOURCE_GROUP_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS
|
|
|
|
.merge(key: API::NO_SLASH_URL_PART_REGEX)
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
before { authenticate! }
|
|
|
|
|
|
|
|
feature_category :continuous_delivery
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :id,
|
|
|
|
types: [String, Integer],
|
|
|
|
desc: 'The ID or URL-encoded path of the project owned by the authenticated user'
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
resource :projects, requirements: ::API::API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'Get all resource groups for a project' do
|
2022-07-16 23:28:13 +05:30
|
|
|
success Entities::Ci::ResourceGroup
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
is_array true
|
|
|
|
tags ci_resource_groups_tags
|
2022-07-16 23:28:13 +05:30
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
get ':id/resource_groups' do
|
|
|
|
authorize! :read_resource_group, user_project
|
|
|
|
|
|
|
|
present paginate(user_project.resource_groups), with: Entities::Ci::ResourceGroup
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'Get a specific resource group' do
|
2021-11-18 22:05:49 +05:30
|
|
|
success Entities::Ci::ResourceGroup
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags ci_resource_groups_tags
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :key, type: String, desc: 'The key of the resource group'
|
|
|
|
end
|
2023-01-13 00:05:48 +05:30
|
|
|
get ':id/resource_groups/:key', requirements: RESOURCE_GROUP_ENDPOINT_REQUIREMENTS do
|
2021-11-18 22:05:49 +05:30
|
|
|
authorize! :read_resource_group, resource_group
|
|
|
|
|
|
|
|
present resource_group, with: Entities::Ci::ResourceGroup
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'List upcoming jobs for a specific resource group' do
|
2022-11-25 23:54:43 +05:30
|
|
|
success Entities::Ci::JobBasic
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
is_array true
|
|
|
|
tags ci_resource_groups_tags
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :key, type: String, desc: 'The key of the resource group'
|
|
|
|
|
|
|
|
use :pagination
|
|
|
|
end
|
2023-01-13 00:05:48 +05:30
|
|
|
get ':id/resource_groups/:key/upcoming_jobs', requirements: RESOURCE_GROUP_ENDPOINT_REQUIREMENTS do
|
2022-11-25 23:54:43 +05:30
|
|
|
authorize! :read_resource_group, resource_group
|
|
|
|
authorize! :read_build, user_project
|
|
|
|
|
|
|
|
upcoming_processables = resource_group
|
|
|
|
.upcoming_processables
|
|
|
|
.preload(:user, pipeline: :project) # rubocop:disable CodeReuse/ActiveRecord
|
|
|
|
|
|
|
|
present paginate(upcoming_processables), with: Entities::Ci::JobBasic
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'Edit an existing resource group' do
|
|
|
|
detail "Updates an existing resource group's properties."
|
2021-11-18 22:05:49 +05:30
|
|
|
success Entities::Ci::ResourceGroup
|
2023-01-13 00:05:48 +05:30
|
|
|
failure [
|
|
|
|
{ code: 400, message: 'Bad request' },
|
|
|
|
{ code: 401, message: 'Unauthorized' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags ci_resource_groups_tags
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :key, type: String, desc: 'The key of the resource group'
|
2023-01-13 00:05:48 +05:30
|
|
|
|
|
|
|
optional :process_mode,
|
|
|
|
type: String,
|
|
|
|
desc: 'The process mode of the resource group',
|
|
|
|
values: ::Ci::ResourceGroup.process_modes.keys
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
2023-01-13 00:05:48 +05:30
|
|
|
put ':id/resource_groups/:key', requirements: RESOURCE_GROUP_ENDPOINT_REQUIREMENTS do
|
2021-11-18 22:05:49 +05:30
|
|
|
authorize! :update_resource_group, resource_group
|
|
|
|
|
|
|
|
if resource_group.update(declared_params(include_missing: false))
|
|
|
|
present resource_group, with: Entities::Ci::ResourceGroup
|
|
|
|
else
|
|
|
|
render_validation_error!(resource_group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
helpers do
|
|
|
|
def resource_group
|
|
|
|
@resource_group ||= user_project.resource_groups.find_by_key!(params[:key])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|