Class: Ci::CreateJobArtifactsService

Inherits:
BaseService show all
Defined in:
app/services/ci/create_job_artifacts_service.rb

Constant Summary collapse

ArtifactsExistError =
Class.new(StandardError)
LSIF_ARTIFACT_TYPE =
'lsif'
OBJECT_STORAGE_ERRORS =
[
  Errno::EIO,
  Google::Apis::ServerError,
  Signet::RemoteServerError
].freeze

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params

Instance Method Summary collapse

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) ⇒ CreateJobArtifactsService

Returns a new instance of CreateJobArtifactsService.


15
16
17
18
# File 'app/services/ci/create_job_artifacts_service.rb', line 15

def initialize(job)
  @job = job
  @project = job.project
end

Instance Method Details

#authorize(artifact_type:, filesize: nil) ⇒ Object


20
21
22
23
24
25
26
27
28
# File 'app/services/ci/create_job_artifacts_service.rb', line 20

def authorize(artifact_type:, filesize: nil)
  result = validate_requirements(artifact_type: artifact_type, filesize: filesize)
  return result unless result[:status] == :success

  headers = JobArtifactUploader.workhorse_authorize(has_length: false, maximum_size: max_size(artifact_type))
  headers[:ProcessLsif] = lsif?(artifact_type)

  success(headers: headers)
end

#execute(artifacts_file, params, metadata_file: nil) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/ci/create_job_artifacts_service.rb', line 30

def execute(artifacts_file, params, metadata_file: nil)
  result = validate_requirements(artifact_type: params[:artifact_type], filesize: artifacts_file.size)
  return result unless result[:status] == :success

  return success if sha256_matches_existing_artifact?(params[:artifact_type], artifacts_file)

  artifact,  = build_artifact(artifacts_file, params, )
  result = parse_artifact(artifact)

  return result unless result[:status] == :success

  persist_artifact(artifact, , params)
end