Class: ContainerRegistry::Tag
- Inherits:
-
Object
- Object
- ContainerRegistry::Tag
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- lib/container_registry/tag.rb
Instance Attribute Summary collapse
- #created_at ⇒ Object
-
#manifest_digest ⇒ Object
writeonly
Sets the attribute manifest_digest.
-
#media_type ⇒ Object
Returns the value of attribute media_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#published_at ⇒ Object
Returns the value of attribute published_at.
-
#referrers ⇒ Object
Returns the value of attribute referrers.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
- #revision ⇒ Object
- #total_size ⇒ Object
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #config ⇒ Object
- #config_blob ⇒ Object
- #digest ⇒ Object
-
#force_created_at_from_iso8601(string_value) ⇒ Object
this function will set and memoize a created_at to avoid a #config_blob call.
-
#initialize(repository, name, from_api: false) ⇒ Tag
constructor
A new instance of Tag.
- #latest? ⇒ Boolean
- #layers ⇒ Object
- #location ⇒ Object
- #manifest ⇒ Object
- #path ⇒ Object
- #protected_for_delete?(user) ⇒ Boolean
- #protection_rule ⇒ Object
- #put(digests) ⇒ Object
- #short_revision ⇒ Object
-
#unsafe_delete ⇒ Object
Deletes the image associated with this tag Note this will delete the image and all tags associated with it.
- #v1? ⇒ Boolean
- #v2? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(repository, name, from_api: false) ⇒ Tag
Returns a new instance of Tag.
14 15 16 17 18 |
# File 'lib/container_registry/tag.rb', line 14 def initialize(repository, name, from_api: false) @repository = repository @name = name @from_api = from_api end |
Instance Attribute Details
#created_at ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/container_registry/tag.rb', line 92 def created_at return @created_at if @created_at strong_memoize(:memoized_created_at) do next unless config DateTime.rfc3339(config['created']) rescue ArgumentError nil end end |
#manifest_digest=(value) ⇒ Object (writeonly)
Sets the attribute manifest_digest
8 9 10 |
# File 'lib/container_registry/tag.rb', line 8 def manifest_digest=(value) @manifest_digest = value end |
#media_type ⇒ Object
Returns the value of attribute media_type.
9 10 11 |
# File 'lib/container_registry/tag.rb', line 9 def media_type @media_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/container_registry/tag.rb', line 7 def name @name end |
#published_at ⇒ Object
Returns the value of attribute published_at.
7 8 9 |
# File 'lib/container_registry/tag.rb', line 7 def published_at @published_at end |
#referrers ⇒ Object
Returns the value of attribute referrers.
7 8 9 |
# File 'lib/container_registry/tag.rb', line 7 def referrers @referrers end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
7 8 9 |
# File 'lib/container_registry/tag.rb', line 7 def repository @repository end |
#revision ⇒ Object
24 25 26 |
# File 'lib/container_registry/tag.rb', line 24 def revision @revision || config_blob&.revision end |
#total_size ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/container_registry/tag.rb', line 139 def total_size return @total_size if @total_size return unless layers layers.sum(&:size) if v2? end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
7 8 9 |
# File 'lib/container_registry/tag.rb', line 7 def updated_at @updated_at end |
Instance Method Details
#[](key) ⇒ Object
64 65 66 67 68 |
# File 'lib/container_registry/tag.rb', line 64 def [](key) return unless manifest manifest[key] end |
#config ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/container_registry/tag.rb', line 84 def config return if config_blob&.data.blank? strong_memoize(:config) do ContainerRegistry::Config.new(self, config_blob) end end |
#config_blob ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/container_registry/tag.rb', line 76 def config_blob return unless manifest && manifest['config'] strong_memoize(:config_blob) do repository.blob(manifest['config']) end end |
#digest ⇒ Object
70 71 72 73 74 |
# File 'lib/container_registry/tag.rb', line 70 def digest strong_memoize(:digest) do @manifest_digest || client.repository_tag_digest(repository.path, name) end end |
#force_created_at_from_iso8601(string_value) ⇒ Object
this function will set and memoize a created_at to avoid a #config_blob call.
106 107 108 109 |
# File 'lib/container_registry/tag.rb', line 106 def force_created_at_from_iso8601(string_value) date = parse_iso8601_string(string_value) instance_variable_set(ivar(:memoized_created_at), date) end |
#latest? ⇒ Boolean
38 39 40 |
# File 'lib/container_registry/tag.rb', line 38 def latest? name == "latest" end |
#layers ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/container_registry/tag.rb', line 123 def layers return unless manifest strong_memoize(:layers) do layers = manifest['layers'] || manifest['fsLayers'] layers.map do |layer| repository.blob(layer) end end end |
#location ⇒ Object
60 61 62 |
# File 'lib/container_registry/tag.rb', line 60 def location "#{repository.location}:#{name}" end |
#manifest ⇒ Object
50 51 52 53 54 |
# File 'lib/container_registry/tag.rb', line 50 def manifest strong_memoize(:manifest) do client.repository_manifest(repository.path, name) end end |
#path ⇒ Object
56 57 58 |
# File 'lib/container_registry/tag.rb', line 56 def path "#{repository.path}:#{name}" end |
#protected_for_delete?(user) ⇒ Boolean
169 170 171 172 173 174 175 176 |
# File 'lib/container_registry/tag.rb', line 169 def protected_for_delete?(user) return true unless user return false unless protection_rule return false if user.can_admin_all_resources? max_access = project.team.max_member_access(user.id) protection_rule.delete_restricted?(max_access) end |
#protection_rule ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/container_registry/tag.rb', line 156 def protection_rule result = nil project.container_registry_protection_tag_rules.select(&:mutable?).each do |rule| next unless rule.matches_tag_name?(name) result ||= ::ContainerRegistry::Protection::TagRule.new set_highest_protection_rule_access_level(result, rule) end result end |
#put(digests) ⇒ Object
135 136 137 |
# File 'lib/container_registry/tag.rb', line 135 def put(digests) repository.client.put_tag(repository.path, name, digests) end |
#short_revision ⇒ Object
28 29 30 31 32 |
# File 'lib/container_registry/tag.rb', line 28 def short_revision return unless revision revision[0..8] end |
#unsafe_delete ⇒ Object
Deletes the image associated with this tag Note this will delete the image and all tags associated with it. Consider using DeleteTagsService instead.
150 151 152 153 154 |
# File 'lib/container_registry/tag.rb', line 150 def unsafe_delete return unless digest client.delete_repository_tag_by_digest(repository.path, digest) end |
#v1? ⇒ Boolean
42 43 44 |
# File 'lib/container_registry/tag.rb', line 42 def v1? manifest && manifest['schemaVersion'] == 1 end |
#v2? ⇒ Boolean
46 47 48 |
# File 'lib/container_registry/tag.rb', line 46 def v2? manifest && manifest['schemaVersion'] == 2 end |
#valid? ⇒ Boolean
34 35 36 |
# File 'lib/container_registry/tag.rb', line 34 def valid? from_api? || manifest.present? end |