Welcome to mirror list, hosted at ThFree Co, Russian Federation.

authorize_job_artifact_service.rb « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 893e92d427c7d6ff69bb845319a898f19c96f4bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

module Ci
  class AuthorizeJobArtifactService
    include Gitlab::Utils::StrongMemoize

    # Max size of the zipped LSIF artifact
    LSIF_ARTIFACT_MAX_SIZE = 20.megabytes
    LSIF_ARTIFACT_TYPE = 'lsif'

    def initialize(job, params, max_size:)
      @job = job
      @max_size = max_size
      @size = params[:filesize]
      @type = params[:artifact_type].to_s
    end

    def forbidden?
      lsif? && !code_navigation_enabled?
    end

    def too_large?
      size && max_size <= size.to_i
    end

    def headers
      default_headers = JobArtifactUploader.workhorse_authorize(has_length: false, maximum_size: max_size)
      default_headers.tap do |h|
        h[:ProcessLsif] = true if lsif? && code_navigation_enabled?
      end
    end

    private

    attr_reader :job, :size, :type

    def code_navigation_enabled?
      strong_memoize(:code_navigation_enabled) do
        Feature.enabled?(:code_navigation, job.project, default_enabled: true)
      end
    end

    def lsif?
      strong_memoize(:lsif) do
        type == LSIF_ARTIFACT_TYPE
      end
    end

    def max_size
      lsif? ? LSIF_ARTIFACT_MAX_SIZE : @max_size.to_i
    end
  end
end