image-inspector-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4da0318dd9b810deb0ddd7f19b91f4127f7864cc
4
+ data.tar.gz: b244d90435141d4c77526550c6580a77597de6cf
5
+ SHA512:
6
+ metadata.gz: 93e4ff76ac2adb2318267a037b018065ce9114037b4c4cda7d88e5795adcf4ab158e6d55b3ac21ab4bbdd12cb58988df0c619509c6344a7381f28bf251176a75
7
+ data.tar.gz: 6ce7a139bfb1c62d0490b376be2a4b1ea6e726ad903e297f88adec21bfcf11904df4e891618080a37240b5e8365ae5c85af6569eaaa6e49368ca3cc70bce98ec
data/.gitignore ADDED
@@ -0,0 +1,15 @@
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
15
+ *.idea*
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ ClassLength:
2
+ Enabled: false
3
+ MethodLength:
4
+ Enabled: false
5
+ Metrics/AbcSize:
6
+ Enabled: false
7
+ Metrics/LineLength:
8
+ Max: 100
9
+ Style/FileName:
10
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0"
4
+ - "2.1"
5
+ - "2.2"
6
+ sudo: false
7
+ cache: bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kubeclient.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Mooli Tayer
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,33 @@
1
+ # image-inspector-client
2
+ a ruby client for [image-inspector](https://github.com/simon3z/image-inspector)
3
+
4
+ ## installing gem
5
+ TBD
6
+
7
+ ## usage
8
+ ```ruby
9
+ require 'image-inspector-client'
10
+ ImageInspectorClient::Client.new('http://localhost:8080', 'v1')
11
+ .fetch_metadata
12
+ .ContainerConfig
13
+ .Cmd
14
+ ```
15
+
16
+ ## building from source
17
+ fetch dependencies:
18
+ ```
19
+ bundle install
20
+ ```
21
+ tests:
22
+ ```
23
+ rake test
24
+ ```
25
+ tests and style check:
26
+ ```
27
+ rake test rubocop
28
+ ```
29
+
30
+ build and install into $GEM_HOME:
31
+ ```
32
+ rake install
33
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
+
5
+ task default: [:test, :rubocop]
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ end
10
+
11
+ RuboCop::RakeTask.new
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'image-inspector-client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'image-inspector-client'
8
+ spec.version = ImageInspectorClient::VERSION
9
+ spec.authors = ['Mooli Tayer']
10
+ spec.email = ['mtayer@redhat.com']
11
+ spec.summary = 'A client for image_inspector REST API'
12
+ spec.description = 'A client for image_inspector REST API'
13
+ spec.homepage = 'https://github.com/moolitayer/image-inspector-client'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+ spec.required_ruby_version = '>= 2.0.0'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.6'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'minitest'
25
+ spec.add_development_dependency 'webmock'
26
+ spec.add_development_dependency 'rubocop', '= 0.30.0'
27
+
28
+ spec.add_dependency 'json'
29
+ spec.add_dependency 'recursive-open-struct', '= 0.6.1'
30
+ spec.add_dependency 'rest-client'
31
+ end
@@ -0,0 +1,91 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ require 'recursive_open_struct'
4
+
5
+ # Client for image inspector: https://github.com/simon3z/image-inspector
6
+ module ImageInspectorClient
7
+ # module entry point
8
+ class Client
9
+ def initialize(
10
+ uri,
11
+ version = 'v1',
12
+ ssl_options: {
13
+ client_cert: nil,
14
+ client_key: nil,
15
+ ca_file: nil,
16
+ cert_store: nil,
17
+ verify_ssl: OpenSSL::SSL::VERIFY_PEER
18
+ },
19
+ auth_options: {
20
+ username: nil,
21
+ password: nil,
22
+ bearer_token: nil
23
+ }
24
+ )
25
+ @endpoint = URI.parse("#{uri}/api/#{version}")
26
+ @auth_options = auth_options
27
+ @ssl_options = ssl_options
28
+ @headers = {}
29
+ end
30
+
31
+ def fetch_metadata
32
+ exception_handler do
33
+ RecursiveOpenStruct.new(
34
+ JSON.parse(
35
+ RestClient::Resource.new(@endpoint, http_options)['metadata'].get(http_headers)
36
+ )
37
+ )
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def exception_handler
44
+ yield
45
+ rescue RestClient::Exception => e
46
+ begin
47
+ json_error_msg = JSON.parse(e.response || '') || {}
48
+ rescue JSON::ParserError
49
+ json_error_msg = {}
50
+ end
51
+ err_message = json_error_msg['message'] || e.message
52
+ raise InspectorClientException.new(e.http_code, err_message)
53
+ end
54
+
55
+ def http_options
56
+ {
57
+ ssl_client_cert: @ssl_options[:client_cert],
58
+ ssl_client_key: @ssl_options[:client_key],
59
+ ssl_ca_file: @ssl_options[:ca_file],
60
+ ssl_cert_store: @ssl_options[:cert_store],
61
+ verify_ssl: @ssl_options[:verify_ssl],
62
+ user: @auth_options[:username],
63
+ password: @auth_options[:password]
64
+ }
65
+ end
66
+
67
+ def http_headers
68
+ if @auth_options[:bearer_token]
69
+ {
70
+ Authorization: "Bearer #{@auth_options[:bearer_token]}"
71
+ }
72
+ else
73
+ {}
74
+ end
75
+ end
76
+ end
77
+
78
+ # Exception thrown by this module
79
+ class InspectorClientException < StandardError
80
+ attr_reader :error_code, :message
81
+
82
+ def initialize(error_code, message)
83
+ @error_code = error_code
84
+ @message = message
85
+ end
86
+
87
+ def to_s
88
+ 'HTTP status code ' + @error_code.to_s + ', ' + @message
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,4 @@
1
+ # Client for image inspector: https://github.com/simon3z/image-inspector
2
+ module ImageInspectorClient
3
+ VERSION = '0.1.0'
4
+ end
data/test/common.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'minitest/autorun'
2
+ require 'webmock/minitest'
3
+ require 'json'
4
+ require 'image-inspector-client'
5
+
6
+ # Assumes test files will be in a subdirectory with the same name as the
7
+ # file suffix. e.g. a file named foo.json would be a "json" subdirectory.
8
+ def open_test_file(name)
9
+ File.new(File.join(File.dirname(__FILE__), name.split('.').last, name))
10
+ end
@@ -0,0 +1,27 @@
1
+ {
2
+ "Id": "85f4e2af80d39fccfa3abd218732bc4fc1711665527c5fdd556fb0ff9139c789",
3
+ "Parent": "48ecf305d2cf7046c1f5f8fcbcd4994403173441d4a7f125b1bb0ceead9de731",
4
+ "Created": "2015-10-13T23:39:52.388889568Z",
5
+ "Container": "6513026ba0de46b0ee484fa9e505bd8b6715df06bcc617fa70ac87defe0838b0",
6
+ "ContainerConfig": {
7
+ "Hostname": "6513026ba0de",
8
+ "Cmd": [
9
+ "/bin/sh",
10
+ "-c",
11
+ "#(nop) ADD file:3d655151e60ee9ae6490fe44ec7e42f0e0117f0cd6728fd5281299c01638a492 in /"
12
+ ],
13
+ "Image": "48ecf305d2cf7046c1f5f8fcbcd4994403173441d4a7f125b1bb0ceead9de731",
14
+ "Entrypoint": null
15
+ },
16
+ "DockerVersion": "1.8.2",
17
+ "Author": "Lokesh Mandvekar \u003clsm5@fedoraproject.org\u003e",
18
+ "Config": {
19
+ "Hostname": "6513026ba0de",
20
+ "Cmd": null,
21
+ "Image": "48ecf305d2cf7046c1f5f8fcbcd4994403173441d4a7f125b1bb0ceead9de731",
22
+ "Entrypoint": null
23
+ },
24
+ "Architecture": "amd64",
25
+ "Size": 186507296,
26
+ "VirtualSize": 186507296
27
+ }
@@ -0,0 +1,14 @@
1
+ require 'common'
2
+
3
+ # General client tests
4
+ class TestClient < MiniTest::Test
5
+ def test_unknown_host
6
+ stub_request(:get, %r{/metadata})
7
+ .to_return(status: 404)
8
+
9
+ assert_raises(ImageInspectorClient::InspectorClientException) do
10
+ ImageInspectorClient::Client.new('http://localhost:8080', 'v1')
11
+ .fetch_metadata
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require 'common'
2
+
3
+ # Tests for fetch_metadata call
4
+ class TestMetadata < MiniTest::Test
5
+ def test_metadata_v1
6
+ stub_request(:get, %r{/metadata}).to_return(
7
+ body: open_test_file('metadata.json'),
8
+ status: 200
9
+ )
10
+
11
+ md = ImageInspectorClient::Client.new('http://localhost:8080', 'v1')
12
+ .fetch_metadata
13
+
14
+ assert_instance_of(RecursiveOpenStruct, md)
15
+ assert_equal(md.Id, '85f4e2af80d39fccfa3abd218732bc4fc1711665527c5fdd556fb0ff9139c789')
16
+ assert_equal(md.DockerVersion, '1.8.2')
17
+ assert_equal(md.Architecture, 'amd64')
18
+ assert_equal(
19
+ md.ContainerConfig.Image,
20
+ '48ecf305d2cf7046c1f5f8fcbcd4994403173441d4a7f125b1bb0ceead9de731'
21
+ )
22
+
23
+ assert_requested(
24
+ :get,
25
+ 'http://localhost:8080/api/v1/metadata',
26
+ times: 1
27
+ )
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: image-inspector-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mooli Tayer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-08 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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.30.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.30.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
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
+ - !ruby/object:Gem::Dependency
98
+ name: recursive-open-struct
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.6.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.6.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rest-client
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A client for image_inspector REST API
126
+ email:
127
+ - mtayer@redhat.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rubocop.yml"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - image-inspector-client.gemspec
140
+ - lib/image-inspector-client.rb
141
+ - lib/image-inspector-client/version.rb
142
+ - test/common.rb
143
+ - test/json/metadata.json
144
+ - test/test_client.rb
145
+ - test/test_metadata.rb
146
+ homepage: https://github.com/moolitayer/image-inspector-client
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: 2.0.0
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.0
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: A client for image_inspector REST API
170
+ test_files:
171
+ - test/common.rb
172
+ - test/json/metadata.json
173
+ - test/test_client.rb
174
+ - test/test_metadata.rb