Class: Gitlab::Kas::Client
- Inherits:
-
Object
- Object
- Gitlab::Kas::Client
- Defined in:
- lib/gitlab/kas/client.rb
Constant Summary collapse
- TIMEOUT =
2.seconds.freeze
- JWT_AUDIENCE =
'gitlab-kas'
- STUB_CLASSES =
{ server_info: Gitlab::Agent::ServerInfo::Rpc::ServerInfo::Stub, agent_tracker: Gitlab::Agent::AgentTracker::Rpc::AgentTracker::Stub, configuration_project: Gitlab::Agent::ConfigurationProject::Rpc::ConfigurationProject::Stub, autoflow: Gitlab::Agent::AutoFlow::Rpc::AutoFlow::Stub, notifications: Gitlab::Agent::Notifications::Rpc::Notifications::Stub }.freeze
- ConfigurationError =
Class.new(StandardError)
Instance Method Summary collapse
- #get_connected_agents_by_agent_ids(agent_ids:) ⇒ Object
-
#get_server_info ⇒ Object
Return GitLab KAS server info This method only returns information about a single KAS server instance without taking into account that there are potentially multiple KAS replicas running, which may not have the same server info.
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #list_agent_config_files(project:) ⇒ Object
- #send_autoflow_event(project:, type:, id:, data:) ⇒ Object
- #send_git_push_event(project:) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
19 20 21 22 |
# File 'lib/gitlab/kas/client.rb', line 19 def initialize raise ConfigurationError, 'GitLab KAS is not enabled' unless Gitlab::Kas.enabled? raise ConfigurationError, 'KAS internal URL is not configured' unless Gitlab::Kas.internal_url.present? end |
Instance Method Details
#get_connected_agents_by_agent_ids(agent_ids:) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/gitlab/kas/client.rb', line 36 def get_connected_agents_by_agent_ids(agent_ids:) request = Gitlab::Agent::AgentTracker::Rpc::GetConnectedAgentsByAgentIDsRequest.new(agent_ids: agent_ids) stub_for(:agent_tracker) .get_connected_agents_by_agent_i_ds(request, metadata: ) .agents .to_a end |
#get_server_info ⇒ Object
Return GitLab KAS server info This method only returns information about a single KAS server instance without taking into account that there are potentially multiple KAS replicas running, which may not have the same server info. This is particularly the case during a rollout.
28 29 30 31 32 33 34 |
# File 'lib/gitlab/kas/client.rb', line 28 def get_server_info request = Gitlab::Agent::ServerInfo::Rpc::GetServerInfoRequest.new stub_for(:server_info) .get_server_info(request, metadata: ) .current_server_info end |
#list_agent_config_files(project:) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gitlab/kas/client.rb', line 45 def list_agent_config_files(project:) request = Gitlab::Agent::ConfigurationProject::Rpc::ListAgentConfigFilesRequest.new( repository: repository(project), gitaly_info: gitaly_info(project) ) stub_for(:configuration_project) .list_agent_config_files(request, metadata: ) .config_files .to_a end |
#send_autoflow_event(project:, type:, id:, data:) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gitlab/kas/client.rb', line 71 def send_autoflow_event(project:, type:, id:, data:) # We only want to send events if AutoFlow is enabled and no-op otherwise return unless Feature.enabled?(:autoflow_enabled, project) project_proto = Gitlab::Agent::Event::Project.new( id: project.id, full_path: project.full_path ) request = Gitlab::Agent::AutoFlow::Rpc::CloudEventRequest.new( event: Gitlab::Agent::Event::CloudEvent.new( id: id, source: "GitLab", spec_version: "v1", type: type, attributes: { datacontenttype: Gitlab::Agent::Event::CloudEvent::CloudEventAttributeValue.new( ce_string: "application/json" ) }, text_data: data.to_json ), flow_project: project_proto ) stub_for(:autoflow) .cloud_event(request, metadata: ) end |
#send_git_push_event(project:) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gitlab/kas/client.rb', line 57 def send_git_push_event(project:) request = Gitlab::Agent::Notifications::Rpc::GitPushEventRequest.new( event: Gitlab::Agent::Event::GitPushEvent.new( project: Gitlab::Agent::Event::Project.new( id: project.id, full_path: project.full_path ) ) ) stub_for(:notifications) .git_push_event(request, metadata: ) end |