hyperb 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cfd1df42e8e7a70e5da8139a47a333c132f55ec
4
- data.tar.gz: 42211756c1e2fac4844f38b02f245f91f2a98ca5
3
+ metadata.gz: 30372b492d04628c4baaa53f4694439eb684ffb9
4
+ data.tar.gz: 6a8a68096e76d8d3c6becfceed11f5516b26f7dd
5
5
  SHA512:
6
- metadata.gz: 839af760aa8293c023623b92b475e975dbb436a195f90b1afd0ecc5efcdc717cffb25569e46be3d87fa08f842112a52d1fbf2bcb2037f46c609f5a53bbd7e233
7
- data.tar.gz: 8645b548c23c76ffe182e32ae77746ebfb10de08fa93a2c1319244152702553112518b0c6f372aba388eb3a90231dfc539126ff1deab6b6a8995d416220b18e1
6
+ metadata.gz: 866e805b09e1f788c3034dfe459685e11097cf47ab36bdbe7b85f6586e3fec5c88ac8937a6aa2283afcf2e2eb8276c271c59e3a821e817dc538847123c06b1de
7
+ data.tar.gz: 8211d6f878ccaec8df7a09d19139cd647b239f9c282d6571f5074a2484792ce78a04a6e04aa5ba3c3c9a8bc0fb0876b0b05d398367f3ca998829aa834cbf4094
data/Makefile CHANGED
@@ -1,8 +1,7 @@
1
1
  .PHONY: test
2
2
 
3
- b:
4
- docker run --rm -v $(PWD):/usr/src hyperb bundle exec ruby t.rb
5
-
3
+ t:
4
+ docker run --rm -v $(PWD):/usr/src hyperb bundle exec ruby test.rb
6
5
 
7
6
  build:
8
7
  docker build -t hyperb .
data/README.md CHANGED
@@ -164,9 +164,18 @@ For more usage examples, please see the full [documentation]().
164
164
  * inspect service
165
165
  * list services
166
166
 
167
+ ### Func (beta)
168
+
169
+ * create func
170
+ * remove func
171
+ * list funcs
172
+ * func status
173
+ * call func
174
+
167
175
  ### Misc.
168
176
 
169
- * Version
177
+ * version
178
+ * info
170
179
 
171
180
  ### Security Groups
172
181
 
@@ -176,10 +185,6 @@ wip
176
185
 
177
186
  wip
178
187
 
179
- ### Func (beta)
180
-
181
- wip
182
-
183
188
  ### Cron (beta)
184
189
 
185
190
  wip
@@ -407,6 +407,64 @@ Returns an Hash containing service fields
407
407
  client.inspect_service(name: 'srvc1')
408
408
  ```
409
409
 
410
+ ## [Funcs API](https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func)
411
+
412
+ #### [create_func](https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/create.html)
413
+
414
+ Return hash containing func information
415
+
416
+ ```ruby
417
+
418
+ func_config = {
419
+ name: "helloworld",
420
+ config: {
421
+ cmd: [
422
+ "echo",
423
+ "HelloWorld"
424
+ ],
425
+ image: "ubuntu"
426
+ }
427
+ }
428
+
429
+ func = client.create_func(func_config)
430
+ puts func
431
+ ```
432
+
433
+ #### [remove_func](https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/remove.html)
434
+
435
+ ```ruby
436
+ client.remove_func name: 'func1'
437
+ ```
438
+
439
+ #### [funcs](https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/list.html)
440
+
441
+ Returns an array of Hyperb::Func
442
+
443
+ ```ruby
444
+ funcs = client.funcs
445
+ funcs.is_a?(Array)
446
+
447
+ puts funcs.first.name
448
+ ```
449
+
450
+ #### [call_func](https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/call.html)
451
+
452
+ Returns a JSON response containing `CallId` or function return value
453
+
454
+ ```ruby
455
+ client.call_func(name: 'fn', uuid: 'uuid')
456
+ # {CallId: ""}
457
+
458
+ client.call_func(name: 'helloworld1', uuid: 'uuid', sync: true)
459
+ # HelloWorld
460
+ ```
461
+
462
+ #### [remove_func](https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/remove.html)
463
+
464
+ ```ruby
465
+ client.remove_func(name: 'fn')
466
+ ```
467
+
410
468
  ## Snapshot API
411
469
 
412
470
  Return hash containing snapshot information
@@ -1,4 +1,4 @@
1
1
  require 'hyperb/version'
2
2
  require 'hyperb/client'
3
3
  require 'hyperb/auth_object'
4
- require 'hyperb/hyper_version'
4
+ require 'hyperb/misc'
@@ -5,7 +5,8 @@ require 'hyperb/services/services'
5
5
  require 'hyperb/volumes/volumes'
6
6
  require 'hyperb/network/fips'
7
7
  require 'hyperb/compose/compose'
8
- require 'hyperb/hyper_version'
8
+ require 'hyperb/misc'
9
+ require 'hyperb/funcs/funcs'
9
10
 
10
11
  module Hyperb
11
12
  # wrapper for apis
@@ -13,10 +14,11 @@ module Hyperb
13
14
  include Hyperb::Images
14
15
  include Hyperb::Containers
15
16
  include Hyperb::Volumes
16
- include Hyperb::HyperVersion
17
+ include Hyperb::Misc
17
18
  include Hyperb::Network
18
19
  include Hyperb::Snapshots
19
20
  include Hyperb::Services
20
21
  include Hyperb::Compose
22
+ include Hyperb::Funcs
21
23
  end
22
24
  end
@@ -13,7 +13,7 @@ module Hyperb
13
13
  def initialize(params = {})
14
14
  params.each do |att, value|
15
15
  value = downcase_symbolize(value) if value.is_a?(Hash)
16
- instance_variable_set("@#{att.downcase.to_sym}", value)
16
+ instance_variable_set("@#{underscore(att)}", value)
17
17
  end
18
18
  end
19
19
 
@@ -0,0 +1,15 @@
1
+ module Hyperb
2
+ # func object
3
+ class Func
4
+ include Hyperb::Utils
5
+ attr_accessor :name, :container_size, :timeout, :uuid,
6
+ :created, :config, :host_config, :networking_config
7
+
8
+ def initialize(attrs = {})
9
+ attrs.each do |k, v|
10
+ v = downcase_symbolize(v) if v.is_a?(Hash)
11
+ instance_variable_set("@#{underscore(k)}", v)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,129 @@
1
+ require 'hyperb/request'
2
+ require 'hyperb/utils'
3
+ require 'hyperb/funcs/func'
4
+
5
+ module Hyperb
6
+ # funcs api wrapper
7
+ module Funcs
8
+ include Hyperb::Utils
9
+ # list funcs
10
+ #
11
+ # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/list.html
12
+ #
13
+ # @raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
14
+ # @raise [Hyperb::Error::InternalServerError] raised hyper servers return 5xx.
15
+ #
16
+ # @return [Hyperb::Func] Array of Funcs.
17
+ def funcs
18
+ path = '/funcs'
19
+ query = {}
20
+ response = JSON.parse(Hyperb::Request.new(self, path, query, 'get').perform)
21
+ response.map { |func| Hyperb::Func.new(func) }
22
+ end
23
+
24
+ # func status
25
+ #
26
+ # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/status.html
27
+ #
28
+ # @raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
29
+ # @raise [Hyperb::Error::InternalServerError] raised hyper servers return 5xx.
30
+ #
31
+ # @return [Hash] Array of Funcs.
32
+ #
33
+ # @param params [Hash] A customizable set of params.
34
+ #
35
+ # @param params :name [String] the function name.
36
+ # @param params :uuid [String] the function uuid.
37
+ def status_func(params = {})
38
+ raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name', 'uuid')
39
+ path = "status/#{params[:name]}/#{params[:uuid]}"
40
+ JSON.parse(Hyperb::FuncCallRequest.new(self, path, {}, 'get').perform)
41
+ end
42
+
43
+ # create a func
44
+ #
45
+ # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/create.html
46
+ #
47
+ # @raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
48
+ # @raise [Hyperb::Error::Conflict] raised when func already exist
49
+ # @raise [Hyperb::Error::BadRequest] raised when a bad parameter is sent
50
+ # @raise [Hyperb::Error::InternalServerError] server error on hyper side.
51
+ # @raise [ArgumentError] when required arguments are not provided.
52
+ #
53
+ # @param params [Hash] A customizable set of params.
54
+ #
55
+ # @param params :name [String] the function name.
56
+ #
57
+ # @param params :container_size [String] the size of containers
58
+ # to run the function (e.g. s1,s2, s3, s4, m1, m2, m3, l1, l2, l3)
59
+ #
60
+ # @param params :timeout [String] default is 300 seconds, maximum is 86400 seconds.
61
+ # @param params :uuid [String] The uuid of function.
62
+ #
63
+ # @param params :config [Hash] func configurations
64
+ # @param params config :tty [Boolean] attach streams to a tty
65
+ # @param params config :exposed_ports [Hash] an object mapping ports to an empty
66
+ # object in the form of: "ExposedPorts": { "<port>/<tcp|udp>: {}" }
67
+ # @param params config :env [Array] list of env vars, "VAR=VALUE"
68
+ # @param params config :cmd [Array|String] list of env vars, "VAR=VALUE"
69
+ # @param params config :image [String] image to run
70
+ # @param params config :entrypoint [String] entrypoint
71
+ # @param params config :working_dir [String] working directory
72
+ # @param params config :labels [Hash] labels
73
+ #
74
+ # @param params :host_config [Hash] func host configurations
75
+ # @param params host_config :links [Array] list of links
76
+ # @param params host_config :port_bindings [Hash]
77
+ # @param params host_config :publish_all_ports [Boolean]
78
+ # @param params host_config :volumes_from [Array]
79
+ # @param params host_config :network_mode [String]
80
+ def create_func(params = {})
81
+ raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
82
+ path = '/funcs/create'
83
+
84
+ body = {}
85
+ body.merge!(prepare_json(params))
86
+
87
+ Hyperb::Request.new(self, path, {}, 'post', body).perform
88
+ end
89
+
90
+ # remove a func
91
+ #
92
+ # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/remove.html
93
+ #
94
+ # @raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
95
+ # @raise [Hyperb::Error::Conflict] raised when func with that name is running
96
+ # @raise [Hyperb::Error::BadRequest] raised when a bad parameter is sent
97
+ # @raise [Hyperb::Error::InternalServerError] server error on hyper side.
98
+ # @raise [ArgumentError] when required arguments are not provided.
99
+ #
100
+ # @param params [Hash] A customizable set of params.
101
+ #
102
+ # @param params :name [String] the function name.
103
+ def remove_func(params = {})
104
+ raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name')
105
+ path = '/funcs/' + params[:name]
106
+ Hyperb::Request.new(self, path, {}, 'delete').perform
107
+ end
108
+
109
+ # call a func
110
+ #
111
+ # @see https://docs.hyper.sh/Reference/API/2016-04-04%20[Ver.%201.23]/Func/call.html
112
+ #
113
+ # @raise [Hyperb::Error::Unauthorized] raised when credentials are not valid.
114
+ # @raise [Hyperb::Error::NotFound] no such func
115
+ # @raise [ArgumentError] when required arguments are not provided.
116
+ #
117
+ # @param params [Hash] A customizable set of params.
118
+ #
119
+ # @param params :name [String] the function name.
120
+ # @param params :uuid [String] function uuid.
121
+ # @param params :sync [Boolean] block until function reply
122
+ def call_func(params = {})
123
+ raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name', 'uuid')
124
+ path = "call/#{params[:name]}/#{params[:uuid]}"
125
+ path.concat('/sync') if params.key?(:sync) && params[:sync]
126
+ Hyperb::FuncCallRequest.new(self, path, {}, 'post').perform
127
+ end
128
+ end
129
+ end
@@ -3,10 +3,15 @@ require 'json'
3
3
 
4
4
  module Hyperb
5
5
  # simple wrapper for the version endpoint
6
- module HyperVersion
6
+ module Misc
7
7
  # returns current version of hyper.sh api
8
8
  def version
9
9
  JSON.parse(Hyperb::Request.new(self, '/version', {}, 'get').perform)
10
10
  end
11
+
12
+ # returns system-wide information about user account
13
+ def info
14
+ JSON.parse(Hyperb::Request.new(self, '/info', {}, 'get').perform)
15
+ end
11
16
  end
12
17
  end
@@ -16,7 +16,7 @@ module Hyperb
16
16
  SERVICE = 'hyper'.freeze
17
17
  ALGORITHM = 'HYPER-HMAC-SHA256'.freeze
18
18
  KEYPARTS_REQUEST = 'hyper_request'.freeze
19
- BASE_URL = ('https://' + HOST + '/').freeze
19
+ BASE_URL = "https://#{HOST}/".freeze
20
20
 
21
21
  attr_accessor :verb, :path, :client, :date, :headers, :signed
22
22
 
@@ -126,4 +126,35 @@ module Hyperb
126
126
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, value)
127
127
  end
128
128
  end
129
+
130
+ # func requests are very simple, they do not require signing
131
+ class FuncCallRequest
132
+ REGION = 'us-west-1'.freeze
133
+ URL = "https://#{REGION}.hyperfunc.io/".freeze
134
+
135
+ attr_accessor :path, :query, :verb, :body, :headers
136
+
137
+ def initialize(client, path, query = {}, verb = 'GET', body = '')
138
+ @client = client
139
+ @path = path
140
+ @verb = verb
141
+ @query = URI.encode_www_form(query)
142
+ @body = body.empty? ? body : body.to_json
143
+ @headers = { content_type: 'application/json' }
144
+ end
145
+
146
+ def perform
147
+ final_url = URL + @path + '?' + @query
148
+ options = {}
149
+ options[:body] = @body unless @body.empty?
150
+ response = HTTP.headers(@headers).public_send(@verb.downcase.to_sym, final_url, options)
151
+ fail_or_return(response.code, response.body)
152
+ end
153
+
154
+ def fail_or_return(code, body)
155
+ error = Hyperb::Error::ERRORS[code]
156
+ raise(error.new(body, code)) if error
157
+ body
158
+ end
159
+ end
129
160
  end
@@ -21,15 +21,15 @@ module Hyperb
21
21
  contains
22
22
  end
23
23
 
24
- # hyper.sh responses are capital cased json
24
+ # hyper.sh responses are capital camel cased json, ie:
25
25
  #
26
- # {"Field": "value"}
26
+ # {"HostConfigs": "value"}
27
27
  #
28
- # this fn is used to symbolize and downcase all hyper.sh api reponses
28
+ # this fn is used to format all hyper.sh api reponses
29
29
  def downcase_symbolize(obj)
30
30
  if obj.is_a? Hash
31
31
  return obj.each_with_object({}) do |(k, v), memo|
32
- memo.tap { |m| m[k.downcase.to_sym] = downcase_symbolize(v) }
32
+ memo.tap { |m| m[underscore(k)] = downcase_symbolize(v) }
33
33
  end
34
34
  end
35
35
 
@@ -41,5 +41,34 @@ module Hyperb
41
41
  end
42
42
  obj
43
43
  end
44
+
45
+ # prepares all json payloads before sending to hyper
46
+ #
47
+ # input: { foo_bar: 'test' }
48
+ # output: {'FooBar': 'test' }
49
+ def prepare_json(params = {})
50
+ json = {}
51
+ params.each do |key, value|
52
+ value = prepare_json(value) if value.is_a?(Hash)
53
+ json[camelize(key)] = value
54
+ end
55
+ json
56
+ end
57
+
58
+ # based on http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore
59
+ #
60
+ # underscores and symbolize a string
61
+ # @param [String] word
62
+ # @returns [String]
63
+ def underscore(word)
64
+ word
65
+ .to_s
66
+ .gsub(/([A-Z]+)([A-Z]+)([A-Z][a-z])/, '\12_\3')
67
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
68
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
69
+ .tr('-', '_')
70
+ .downcase
71
+ .to_sym
72
+ end
44
73
  end
45
74
  end
@@ -1,3 +1,3 @@
1
1
  module Hyperb
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
@@ -116,8 +116,19 @@ RSpec.describe Hyperb::Containers do
116
116
  expect(res.has_key?(:args)).to be true
117
117
  expect(res.has_key?(:config)).to be true
118
118
  expect(res.has_key?(:created)).to be true
119
- end
119
+ expect(res.has_key?(:host_config)).to be true
120
+ expect(res.has_key?(:app_armor_profile)).to be true
121
+
122
+ expect(res[:host_config].has_key?(:publish_all_ports)).to be true
123
+ expect(res[:host_config].has_key?(:blkio_weight_device)).to be true
124
+ expect(res[:host_config].has_key?(:blkio_weight)).to be true
125
+ expect(res[:host_config].has_key?(:memory_reservation)).to be true
126
+ expect(res[:host_config].has_key?(:oom_kill_disable)).to be true
120
127
 
128
+ expect(res[:config].has_key?(:attach_stderr)).to be true
129
+ expect(res[:config].has_key?(:attach_stdin)).to be true
130
+ expect(res[:config].has_key?(:attach_stdout)).to be true
131
+ end
121
132
  end
122
133
 
123
134
  describe '#remove_container' do
@@ -0,0 +1,22 @@
1
+ {
2
+ "Name": "helloworld",
3
+ "ContainerSize": "s4",
4
+ "Timeout": 300,
5
+ "UUID": "e62c014e-386c-42ea-8d07-41d44e98cc3d",
6
+ "Created": "2017-03-16T07:05:24.473Z",
7
+ "Config": {
8
+ "Env": [],
9
+ "Cmd": [
10
+ "echo",
11
+ "HelloWorld"
12
+ ],
13
+ "Image": "ubuntu",
14
+ "StopSignal": "SIGTERM"
15
+ },
16
+ "HostConfig": {
17
+ "NetworkMode": "bridge"
18
+ },
19
+ "NetworkingConfig": {
20
+ "EndpointsConfig": null
21
+ }
22
+ }
@@ -0,0 +1,24 @@
1
+ [
2
+ {
3
+ "Name": "helloworld",
4
+ "ContainerSize": "s4",
5
+ "Timeout": 300,
6
+ "UUID": "e62c014e-386c-42ea-8d07-41d44e98cc3d",
7
+ "Created": "2017-03-16T07:05:24.473Z",
8
+ "Config": {
9
+ "Env": [],
10
+ "Cmd": [
11
+ "echo",
12
+ "HelloWorld"
13
+ ],
14
+ "Image": "ubuntu",
15
+ "StopSignal": "SIGTERM"
16
+ },
17
+ "HostConfig": {
18
+ "NetworkMode": "bridge"
19
+ },
20
+ "NetworkingConfig": {
21
+ "EndpointsConfig": "null"
22
+ }
23
+ }
24
+ ]
@@ -0,0 +1,64 @@
1
+ {
2
+ "Architecture": "x86_64",
3
+ "Containers": 11,
4
+ "ContainersRunning": 7,
5
+ "ContainersStopped": 3,
6
+ "ContainersPaused": 1,
7
+ "CpuCfsPeriod": true,
8
+ "CpuCfsQuota": true,
9
+ "Debug": false,
10
+ "DiscoveryBackend": "",
11
+ "DockerRootDir": "",
12
+ "Driver": "",
13
+ "DriverStatus": [[""]],
14
+ "Plugins": {
15
+ "Volume": [
16
+ ""
17
+ ],
18
+ "Network": [
19
+ "null",
20
+ "host",
21
+ "bridge"
22
+ ]
23
+ },
24
+ "ExecutionDriver": "hyper",
25
+ "ExperimentalBuild": false,
26
+ "HttpProxy": "",
27
+ "HttpsProxy": "",
28
+ "ID": "",
29
+ "IPv4Forwarding": true,
30
+ "Images": 16,
31
+ "IndexServerAddress": "https://index.docker.io/v1/",
32
+ "InitPath": "",
33
+ "InitSha1": "",
34
+ "KernelVersion": "3.12.0-1-amd64",
35
+ "Labels": [
36
+ "storage=ssd"
37
+ ],
38
+ "MemTotal": 2099236864,
39
+ "MemoryLimit": true,
40
+ "NCPU": 1,
41
+ "NEventsListener": 0,
42
+ "NFd": 11,
43
+ "NGoroutines": 21,
44
+ "Name": "prod-server-42",
45
+ "NoProxy": "9.81.1.160",
46
+ "OomKillDisable": true,
47
+ "OSType": "linux",
48
+ "OomScoreAdj": 500,
49
+ "OperatingSystem": "HyperStart",
50
+ "RegistryConfig": {
51
+ "IndexConfigs": {
52
+ "docker.io": {
53
+ "Mirrors": null,
54
+ "Name": "docker.io",
55
+ "Official": true,
56
+ "Secure": true
57
+ }
58
+ },
59
+ "InsecureRegistryCIDRs": [ ]
60
+ },
61
+ "SwapLimit": false,
62
+ "SystemTime": "2015-03-10T11:11:23.730591467-07:00",
63
+ "ServerVersion": "1.9.0"
64
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "Total": 1,
3
+ "Pending": 0,
4
+ "Running": 0,
5
+ "Finished": 1,
6
+ "Failed": 0,
7
+ "List": [
8
+ {
9
+ "CallId": "218b7b10-e7f1-4c48-ac3c-66792f8ffc06",
10
+ "Created": "2017-03-16T07:06:10.528Z",
11
+ "Status": "FINISHED",
12
+ "Message": null
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,137 @@
1
+ require 'helper'
2
+
3
+ RSpec.describe Hyperb::Funcs do
4
+
5
+ before do
6
+ @client = Hyperb::Client.new(access_key: 'key', secret_key: '123')
7
+ @funcs_path = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/funcs'
8
+ @call_path = Hyperb::FuncCallRequest::URL
9
+ end
10
+
11
+ describe '#funcs' do
12
+
13
+ before do
14
+ stub_request(:get, @funcs_path)
15
+ .to_return(body: fixture('funcs.json'))
16
+ end
17
+
18
+ it 'request to the correct path should be made' do
19
+ @client.funcs
20
+ expect(a_request(:get, @funcs_path)).to have_been_made
21
+ end
22
+
23
+ it 'return array of funcs' do
24
+ funcs = @client.funcs
25
+ expect(funcs).to be_a Array
26
+ expect(funcs.first).to be_a Hyperb::Func
27
+ end
28
+
29
+ it 'correct attrs' do
30
+ @client.funcs.each do |fn|
31
+
32
+ expect(fn.name).to be_a String
33
+ expect(fn.created).to be_a String
34
+ expect(fn.container_size).to be_a String
35
+ expect(fn.timeout).to be_a Fixnum
36
+ expect(fn.uuid).to be_a String
37
+
38
+ expect(fn.config).to be_a Hash
39
+ expect(fn.config[:cmd]).to be_a Array
40
+ expect(fn.config[:env]).to be_a Array
41
+ expect(fn.config[:image]).to be_a String
42
+ expect(fn.config[:stop_signal]).to be_a String
43
+
44
+ expect(fn.host_config).to be_a Hash
45
+ expect(fn.host_config[:network_mode]).to be_a String
46
+
47
+ expect(fn.networking_config).to be_a Hash
48
+ expect(fn.networking_config[:endpoints_config]).to be_a String
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#create_func' do
54
+
55
+ before do
56
+ stub_request(:post, @funcs_path + '/create')
57
+ .to_return(body: fixture('create_func.json'))
58
+ end
59
+
60
+ it 'request to the correct path should be made' do
61
+
62
+ params = {
63
+ name: 'helloworld',
64
+ config: {
65
+ cmd: [
66
+ 'echo',
67
+ 'HelloWorld'
68
+ ],
69
+ image: 'ubuntu'
70
+ }
71
+ }
72
+
73
+ @client.create_func(params)
74
+ expect(a_request(:post, @funcs_path + '/create')
75
+ .with(body:
76
+ {
77
+ 'Name': 'helloworld',
78
+ 'Config':
79
+ {
80
+ 'Cmd': ['echo', 'HelloWorld'],
81
+ 'Image': 'ubuntu'
82
+ }
83
+ })
84
+ ).to have_been_made
85
+ end
86
+ end
87
+
88
+ describe '#status_func' do
89
+
90
+ it 'request to the correct path should be made' do
91
+
92
+ stub_request(:get, "#{@call_path}status/func1/uuid-123")
93
+ .to_return(body: fixture('status_func.json'))
94
+
95
+ @client.status_func(name: 'func1', uuid: 'uuid-123')
96
+ expect(a_request(:get, "#{@call_path}status/func1/uuid-123"))
97
+ .to have_been_made
98
+ end
99
+ end
100
+
101
+ describe '#call_func' do
102
+
103
+ it 'request to the correct path should be made' do
104
+
105
+ stub_request(:post, "#{@call_path}call/func1/uuid-123")
106
+ .to_return(body: "")
107
+
108
+ @client.call_func(name: 'func1', uuid: 'uuid-123')
109
+ expect(a_request(:post, "#{@call_path}call/func1/uuid-123"))
110
+ .to have_been_made
111
+ end
112
+
113
+ it 'request to the correct path should be made with sync:true' do
114
+
115
+ stub_request(:post, "#{@call_path}call/func1/uuid-123/sync")
116
+ .to_return(body: "")
117
+
118
+ @client.call_func(name: 'func1', uuid: 'uuid-123', sync: true)
119
+ expect(a_request(:post, "#{@call_path}call/func1/uuid-123/sync"))
120
+ .to have_been_made
121
+ end
122
+ end
123
+
124
+ describe '#remove_func' do
125
+
126
+ before do
127
+ stub_request(:delete, @funcs_path + '/func1')
128
+ .to_return(body: "")
129
+ end
130
+
131
+ it 'request to the correct path should be made' do
132
+
133
+ @client.remove_func(name: 'func1')
134
+ expect(a_request(:delete, @funcs_path + '/func1')).to have_been_made
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ RSpec.describe Hyperb::Misc 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 + '/info'
8
+ end
9
+
10
+ describe '#info' do
11
+
12
+ it 'request to the correct path should be made' do
13
+ path = @base_path
14
+ stub_request(:get, path)
15
+ .to_return(body: fixture('info.json'))
16
+
17
+ @client.info
18
+ expect(a_request(:get, path)).to have_been_made
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,117 +1,117 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - drish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-30 00:00:00.000000000 Z
11
+ date: 2017-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.8'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.0'
62
- - - ">="
62
+ - - '>='
63
63
  - !ruby/object:Gem::Version
64
64
  version: 3.0.1
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - "~>"
69
+ - - ~>
70
70
  - !ruby/object:Gem::Version
71
71
  version: '3.0'
72
- - - ">="
72
+ - - '>='
73
73
  - !ruby/object:Gem::Version
74
74
  version: 3.0.1
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: simplecov
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - "~>"
79
+ - - ~>
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0.9'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - "~>"
86
+ - - ~>
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0.9'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: rspec
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - "~>"
93
+ - - ~>
94
94
  - !ruby/object:Gem::Version
95
95
  version: '3.0'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - "~>"
100
+ - - ~>
101
101
  - !ruby/object:Gem::Version
102
102
  version: '3.0'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: pry
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - "~>"
107
+ - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: 0.10.4
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - "~>"
114
+ - - ~>
115
115
  - !ruby/object:Gem::Version
116
116
  version: 0.10.4
117
117
  description: The Hyper.sh Ruby Gem
@@ -121,10 +121,10 @@ executables: []
121
121
  extensions: []
122
122
  extra_rdoc_files: []
123
123
  files:
124
- - ".codeclimate.yml"
125
- - ".gitignore"
126
- - ".rspec"
127
- - ".rubocop.yml"
124
+ - .codeclimate.yml
125
+ - .gitignore
126
+ - .rspec
127
+ - .rubocop.yml
128
128
  - Dockerfile
129
129
  - Gemfile
130
130
  - LICENSE.txt
@@ -148,9 +148,11 @@ files:
148
148
  - lib/hyperb/containers/containers.rb
149
149
  - lib/hyperb/containers/host_config.rb
150
150
  - lib/hyperb/error.rb
151
- - lib/hyperb/hyper_version.rb
151
+ - lib/hyperb/funcs/func.rb
152
+ - lib/hyperb/funcs/funcs.rb
152
153
  - lib/hyperb/images/image.rb
153
154
  - lib/hyperb/images/images.rb
155
+ - lib/hyperb/misc.rb
154
156
  - lib/hyperb/network/fips.rb
155
157
  - lib/hyperb/request.rb
156
158
  - lib/hyperb/services/services.rb
@@ -172,13 +174,16 @@ files:
172
174
  - spec/fixtures/container_stats.json
173
175
  - spec/fixtures/containers.json
174
176
  - spec/fixtures/create_container.json
177
+ - spec/fixtures/create_func.json
175
178
  - spec/fixtures/create_image.json
176
179
  - spec/fixtures/create_service.json
177
180
  - spec/fixtures/create_snapshot.json
178
181
  - spec/fixtures/create_volume.json
179
182
  - spec/fixtures/fip_allocate.json
180
183
  - spec/fixtures/fips_ls.json
184
+ - spec/fixtures/funcs.json
181
185
  - spec/fixtures/images.json
186
+ - spec/fixtures/info.json
182
187
  - spec/fixtures/inspect_container.json
183
188
  - spec/fixtures/inspect_image.json
184
189
  - spec/fixtures/inspect_service.json
@@ -186,11 +191,14 @@ files:
186
191
  - spec/fixtures/remove_container.json
187
192
  - spec/fixtures/remove_image.json
188
193
  - spec/fixtures/services.json
194
+ - spec/fixtures/status_func.json
189
195
  - spec/fixtures/volumes.json
196
+ - spec/funcs_spec.rb
190
197
  - spec/helper.rb
191
198
  - spec/host_config_spec.rb
192
199
  - spec/image_spec.rb
193
200
  - spec/images_spec.rb
201
+ - spec/misc_spec.rb
194
202
  - spec/network_spec.rb
195
203
  - spec/request_spec.rb
196
204
  - spec/services_spec.rb
@@ -207,17 +215,17 @@ require_paths:
207
215
  - lib
208
216
  required_ruby_version: !ruby/object:Gem::Requirement
209
217
  requirements:
210
- - - ">="
218
+ - - '>='
211
219
  - !ruby/object:Gem::Version
212
220
  version: '2.2'
213
221
  required_rubygems_version: !ruby/object:Gem::Requirement
214
222
  requirements:
215
- - - ">="
223
+ - - '>='
216
224
  - !ruby/object:Gem::Version
217
225
  version: '0'
218
226
  requirements: []
219
227
  rubyforge_project:
220
- rubygems_version: 2.6.12
228
+ rubygems_version: 2.0.14.1
221
229
  signing_key:
222
230
  specification_version: 4
223
231
  summary: The Hyper.sh Ruby Gem