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_WHITELIST_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
# File 'lib/gitlab/ci/config/external/file/component.rb', line 18

def content
  return unless component_result.success?

  ::Gitlab::UsageDataCounters::HLLRedisCounter.track_event('cicd_component_usage', values: context.user.id)

  component_result.payload.fetch(:content)
end

#metadataObject



27
28
29
30
31
32
33
34
35
# File 'lib/gitlab/ci/config/external/file/component.rb', line 27

def 
  super.merge(
    type: :component,
    location: masked_location,
    blob: masked_blob,
    raw: nil,
    extra: {}
  )
end

#validate_content!Object



49
50
51
# File 'lib/gitlab/ci/config/external/file/component.rb', line 49

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

#validate_context!Object



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

def validate_context!
  return if context.project&.repository

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

#validate_location!Object



37
38
39
40
41
# File 'lib/gitlab/ci/config/external/file/component.rb', line 37

def validate_location!
  return unless invalid_location_type?

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