Class: UffizziCore::ContainerRegistryService
- Inherits:
-
Object
- Object
- UffizziCore::ContainerRegistryService
- Defined in:
- app/services/uffizzi_core/container_registry_service.rb
Instance Attribute Summary collapse
-
#container_data ⇒ Object
Returns the value of attribute container_data.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .additional_sources ⇒ Object
- .docker_registry?(container) ⇒ Boolean
- .init_by_container(container, credentials) ⇒ Object
- .init_by_credentials(container, credentials) ⇒ Object
- .init_by_subclass(credential_type) ⇒ Object
- .sources ⇒ Object
Instance Method Summary collapse
- #credential(credentials_scope) ⇒ Object
- #credential_correct?(credential) ⇒ Boolean
- #digest(credential, image, tag) ⇒ Object
- #image_available?(credentials_scope) ⇒ Boolean
- #image_data ⇒ Object
- #image_name(credentials) ⇒ Object
-
#initialize(type, container_data = {}) ⇒ ContainerRegistryService
constructor
A new instance of ContainerRegistryService.
- #repo_type ⇒ Object
- #service ⇒ Object
Constructor Details
#initialize(type, container_data = {}) ⇒ ContainerRegistryService
Returns a new instance of ContainerRegistryService.
49 50 51 52 53 54 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 49 def initialize(type, container_data = {}) @type = type @container_data = container_data raise ::UffizziCore::RegistryNotSupportedError unless self.class.sources.include?(type) end |
Instance Attribute Details
#container_data ⇒ Object
Returns the value of attribute container_data.
4 5 6 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 4 def container_data @container_data end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 4 def type @type end |
Class Method Details
.additional_sources ⇒ Object
44 45 46 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 44 def additional_sources [] end |
.docker_registry?(container) ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 29 def docker_registry?(container) registry_url = container.dig(:image, :registry_url) return false if registry_url.nil? registry_domain_regexp = /(\w+\.\w{2,})(?::\d+)?\z/ registry_domain = registry_url.match(registry_domain_regexp)&.to_a&.last return false if registry_domain.nil? ['amazonaws.com', 'azurecr.io', 'gcr.io', 'ghcr.io'].exclude?(registry_domain) end |
.init_by_container(container, credentials) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 12 def init_by_container(container, credentials) registry_url = container.dig(:image, :registry_url) return new(:docker_hub, container) if registry_url.include?('docker.io') return new(:azure, container) if registry_url.include?('azurecr.io') return new(:google, container) if registry_url.include?('gcr.io') return init_by_credentials(container, credentials) if registry_url.include?('amazonaws.com') return new(:github_container_registry, container) if registry_url.include?('ghcr.io') return new(:docker_registry, container) if docker_registry?(container) end |
.init_by_credentials(container, credentials) ⇒ Object
23 24 25 26 27 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 23 def init_by_credentials(container, credentials) return new(:docker_registry, container) if credentials && credentials.docker_registry.where(username: 'AWS').exists? new(:amazon, container) end |
.init_by_subclass(credential_type) ⇒ Object
7 8 9 10 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 7 def init_by_subclass(credential_type) type = credential_type.demodulize.underscore new(type.to_sym) end |
.sources ⇒ Object
40 41 42 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 40 def sources [:azure, :google, :amazon, :github_container_registry, :docker_registry, :docker_hub, *additional_sources] end |
Instance Method Details
#credential(credentials_scope) ⇒ Object
90 91 92 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 90 def credential(credentials_scope) credentials_scope.send(type).first end |
#credential_correct?(credential) ⇒ Boolean
68 69 70 71 72 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 68 def credential_correct?(credential) service.credential_correct?(credential) rescue URI::InvalidURIError, Faraday::ConnectionFailed, UffizziCore::ContainerRegistryError false end |
#digest(credential, image, tag) ⇒ Object
56 57 58 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 56 def digest(credential, image, tag) service.digest(credential, image, tag) end |
#image_available?(credentials_scope) ⇒ Boolean
94 95 96 97 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 94 def image_available?(credentials_scope) credential = credential(credentials_scope) service.image_available?(credential, image_data) end |
#image_data ⇒ Object
74 75 76 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 74 def image_data @image_data ||= container_data[:image] end |
#image_name(credentials) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 78 def image_name(credentials) if image_data[:registry_url].present? && [:google, :github_container_registry, :docker_registry, :docker_hub].exclude?(type) return image_data[:name] end if type == :docker_registry && credential(credentials).nil? return [image_data[:registry_url], image_data[:namespace], image_data[:name]].compact.join('/') end "#{image_data[:namespace]}/#{image_data[:name]}" end |
#repo_type ⇒ Object
64 65 66 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 64 def repo_type @repo_type ||= "UffizziCore::Repo::#{type.to_s.camelize}".safe_constantize end |
#service ⇒ Object
60 61 62 |
# File 'app/services/uffizzi_core/container_registry_service.rb', line 60 def service @service ||= "UffizziCore::ContainerRegistry::#{type.to_s.camelize}Service".safe_constantize end |