Module: Docker::Template::Auth
- Defined in:
- lib/docker/template/auth.rb
Constant Summary collapse
- DEFAULT_SERVER =
–
"https://index.docker.io/v1/"
Class Method Summary collapse
-
.auth_from_config ⇒ Object
–.
-
.auth_from_env ⇒ Object
–.
-
.auth_with_env? ⇒ Boolean
–.
-
.hub ⇒ Object
–.
Class Method Details
.auth_from_config ⇒ Object
–
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/docker/template/auth.rb', line 52 def auth_from_config credentials = Pathutil.new("~/.docker/config.json") credentials = credentials..read_json unless credentials.empty? credentials["auths"].each do |server, info| username, password = Base64.decode64(info["auth"]) .split(":", 2) Docker.authenticate!({ "username" => username, "serveraddress" => server, "email" => info["email"], "password" => password }) end end end |
.auth_from_env ⇒ Object
–
41 42 43 44 45 46 47 48 |
# File 'lib/docker/template/auth.rb', line 41 def auth_from_env Docker.authenticate!({ "username" => ENV["DOCKER_USERNAME"] || ENV["bamboo_dockerUsername"], "serveraddress" => ENV["DOCKER_SERVER"] || ENV["bamboo_dockerServer"] || DEFAULT_SERVER, "password" => ENV["DOCKER_PASSWORD"] || ENV["bamboo_dockerPassword"], "email" => ENV["DOCKER_EMAIL"] || ENV["bamboo_dockerEmail"] }) end |
.auth_with_env? ⇒ Boolean
–
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/docker/template/auth.rb', line 16 def auth_with_env? ( ENV.key?("DOCKER_USERNAME") && \ ENV.key?("DOCKER_PASSWORD") && \ ENV.key?("DOCKER_EMAIL") ) || \ ( ENV.key?("bamboo_dockerUsername") && \ ENV.key?("bamboo_dockerPassword") && \ ENV.key?("bambo_dockerEmail") ) end |
.hub ⇒ Object
–
31 32 33 34 35 36 37 |
# File 'lib/docker/template/auth.rb', line 31 def hub return auth_from_env if auth_with_env? auth_from_config rescue Docker::Error::AuthenticationError raise Error::UnsuccessfulAuth end |