Class: Clusters::ParseClusterApplicationsArtifactService

Inherits:
BaseService
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/clusters/parse_cluster_applications_artifact_service.rb

Constant Summary collapse

MAX_ACCEPTABLE_ARTIFACT_SIZE =
5.kilobytes
RELEASE_NAMES =
%w[cilium].freeze

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(job, current_user) ⇒ ParseClusterApplicationsArtifactService

Returns a new instance of ParseClusterApplicationsArtifactService.


10
11
12
13
14
# File 'app/services/clusters/parse_cluster_applications_artifact_service.rb', line 10

def initialize(job, current_user)
  @job = job

  super(job.project, current_user)
end

Instance Method Details

#execute(artifact) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/clusters/parse_cluster_applications_artifact_service.rb', line 16

def execute(artifact)
  raise ArgumentError, 'Artifact is not cluster_applications file type' unless artifact&.cluster_applications?

  return error(too_big_error_message, :bad_request) unless artifact.file.size < MAX_ACCEPTABLE_ARTIFACT_SIZE
  return error(no_deployment_message, :bad_request) unless job.deployment
  return error(no_deployment_cluster_message, :bad_request) unless cluster

  parse!(artifact)

  success
rescue Gitlab::Kubernetes::Helm::Parsers::ListV2::ParserError, ActiveRecord::RecordInvalid => error
  Gitlab::ErrorTracking.track_exception(error, job_id: artifact.job_id)
  error(error.message, :bad_request)
end