debian-mirror-gitlab/lib/api/clusters/agents.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
2.9 KiB
Ruby
Raw Normal View History

2022-06-21 17:19:12 +05:30
# frozen_string_literal: true
module API
module Clusters
class Agents < ::API::Base
include PaginationParams
before { authenticate! }
feature_category :kubernetes_management
2022-07-16 23:28:13 +05:30
urgency :low
2022-06-21 17:19:12 +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'
2022-06-21 17:19:12 +05:30
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
2023-01-13 00:05:48 +05:30
desc 'List the agents for a project' do
detail 'This feature was introduced in GitLab 14.10. Returns the list of agents registered for the project.'
2022-06-21 17:19:12 +05:30
success Entities::Clusters::Agent
2023-01-13 00:05:48 +05:30
tags %w[cluster_agents]
2022-06-21 17:19:12 +05:30
end
params do
use :pagination
end
get ':id/cluster_agents' do
2022-07-23 23:45:48 +05:30
not_found!('ClusterAgents') unless can?(current_user, :read_cluster, user_project)
2022-06-21 17:19:12 +05:30
agents = ::Clusters::AgentsFinder.new(user_project, current_user).execute
present paginate(agents), with: Entities::Clusters::Agent
end
2023-01-13 00:05:48 +05:30
desc 'Get details about an agent' do
detail 'This feature was introduced in GitLab 14.10. Gets a single agent details.'
2022-06-21 17:19:12 +05:30
success Entities::Clusters::Agent
2023-01-13 00:05:48 +05:30
tags %w[cluster_agents]
2022-06-21 17:19:12 +05:30
end
params do
requires :agent_id, type: Integer, desc: 'The ID of an agent'
end
get ':id/cluster_agents/:agent_id' do
2022-07-23 23:45:48 +05:30
agent = ::Clusters::AgentsFinder.new(user_project, current_user).find(params[:agent_id])
2022-06-21 17:19:12 +05:30
present agent, with: Entities::Clusters::Agent
end
2023-01-13 00:05:48 +05:30
desc 'Register an agent with a project' do
detail 'This feature was introduced in GitLab 14.10. Registers an agent to the project.'
2022-06-21 17:19:12 +05:30
success Entities::Clusters::Agent
2023-01-13 00:05:48 +05:30
tags %w[cluster_agents]
2022-06-21 17:19:12 +05:30
end
params do
requires :name, type: String, desc: 'The name of the agent'
end
post ':id/cluster_agents' do
authorize! :create_cluster, user_project
params = declared_params(include_missing: false)
result = ::Clusters::Agents::CreateService.new(user_project, current_user).execute(name: params[:name])
bad_request!(result[:message]) if result[:status] == :error
present result[:cluster_agent], with: Entities::Clusters::Agent
end
2023-01-13 00:05:48 +05:30
desc 'Delete a registered agent' do
detail 'This feature was introduced in GitLab 14.10. Deletes an existing agent registration.'
tags %w[cluster_agents]
2022-06-21 17:19:12 +05:30
end
params do
requires :agent_id, type: Integer, desc: 'The ID of an agent'
end
delete ':id/cluster_agents/:agent_id' do
authorize! :admin_cluster, user_project
2022-07-23 23:45:48 +05:30
agent = ::Clusters::AgentsFinder.new(user_project, current_user).find(params[:agent_id])
2022-06-21 17:19:12 +05:30
destroy_conditionally!(agent)
end
end
end
end
end