docker-template 0.20.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c619f82805d6347fc614a212828d5bcb1b185783171a771c2720c9f277c175a
4
- data.tar.gz: d1dc93f95b9f840b82e5d4d29017d7b681660a1f3921626d128f140508676c21
3
+ metadata.gz: deedf46a1eaad06ea4d15d5b8aaa64e18bed91ac1fe60e24ddb7ed2e1a007326
4
+ data.tar.gz: a8d61651f99f6cb7796003a615d0ad03f75bc0f29a0eb33d1c47a322b244d1cf
5
5
  SHA512:
6
- metadata.gz: 10fa2829cfb98fb41a19dfbd92ef71926024c4e0e3bee74d2950823e7cd397e8fcca4728d56e0b1bec89a37b1a2951f573329ebe513646d267c290d5d0e01570
7
- data.tar.gz: 97c360cb05d1356f81189bc226228fb57d0f16e946f84b886c16b8e6dec78d410253a39289d03a29511ff10e89adbdb3a67bffaa2e786610ee1497d9a77e964a
6
+ metadata.gz: bfca0f56abefaf977c4afb325e1b372de5a73392063f53b7a5d8244263b7bbdfe1c09ba2faa7d76f21811e4ec70f336478ea78db2d3e6dc45e990dc57481ffc4
7
+ data.tar.gz: 56234609946129e0de47d3dd7607d1b38e4efaab8313e7da31d168ae9ee42da3699276bfbe4bf7446c6ca4fd9fb1c116e64dce0898807e6616c328ac2a40e157
@@ -2,16 +2,20 @@
2
2
  # Copyright: 2015 - 2016 Jordon Bedwell - Apache v2.0 License
3
3
  # Encoding: utf-8
4
4
 
5
+ require "open3"
6
+ require "json"
7
+
5
8
  module Docker
6
9
  module Template
7
- module Auth
8
- module_function
9
-
10
- # --
11
-
10
+ class Auth
12
11
  DEFAULT_SERVER = "https://index.docker.io/v1/"
12
+ def initialize(repo)
13
+ @repo = repo
14
+ end
13
15
 
14
- # --
16
+ def auth_with_cmd?
17
+ @repo.user =~ %r!/!
18
+ end
15
19
 
16
20
  def auth_with_env?
17
21
  ENV.key?("DOCKER_USERNAME") && \
@@ -20,17 +24,29 @@ module Docker
20
24
  end
21
25
 
22
26
  # --
23
-
24
- def hub
25
- return auth_from_env if auth_with_env?
26
-
27
+ def auth(skip: nil)
28
+ return auth_from_cmd if auth_with_cmd? && skip != :cmd
29
+ return auth_from_env if auth_with_env? && skip != :env
27
30
  auth_from_config
31
+
32
+ # Wrap around their error to create ours.
28
33
  rescue Docker::Error::AuthenticationError
29
34
  raise Error::UnsuccessfulAuth
35
+ # Something went wrong?
30
36
  end
31
37
 
32
38
  # --
39
+ def auth_from_cmd
40
+ case @repo.user
41
+ when %r!^gcr\.io/! then auth_from_gcr
42
+ else
43
+ auth({
44
+ skip: :cmd
45
+ })
46
+ end
47
+ end
33
48
 
49
+ # --
34
50
  def auth_from_env
35
51
  Docker.authenticate!({
36
52
  "username" => ENV["DOCKER_USERNAME"],
@@ -41,25 +57,43 @@ module Docker
41
57
  end
42
58
 
43
59
  # --
44
-
45
60
  def auth_from_config
46
- credentials = Pathutil.new("~/.docker/config.json")
47
- credentials = credentials.expand_path.read_json
61
+ cred = Pathutil.new("~/.docker/config.json")
62
+ cred = cred.expand_path.read_json
48
63
 
49
- unless credentials.empty?
50
- credentials["auths"].each do |server, info|
51
- username, password = Base64.decode64(info["auth"])
52
- .split(":", 2)
64
+ unless cred.empty?
65
+ cred["auths"].each do |server, info|
66
+ next if info.empty?
53
67
 
68
+ user, pass = Base64.decode64(info["auth"]).split(":", 2)
54
69
  Docker.authenticate!({
55
- "username" => username,
70
+ "username" => user,
56
71
  "serveraddress" => server,
57
72
  "email" => info["email"],
58
- "password" => password
73
+ "password" => pass
59
74
  })
60
75
  end
61
76
  end
62
77
  end
78
+
79
+ private
80
+ def auth_from_gcr
81
+ i, o, e, = Open3.popen3("docker-credential-gcr get")
82
+ server, = @repo.user.split("/", 2)
83
+
84
+ i.puts server; i.close
85
+ val = JSON.parse(o.read.chomp)
86
+ [o, e].map(&:close)
87
+
88
+ if val
89
+ Docker.authenticate!({
90
+ "serveraddress" => server,
91
+ "username" => val["Username"],
92
+ "email" => "docker-template+opensource@envygeeks.io",
93
+ "password" => val["Secret"],
94
+ })
95
+ end
96
+ end
63
97
  end
64
98
  end
65
99
  end
@@ -81,7 +81,8 @@ module Docker
81
81
  def push
82
82
  return if rootfs? || !@repo.pushable?
83
83
 
84
- Notify.push(self); Auth.hub
84
+ Notify.push(self)
85
+ Auth.new(@repo).auth
85
86
  img = @img || Image.get(@repo.to_s)
86
87
  img.push nil, :repo_tag => @repo.to_s, \
87
88
  &Logger.new(repo).method(:api)
@@ -4,6 +4,6 @@
4
4
 
5
5
  module Docker
6
6
  module Template
7
- VERSION = "0.20.0"
7
+ VERSION = "0.21.0"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordon Bedwell