Sha256: 4f12a175bcdac82d134e758fa17abdd5cb52a7ab97099c9b0fb50d59c7d62ed3

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module DockerCookbook
  class DockerRegistry < DockerBase
    require 'docker'
    require_relative 'helpers_auth'

    resource_name :docker_registry

    property :email, [String, nil]
    property :password, [String, nil]
    property :serveraddress, [String, nil], name_property: true
    property :username, [String, nil]

    action :login do
      tries = api_retries

      registry_host = parse_registry_host(serveraddress)

      (node.run_state['docker_auth'] ||= {})[registry_host] = {
        'serveraddress' => registry_host,
        'username' => username,
        'password' => password,
        'email' => email
      }

      begin
        Docker.connection.post(
          '/auth', {},
          body: node.run_state['docker_auth'][registry_host].to_json
        )
      rescue Docker::Error::ServerError, Docker::Error::UnauthorizedError
        if (tries -= 1).zero?
          raise Docker::Error::AuthenticationError, "#{username} failed to authenticate with #{serveraddress}"
        else
          retry
        end
      end

      true
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chef-12.8.1 acceptance/top-cookbooks/test_run/docker/libraries/docker_registry.rb
chef-12.8.1-universal-mingw32 acceptance/top-cookbooks/test_run/docker/libraries/docker_registry.rb