forked from sous-chefs/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_registry.rb
40 lines (31 loc) · 1.07 KB
/
docker_registry.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module DockerCookbook
class DockerRegistry < DockerBase
resource_name :docker_registry
property :email, String
property :password, String,
sensitive: true
property :serveraddress, String,
name_property: true
property :username, String
action :login do
tries = new_resource.api_retries
registry_host = parse_registry_host(new_resource.serveraddress)
(node.run_state['docker_auth'] ||= {})[registry_host] = {
'serveraddress' => registry_host,
'username' => new_resource.username,
'password' => new_resource.password,
'email' => new_resource.email,
}
begin
Docker.connection.post(
'/auth', {},
body: node.run_state['docker_auth'][registry_host].to_json
)
rescue Docker::Error::ServerError, Docker::Error::UnauthorizedError
raise Docker::Error::AuthenticationError, "#{new_resource.username} failed to authenticate with #{new_resource.serveraddress}" if (tries -= 1) == 0
retry
end
true
end
end
end