Class: Gitlab::Ci::Config::External::File::Component

Inherits:
Base
  • Object
show all
Extended by:
Utils::Override
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/config/external/file/component.rb

Constant Summary

Constants inherited from Base

Base::YAML_ALLOWLIST_EXTENSION

Instance Attribute Summary

Attributes inherited from Base

#context, #errors, #location, #params

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods inherited from Base

#eql?, #error_message, #hash, #invalid_extension?, #invalid_location_type?, #load_and_validate_expanded_hash!, #matching?, #preload_content, #preload_context, #to_hash, #valid?

Constructor Details

#initialize(params, context) ⇒ Component

Returns a new instance of Component.



12
13
14
15
16
# File 'lib/gitlab/ci/config/external/file/component.rb', line 12

def initialize(params, context)
  @location = params[:component]

  super
end

Instance Method Details

#contentObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/ci/config/external/file/component.rb', line 18

def content
  return unless component_result.success?

  if context.user.present?
    ::Gitlab::UsageDataCounters::HLLRedisCounter.track_event(
      'cicd_component_usage',
      values: context.user.id
    )
  end

  component_payload.fetch(:content)
end

#metadataObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gitlab/ci/config/external/file/component.rb', line 32

def 
  super.merge(
    type: :component,
    location: masked_location,
    blob: masked_blob,
    raw: nil,
    extra: {},
    component: component_attrs # never expose this data in the response
    # see https://gitlab.com/gitlab-org/gitlab/-/issues/455376
    # and https://gitlab.com/gitlab-org/gitlab/-/issues/453955
  )
end

#validate_content!Object



57
58
59
# File 'lib/gitlab/ci/config/external/file/component.rb', line 57

def validate_content!
  errors.push(component_result.message) unless content.present?
end

#validate_context!Object



51
52
53
54
55
# File 'lib/gitlab/ci/config/external/file/component.rb', line 51

def validate_context!
  return if context.project&.repository

  errors.push('Unable to use components outside of a project context')
end

#validate_location!Object



45
46
47
48
49
# File 'lib/gitlab/ci/config/external/file/component.rb', line 45

def validate_location!
  return unless invalid_location_type?

  errors.push("Included file `#{masked_location}` needs to be a string")
end