docker_registry 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7439300efc7edd3b93e2d83594f5979e00cfc39d
4
+ data.tar.gz: fb498efb326bb95029371566eda4f227e0c0443c
5
+ SHA512:
6
+ metadata.gz: 93955e9aa6139230448b3e331b344ed7c120f4784eff6bdaf4c7d82fb398a508aca4b9e4838b35bddcc3b28a1f80b7d319804d3d5060fcb15b54d63c10dd18a0
7
+ data.tar.gz: bff00e32972fa2056d4dd9d9a6c4fe784dde9051680056b5369f0036630390124e5b9bf91d8f879fc8d8730a608c723dd599a195944f2aaf61bcc704e60eb462
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Style/Documentation:
2
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docker_registry.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sho Kusano
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # DockerRegistry
2
+
3
+ Docker registry HTTP API client
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'docker_registry'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install docker_registry
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ registry = DockerRegistry::Registry.new("https://index.docker.io")
25
+ registry.search("dockerfile/ruby")
26
+ # =>
27
+ # [
28
+ # #<DockerRegistry::Repository ... >,
29
+ # #<DockerRegistry::Repository ... >,
30
+ # #<DockerRegistry::Repository ... >
31
+ # ...
32
+ # ]
33
+
34
+ repository = client.all[0]
35
+ repository.tags
36
+ # =>
37
+ # [
38
+ # #<DockerRegistry::Tag ... >,
39
+ # #<DockerRegistry::Tag ... >,
40
+ # #<DockerRegistry::Tag ... >
41
+ # ...
42
+ # ]
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/docker_registry/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'docker_registry/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'docker_registry'
8
+ spec.version = DockerRegistry::VERSION
9
+ spec.authors = ['Sho Kusano']
10
+ spec.email = ['rosylilly@aduca.org']
11
+ spec.summary = 'Docker registry HTTP API client'
12
+ spec.description = 'Docker registry HTTP API client'
13
+ spec.homepage = 'https://github.com/rosylilly/docker_registry'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rubocop', '>= 0.26.0'
24
+
25
+ spec.add_dependency 'faraday'
26
+ spec.add_dependency 'faraday_middleware'
27
+ spec.add_dependency 'oj'
28
+ end
@@ -0,0 +1,50 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'docker_registry'
4
+ require 'docker_registry/oj_parser'
5
+
6
+ class DockerRegistry::Client
7
+ # @param [#to_s] base_uri Docker registry base URI
8
+ # @param [Hash] options Client options
9
+ # @option options [#to_s] :user User name for basic authentication
10
+ # @option options [#to_s] :password Password for basic authentication
11
+ def initialize(base_uri, options = {})
12
+ @base_uri = base_uri.to_s
13
+ @faraday = Faraday.new(@base_uri) do |builder|
14
+ builder.request :json
15
+ builder.use DockerRegistry::OjParser, content_type: /\bjson$/
16
+
17
+ if options[:user] && options[:password]
18
+ builder.request(
19
+ :basic_auth,
20
+ options[:user].to_s, options[:password].to_s
21
+ )
22
+ end
23
+
24
+ builder.adapter :net_http
25
+ end
26
+ end
27
+
28
+ def ping
29
+ @faraday.get('/v1/_ping').body === true
30
+ end
31
+
32
+ # @param [#to_s] query Seach query
33
+ def search(query = '')
34
+ @faraday.get('/v1/search', { q: query }).body
35
+ end
36
+
37
+ def repositry_tags(name)
38
+ @faraday.get("/v1/repositories/#{name}/tags").body
39
+ end
40
+
41
+ def delete_repository(name)
42
+ @faraday.delete("/v1/repositories/#{name}/").status == 200
43
+ end
44
+
45
+ def delete_reporitory_tag(repository_name, tag_name)
46
+ @faraday\
47
+ .delete("/v1/repositories/#{repository_name}/tags/#{tag_name}")\
48
+ .status == 200
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ require 'faraday_middleware/response_middleware'
2
+ require 'docker_registry'
3
+
4
+ module DockerRegistry
5
+ class OjParser < FaradayMiddleware::ResponseMiddleware
6
+ dependency do
7
+ require 'oj' unless defined?(::Oj)
8
+ end
9
+
10
+ define_parser do |body|
11
+ ::Oj.load(body) unless body.strip.empty?
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ require 'uri'
2
+ require 'docker_registry'
3
+ require 'docker_registry/client'
4
+ require 'docker_registry/repository'
5
+ require 'docker_registry/tag'
6
+
7
+ class DockerRegistry::Registry
8
+ attr_reader :base_uri, :options, :client
9
+
10
+ # @see DockerRegistry::Client#initialize
11
+ def initialize(uri)
12
+ @uri = URI.parse(uri)
13
+ @client = DockerRegistry::Client.new(
14
+ "#{@uri.scheme}://#{@uri.host}:#{@uri.port}",
15
+ user: @uri.user,
16
+ password: @uri.password
17
+ )
18
+ end
19
+
20
+ def domain
21
+ @domain ||= URI.parse(@base_uri).host
22
+ end
23
+
24
+ def ping
25
+ @client.ping
26
+ end
27
+
28
+ def all
29
+ search
30
+ end
31
+
32
+ def search(query = '')
33
+ (@client.search(query)['results'] || []).map do |repo|
34
+ DockerRegistry::Repository.new(repo, self)
35
+ end
36
+ end
37
+
38
+ def repositry_tags(repository)
39
+ (@client.repositry_tags(repository.name) || {}).map do |name, image_id|
40
+ DockerRegistry::Tag.new(name, image_id, repository)
41
+ end
42
+ end
43
+
44
+ def delete_repository(repository)
45
+ @client.delete_repository(repository.name)
46
+ end
47
+
48
+ def delete_reporitory_tag(tag)
49
+ @client.delete_reporitory_tag(tag.repository.name, tag.name)
50
+ end
51
+ end
@@ -0,0 +1,30 @@
1
+ require 'docker_registry'
2
+
3
+ class DockerRegistry::Repository
4
+ attr_reader :name, :metadata, :registry
5
+
6
+ def initialize(metadata, registry)
7
+ @metadata = {}
8
+ metadata.each_pair do |key, val|
9
+ @metadata[key.to_sym] = val
10
+ end
11
+ @name = @metadata[:name]
12
+ @registry = registry
13
+ end
14
+
15
+ def full_name
16
+ "#{registry.domain}/#{name}"
17
+ end
18
+
19
+ def tags
20
+ registry.repositry_tags(self)
21
+ end
22
+
23
+ def delete!
24
+ registry.delete_repository(self)
25
+ end
26
+
27
+ def inspect
28
+ "#<DockerRegistry::Repository #{full_name} >"
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ require 'docker_registry'
2
+
3
+ class DockerRegistry::Tag
4
+ attr_reader :name, :image_id, :repository
5
+
6
+ def initialize(name, image_id, repository)
7
+ @name = name
8
+ @image_id = image_id
9
+ @repository = repository
10
+ end
11
+
12
+ def registry
13
+ @repository.registry
14
+ end
15
+
16
+ def delete!
17
+ registry.delete_reporitory_tag(self)
18
+ end
19
+
20
+ def inspect
21
+ "#<DockerRegistry::Tag #{@repository.full_name}:#{name} >"
22
+ end
23
+ end
24
+
@@ -0,0 +1,3 @@
1
+ module DockerRegistry
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'docker_registry/version'
2
+ require 'docker_registry/registry'
3
+ require 'docker_registry/repository'
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docker_registry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sho Kusano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.26.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.26.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: oj
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Docker registry HTTP API client
98
+ email:
99
+ - rosylilly@aduca.org
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - docker_registry.gemspec
111
+ - lib/docker_registry.rb
112
+ - lib/docker_registry/client.rb
113
+ - lib/docker_registry/oj_parser.rb
114
+ - lib/docker_registry/registry.rb
115
+ - lib/docker_registry/repository.rb
116
+ - lib/docker_registry/tag.rb
117
+ - lib/docker_registry/version.rb
118
+ homepage: https://github.com/rosylilly/docker_registry
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Docker registry HTTP API client
142
+ test_files: []