Skip to content
Snippets Groups Projects

Receptive cluster agents

Closed Tiger Watson requested to merge receptive-cluster-agents into master
5 files
+ 320
0
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 94
0
# frozen_string_literal: true
module API
module Clusters
class AgentUrlConfigurations < ::API::Base
before do
authenticate!
not_found! unless Feature.enabled?(:cluster_agent_incoming_connections, user_project)
end
feature_category :deployment_management
params do
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
params do
requires :agent_id, type: Integer, desc: 'The ID of an agent'
end
resource ':id/cluster_agents/:agent_id' do
resource :url_configurations do
desc 'Get a single agent url configuration' do
detail 'This feature was introduced in GitLab 17.4. Gets a single agent url configuration.'
success Entities::Clusters::AgentUrlConfiguration
tags %w[cluster_agents]
end
params do
requires :url_configuration_id, type: Integer, desc: 'The ID of the agent url configuration'
end
get ':url_configuration_id' do
authorize! :admin_cluster, user_project
url_cfg = ::Clusters::Agents::UrlConfiguration.find_by_id(params[:url_configuration_id])
not_found! unless url_cfg
present url_cfg, with: Entities::Clusters::AgentUrlConfiguration
end
desc 'Create an agent url configuration for a receptive agent' do
detail 'This feature was introduced in GitLab 17.4. ' \
'Creates a new url configuration for a receptive agent.'
success Entities::Clusters::AgentUrlConfiguration
tags %w[cluster_agents]
end
params do
requires :url, type: String, desc: 'The url where the receptive agent is listening'
end
post do
authorize! :create_cluster, user_project
agent = ::Clusters::AgentsFinder.new(user_project, current_user).find(params[:agent_id])
url_cfg_params = declared_params(include_missing: false)
result = ::Clusters::Agents::CreateUrlConfigurationService.new(
agent: agent,
current_user: current_user,
params: url_cfg_params
).execute
bad_request!(result[:message]) if result[:status] == :error
present result[:url_configuration], with: Entities::Clusters::AgentUrlConfiguration
end
desc 'Delete an agent url configuration' do
detail 'This feature was introduced in GitLab 17.4. Deletes an agent url configuration.'
tags %w[cluster_agents]
end
params do
requires :url_configuration_id, type: Integer, desc: 'The ID of the agent url configuration'
end
delete ':url_configuration_id' do
authorize! :admin_cluster, user_project
agent = ::Clusters::AgentsFinder.new(user_project, current_user).find(params[:agent_id])
url_cfg = ::Clusters::Agents::UrlConfiguration.find_by_id(params[:url_configuration_id])
not_found! unless url_cfg
destroy_conditionally!(url_cfg) do |url_cfg|
::Clusters::Agents::DeleteUrlConfigurationService
.new(agent: agent, current_user: current_user, url_configuration: url_cfg)
.execute
end
end
end
end
end
end
end
end
Loading