Module: Dapp::Dimg::DockerRegistry

Defined in:
lib/dapp/dimg/docker_registry.rb,
lib/dapp/dimg/docker_registry/base.rb,
lib/dapp/dimg/docker_registry/dimg.rb,
lib/dapp/dimg/docker_registry/error.rb,
lib/dapp/dimg/docker_registry/default.rb,
lib/dapp/dimg/docker_registry/base/request.rb,
lib/dapp/dimg/docker_registry/base/authorization.rb

Defined Under Namespace

Modules: Error Classes: Base, Default, Dimg

Class Method Summary collapse

Class Method Details

.hostname_exist?(url) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/dapp/dimg/docker_registry.rb', line 30

def self.hostname_exist?(url)
  return false unless url
  Base.url_available?(url)
end

.new(repo) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dapp/dimg/docker_registry.rb', line 4

def self.new(repo)
  /^#{repo_name_format}$/ =~ repo
  expected_hostname = Regexp.last_match(:hostname)
  expected_repo_suffix = Regexp.last_match(:repo_suffix)

  if expected_hostname
    %w(https http).each do |protocol|
      expected_hostname_url = [protocol, expected_hostname].join('://')
      return Dimg.new(repo, expected_hostname_url, expected_repo_suffix) if hostname_exist?(expected_hostname_url)
    end
    raise ::Dapp::Dimg::Error::Registry, code: :registry_not_available, data: { registry: repo }
  else
    Default.new(repo, expected_repo_suffix)
  end
end

.repo_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/dapp/dimg/docker_registry.rb', line 26

def self.repo_name?(name)
  !(/^#{repo_name_format}$/ =~ name).nil?
end

.repo_name_formatObject



20
21
22
23
24
# File 'lib/dapp/dimg/docker_registry.rb', line 20

def self.repo_name_format
  rpart = '[a-z0-9]+(([_.]|__|-+)[a-z0-9]+)*'
  hpart = '(?!-)[a-z0-9-]+(?<!-)'
  "(?<hostname>#{hpart}(\\.#{hpart})*(?<port>:[0-9]+)?\/)?(?<repo_suffix>#{rpart}(\/#{rpart})*)"
end