Class: Gitlab::Ci::Components::InstancePath

Inherits:
Object
  • Object
show all
Includes:
LoopHelpers, Utils::StrongMemoize
Defined in:
lib/gitlab/ci/components/instance_path.rb

Constant Summary collapse

SHORTHAND_SEMVER_PATTERN =
/^\d+(\.\d+)?$/
LATEST =
'~latest'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LoopHelpers

#loop_until

Constructor Details

#initialize(address:) ⇒ InstancePath

Returns a new instance of InstancePath.



23
24
25
# File 'lib/gitlab/ci/components/instance_path.rb', line 23

def initialize(address:)
  @full_path, @reference = address.to_s.split('@', 2)
end

Instance Attribute Details

#component_nameObject (readonly)

Returns the value of attribute component_name.



10
11
12
# File 'lib/gitlab/ci/components/instance_path.rb', line 10

def component_name
  @component_name
end

#referenceObject (readonly)

Returns the value of attribute reference.



10
11
12
# File 'lib/gitlab/ci/components/instance_path.rb', line 10

def reference
  @reference
end

Class Method Details

.fqdn_prefixObject



19
20
21
# File 'lib/gitlab/ci/components/instance_path.rb', line 19

def self.fqdn_prefix
  "#{Gitlab.config.gitlab.server_fqdn}/"
end

.match?(address) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/gitlab/ci/components/instance_path.rb', line 15

def self.match?(address)
  address.include?('@') && address.start_with?(fqdn_prefix)
end

Instance Method Details

#fetch_content!(current_user:) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/gitlab/ci/components/instance_path.rb', line 27

def fetch_content!(current_user:)
  return unless project
  return unless sha

  raise Gitlab::Access::AccessDeniedError unless Ability.allowed?(current_user, :download_code, project)

  component_project = ::Ci::Catalog::ComponentsProject.new(project, sha)
  component_project.fetch_component(component_name)
end

#invalid_usage_for_latest?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/gitlab/ci/components/instance_path.rb', line 54

def invalid_usage_for_latest?
  reference == LATEST && project && project.catalog_resource.nil?
end

#invalid_usage_for_partial_semver?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/gitlab/ci/components/instance_path.rb', line 58

def invalid_usage_for_partial_semver?
  reference.match?(SHORTHAND_SEMVER_PATTERN) && project && project.catalog_resource.nil?
end

#matched_versionObject



49
50
51
# File 'lib/gitlab/ci/components/instance_path.rb', line 49

def matched_version
  find_catalog_version&.semver&.to_s
end

#projectObject



37
38
39
# File 'lib/gitlab/ci/components/instance_path.rb', line 37

def project
  find_project_by_component_path(instance_path)
end

#shaObject



42
43
44
45
46
# File 'lib/gitlab/ci/components/instance_path.rb', line 42

def sha
  return unless project

  find_version_sha
end