hyperb 0.2.1 → 0.2.2
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 +4 -4
- data/.codeclimate.yml +12 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +41 -0
- data/Dockerfile +7 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +21 -0
- data/Makefile +16 -0
- data/README.md +188 -0
- data/Rakefile +24 -0
- data/circle.yml +13 -0
- data/examples/README.md +367 -0
- data/examples/auth-gcr-registry.md +19 -0
- data/examples/compose.md +75 -0
- data/examples/handling-errors.md +54 -0
- data/examples/streaming-logs.md +28 -0
- data/examples/streaming-stats.md +25 -0
- data/hyperb.gemspec +30 -0
- data/lib/hyperb.rb +4 -0
- data/lib/hyperb/api.rb +22 -0
- data/lib/hyperb/auth_object.rb +42 -0
- data/lib/hyperb/client.rb +32 -0
- data/lib/hyperb/compose/compose.rb +116 -0
- data/lib/hyperb/containers/container.rb +27 -0
- data/lib/hyperb/containers/containers.rb +251 -0
- data/lib/hyperb/error.rb +44 -0
- data/lib/hyperb/hyper_version.rb +12 -0
- data/lib/hyperb/images/image.rb +13 -0
- data/lib/hyperb/images/images.rb +108 -0
- data/lib/hyperb/network/fips.rb +102 -0
- data/lib/hyperb/request.rb +129 -0
- data/lib/hyperb/services/services.rb +59 -0
- data/lib/hyperb/snapshots/snapshot.rb +12 -0
- data/lib/hyperb/snapshots/snapshots.rb +39 -0
- data/lib/hyperb/utils.rb +39 -0
- data/lib/hyperb/version.rb +3 -0
- data/lib/hyperb/volumes/volume.rb +16 -0
- data/lib/hyperb/volumes/volumes.rb +67 -0
- data/spec/auth_object_spec.rb +45 -0
- data/spec/client_spec.rb +27 -0
- data/spec/compose_spec.rb +145 -0
- data/spec/container_spec.rb +25 -0
- data/spec/containers_spec.rb +442 -0
- data/spec/create_snapshot.rb +30 -0
- data/spec/error_spec.rb +18 -0
- data/spec/fixtures/auth_obj.json +12 -0
- data/spec/fixtures/compose_rm.json +1 -0
- data/spec/fixtures/compose_up.json +1 -0
- data/spec/fixtures/container_stats.json +78 -0
- data/spec/fixtures/containers.json +160 -0
- data/spec/fixtures/create_container.json +4 -0
- data/spec/fixtures/create_image.json +1 -0
- data/spec/fixtures/create_service.json +35 -0
- data/spec/fixtures/create_snapshot.json +8 -0
- data/spec/fixtures/fip_allocate.json +7 -0
- data/spec/fixtures/fips_ls.json +14 -0
- data/spec/fixtures/images.json +32 -0
- data/spec/fixtures/inspect_container.json +159 -0
- data/spec/fixtures/inspect_image.json +89 -0
- data/spec/fixtures/inspect_volume.json +11 -0
- data/spec/fixtures/remove_container.json +1 -0
- data/spec/fixtures/remove_image.json +5 -0
- data/spec/fixtures/volumes.json +13 -0
- data/spec/helper.rb +36 -0
- data/spec/image_spec.rb +17 -0
- data/spec/images_spec.rb +133 -0
- data/spec/network_spec.rb +106 -0
- data/spec/request_spec.rb +41 -0
- data/spec/services_spec.rb +193 -0
- data/spec/version_spec.rb +7 -0
- data/spec/volumes_spec.rb +88 -0
- metadata +74 -3
@@ -0,0 +1,89 @@
|
|
1
|
+
{
|
2
|
+
"Id" : "85f05633ddc1c50679be2b16a0479ab6f7637f8884e0cfe0f4d20e1ebb3d6e7c",
|
3
|
+
"Container" : "cb91e48a60d01f1e27028b4fc6819f4f290b3cf12496c8176ec714d0d390984a",
|
4
|
+
"Comment" : "",
|
5
|
+
"Os" : "linux",
|
6
|
+
"Architecture" : "amd64",
|
7
|
+
"Parent" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c",
|
8
|
+
"ContainerConfig" : {
|
9
|
+
"Tty" : false,
|
10
|
+
"Hostname" : "e611e15f9c9d",
|
11
|
+
"Volumes" : null,
|
12
|
+
"Domainname" : "",
|
13
|
+
"AttachStdout" : false,
|
14
|
+
"PublishService" : "",
|
15
|
+
"AttachStdin" : false,
|
16
|
+
"OpenStdin" : false,
|
17
|
+
"StdinOnce" : false,
|
18
|
+
"NetworkDisabled" : false,
|
19
|
+
"OnBuild" : [],
|
20
|
+
"Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c",
|
21
|
+
"User" : "",
|
22
|
+
"WorkingDir" : "",
|
23
|
+
"Entrypoint" : null,
|
24
|
+
"MacAddress" : "",
|
25
|
+
"AttachStderr" : false,
|
26
|
+
"Labels" : {
|
27
|
+
"com.example.license" : "GPL",
|
28
|
+
"com.example.version" : "1.0",
|
29
|
+
"com.example.vendor" : "Acme"
|
30
|
+
},
|
31
|
+
"Env" : [
|
32
|
+
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
33
|
+
],
|
34
|
+
"ExposedPorts" : null,
|
35
|
+
"Cmd" : [
|
36
|
+
"/bin/sh",
|
37
|
+
"-c",
|
38
|
+
"#(nop) LABEL com.example.vendor=Acme com.example.license=GPL com.example.version=1.0"
|
39
|
+
]
|
40
|
+
},
|
41
|
+
"DockerVersion" : "1.9.0-dev",
|
42
|
+
"VirtualSize" : 188359297,
|
43
|
+
"Size" : 0,
|
44
|
+
"Author" : "",
|
45
|
+
"Created" : "2015-09-10T08:30:53.26995814Z",
|
46
|
+
"GraphDriver" : {
|
47
|
+
"Name" : "aufs",
|
48
|
+
"Data" : null
|
49
|
+
},
|
50
|
+
"RepoDigests" : [
|
51
|
+
"localhost:5000/test/busybox/example@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"
|
52
|
+
],
|
53
|
+
"RepoTags" : [
|
54
|
+
"example:1.0",
|
55
|
+
"example:latest",
|
56
|
+
"example:stable"
|
57
|
+
],
|
58
|
+
"Config" : {
|
59
|
+
"Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c",
|
60
|
+
"NetworkDisabled" : false,
|
61
|
+
"OnBuild" : [],
|
62
|
+
"StdinOnce" : false,
|
63
|
+
"PublishService" : "",
|
64
|
+
"AttachStdin" : false,
|
65
|
+
"OpenStdin" : false,
|
66
|
+
"Domainname" : "",
|
67
|
+
"AttachStdout" : false,
|
68
|
+
"Tty" : false,
|
69
|
+
"Hostname" : "e611e15f9c9d",
|
70
|
+
"Volumes" : null,
|
71
|
+
"Cmd" : [
|
72
|
+
"/bin/bash"
|
73
|
+
],
|
74
|
+
"ExposedPorts" : null,
|
75
|
+
"Env" : [
|
76
|
+
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
77
|
+
],
|
78
|
+
"Labels" : {
|
79
|
+
"com.example.vendor" : "Acme",
|
80
|
+
"com.example.version" : "1.0",
|
81
|
+
"com.example.license" : "GPL"
|
82
|
+
},
|
83
|
+
"Entrypoint" : null,
|
84
|
+
"MacAddress" : "",
|
85
|
+
"AttachStderr" : false,
|
86
|
+
"WorkingDir" : "",
|
87
|
+
"User" : ""
|
88
|
+
}
|
89
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
[]
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
Coveralls.wear!
|
5
|
+
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
|
6
|
+
|
7
|
+
SimpleCov.start do
|
8
|
+
add_filter '/spec/'
|
9
|
+
minimum_coverage(95.5)
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'hyperb'
|
13
|
+
require 'bundler/setup'
|
14
|
+
require 'webmock/rspec'
|
15
|
+
|
16
|
+
WebMock.disable_net_connect!(allow: 'coveralls.io')
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
# Enable flags like --only-failures and --next-failure
|
20
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
21
|
+
|
22
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
23
|
+
config.disable_monkey_patching!
|
24
|
+
|
25
|
+
config.expect_with :rspec do |c|
|
26
|
+
c.syntax = :expect
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def fixture_path
|
31
|
+
File.expand_path('../fixtures', __FILE__)
|
32
|
+
end
|
33
|
+
|
34
|
+
def fixture(file)
|
35
|
+
File.new(fixture_path + '/' + file)
|
36
|
+
end
|
data/spec/image_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
RSpec.describe Hyperb::Image do
|
4
|
+
|
5
|
+
describe '#created' do
|
6
|
+
|
7
|
+
it 'returns timestamp when created is set' do
|
8
|
+
image = Hyperb::Image.new(id: 1, created: 1420064636)
|
9
|
+
expect(image.created).to be_a Fixnum
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns nil when created is not set' do
|
13
|
+
image = Hyperb::Image.new(id: 1)
|
14
|
+
expect(image.created).to be_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/images_spec.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'http'
|
3
|
+
|
4
|
+
RSpec.describe Hyperb::Images do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@client = Hyperb::Client.new(access_key: 'key', secret_key: '123')
|
8
|
+
@images_path = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/images/json?all=true'
|
9
|
+
@create_image_path = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/images/create?fromImage=busybox'
|
10
|
+
@remove_image_path = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/images/busybox'
|
11
|
+
@inspect_image_path = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/images/busybox/json'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#images' do
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_request(:get, @images_path)
|
18
|
+
.to_return(body: fixture('images.json'))
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'request to the correct path should be made, all=true by default' do
|
22
|
+
@client.images
|
23
|
+
expect(a_request(:get, @images_path)).to have_been_made
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'request to the correct path should be made with filter=name' do
|
27
|
+
stub_request(:get, @images_path + '&filter=busybox')
|
28
|
+
.to_return(body: fixture('images.json'))
|
29
|
+
|
30
|
+
@client.images(filter: 'busybox')
|
31
|
+
expect(a_request(:get, @images_path + '&filter=busybox')).to have_been_made
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'return array of images' do
|
35
|
+
images = @client.images
|
36
|
+
expect(images).to be_a Array
|
37
|
+
expect(images[0]).to be_a Hyperb::Image
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'correct attrs' do
|
41
|
+
@client.images.each do |img|
|
42
|
+
expect(img.id).to be_a String
|
43
|
+
expect(img.created).to be_a Fixnum
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#create_image' do
|
50
|
+
|
51
|
+
before do
|
52
|
+
stub_request(:post, @create_image_path)
|
53
|
+
.to_return(body: fixture('create_image.json'))
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'request to the correct path should be made' do
|
57
|
+
@client.create_image from_image: 'busybox'
|
58
|
+
expect(a_request(:post, @create_image_path)).to have_been_made
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should raise ArgumentError if argument missing' do
|
62
|
+
expect { @client.create_image wrong_arg: 'busybox' }.to raise_error(ArgumentError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'return http:response' do
|
66
|
+
res = @client.create_image from_image: 'busybox'
|
67
|
+
expect(res).to be_a HTTP::Response::Body
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'create image with auth_object' do
|
71
|
+
p = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/images/create?fromImage=gcr.io/private/custom_busybox'
|
72
|
+
stub_request(:post, p)
|
73
|
+
.to_return(body: fixture('create_image.json'))
|
74
|
+
|
75
|
+
x_registry_auth = { username: 'test', password: fixture('auth_obj.json'), email: 'test@t.com' }
|
76
|
+
@client.create_image from_image: 'gcr.io/private/custom_busybox', x_registry_auth: x_registry_auth
|
77
|
+
|
78
|
+
expect(a_request(:post, p)).to have_been_made
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#remove_image' do
|
84
|
+
|
85
|
+
before do
|
86
|
+
stub_request(:delete, @remove_image_path)
|
87
|
+
.to_return(body: fixture('remove_image.json'))
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'request to the correct path should be made' do
|
91
|
+
@client.remove_image name: 'busybox'
|
92
|
+
expect(a_request(:delete, @remove_image_path)).to have_been_made
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'request to the correct path should be made with force=true' do
|
96
|
+
stub_request(:delete, @remove_image_path + '?force=true')
|
97
|
+
.to_return(body: fixture('remove_image.json'))
|
98
|
+
|
99
|
+
@client.remove_image(name: 'busybox', force: true)
|
100
|
+
expect(a_request(:delete, @remove_image_path + '?force=true')).to have_been_made
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'return an array of symbolized hashes' do
|
104
|
+
res = @client.remove_image(name: 'busybox')
|
105
|
+
expect(res).to be_a Array
|
106
|
+
res.each do |r|
|
107
|
+
r.keys.each { |k| expect(k).to be_a(Symbol) }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#inspect_image' do
|
113
|
+
|
114
|
+
before do
|
115
|
+
stub_request(:get, @inspect_image_path)
|
116
|
+
.to_return(body: fixture('inspect_image.json'))
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'request to the correct path should be made' do
|
120
|
+
@client.inspect_image name: 'busybox'
|
121
|
+
expect(a_request(:get, @inspect_image_path)).to have_been_made
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'return a hash with symbolized attrs' do
|
125
|
+
res = @client.inspect_image(name: 'busybox')
|
126
|
+
expect(res).to be_a Hash
|
127
|
+
expect(res.has_key?(:id)).to be true
|
128
|
+
expect(res.has_key?(:container)).to be true
|
129
|
+
expect(res.has_key?(:comment)).to be true
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
RSpec.describe Hyperb::Network do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Hyperb::Client.new(access_key: 'key', secret_key: '123')
|
7
|
+
@base_path = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/fips'
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#fip_allocate' do
|
11
|
+
|
12
|
+
it 'should raise ArgumentError when count is not provided' do
|
13
|
+
expect { @client.fip_allocate }.to raise_error(ArgumentError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'request to the correct path should be made' do
|
17
|
+
path = @base_path + '/allocate?count=1'
|
18
|
+
stub_request(:post, path)
|
19
|
+
.to_return(body: fixture('fip_allocate.json'))
|
20
|
+
|
21
|
+
@client.fip_allocate count: 1
|
22
|
+
expect(a_request(:post, path)).to have_been_made
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#fip_attach' do
|
27
|
+
|
28
|
+
it 'should raise ArgumentError when container is not provided' do
|
29
|
+
expect { @client.fip_attach }.to raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should raise ArgumentError when ip is not provided' do
|
33
|
+
expect { @client.fip_attach }.to raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should raise ArgumentError when container and ip are not provided' do
|
37
|
+
expect { @client.fip_attach }.to raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'request to the correct path should be made' do
|
41
|
+
path = @base_path + '/attach?container=nginx&ip=8.8.8.8'
|
42
|
+
stub_request(:post, path)
|
43
|
+
.to_return(body: "")
|
44
|
+
|
45
|
+
@client.fip_attach ip: '8.8.8.8', container: 'nginx'
|
46
|
+
expect(a_request(:post, path)).to have_been_made
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#fip_detach' do
|
51
|
+
|
52
|
+
it 'should raise ArgumentError when container is not provided' do
|
53
|
+
expect { @client.fip_detach }.to raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'request to the correct path should be made' do
|
57
|
+
path = @base_path + '/detach?container=nginx'
|
58
|
+
stub_request(:post, path)
|
59
|
+
.to_return(body: "")
|
60
|
+
|
61
|
+
@client.fip_detach container: 'nginx'
|
62
|
+
expect(a_request(:post, path)).to have_been_made
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#fips_ls' do
|
67
|
+
|
68
|
+
it 'request to the correct path should be made' do
|
69
|
+
path = @base_path
|
70
|
+
stub_request(:get, path)
|
71
|
+
.to_return(body: fixture('fips_ls.json'))
|
72
|
+
|
73
|
+
@client.fips_ls
|
74
|
+
expect(a_request(:get, path)).to have_been_made
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should return correct attrs' do
|
78
|
+
path = @base_path
|
79
|
+
stub_request(:get, path)
|
80
|
+
.to_return(body: fixture('fips_ls.json'))
|
81
|
+
|
82
|
+
fips = @client.fips_ls
|
83
|
+
expect(fips).to be_a Array
|
84
|
+
expect(fips.first.key?(:container)).to be true
|
85
|
+
expect(fips.first.key?(:service)).to be true
|
86
|
+
expect(fips.first.key?(:fip)).to be true
|
87
|
+
expect(fips.first.key?(:name)).to be true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#fip_release' do
|
92
|
+
|
93
|
+
it 'should raise ArgumentError when ip is not provided' do
|
94
|
+
expect { @client.fip_allocate }.to raise_error(ArgumentError)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'request to the correct path should be made' do
|
98
|
+
path = @base_path + '/release?ip=8.8.8.8'
|
99
|
+
stub_request(:post, path)
|
100
|
+
.to_return(body: "")
|
101
|
+
|
102
|
+
@client.fip_release ip: '8.8.8.8'
|
103
|
+
expect(a_request(:post, path)).to have_been_made
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
RSpec.describe Hyperb::Request do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Hyperb::Client.new(access_key: 'ak', secret_key: 'sk')
|
7
|
+
end
|
8
|
+
|
9
|
+
it '#singed_headers without signature' do
|
10
|
+
req = Hyperb::Request.new(@client, '/', {}, 'get')
|
11
|
+
expect(req.signed_headers).to eql('content-type;host;x-hyper-content-sha256;x-hyper-date')
|
12
|
+
end
|
13
|
+
|
14
|
+
it '#singed_headers with signature' do
|
15
|
+
req = Hyperb::Request.new(@client, '/', {}, 'get')
|
16
|
+
req.sign
|
17
|
+
expect(req.signed_headers).to eql('authorization;content-type;host;x-hyper-content-sha256;x-hyper-date')
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#sign' do
|
21
|
+
req = Hyperb::Request.new(@client, '/', {}, 'get')
|
22
|
+
req.sign
|
23
|
+
expect(req.headers[:authorization]).not_to be nil
|
24
|
+
expect(req.signed).to be true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should merge optional headers' do
|
28
|
+
optional_headers = { x_header: 't' }
|
29
|
+
req = Hyperb::Request.new(@client, '/', {}, 'get', '', optional_headers)
|
30
|
+
expect(req.headers[:x_header]).not_to be nil
|
31
|
+
expect(req.headers[:x_header]).to eql('t')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should add optional header to SignedHeaders header' do
|
35
|
+
optional_headers = { x_header: 't' }
|
36
|
+
req = Hyperb::Request.new(@client, '/', {}, 'get', '', optional_headers)
|
37
|
+
req.sign
|
38
|
+
expect(req.signed_headers).to eql('authorization;content-type;host;x-header;x-hyper-content-sha256;x-hyper-date')
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|