triton-internal 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09d4eaf1f2000e78096108a63aaf97e81adc2e99
4
- data.tar.gz: 5b67fa60083fbb80be94bd7d2a5622ba386d503d
3
+ metadata.gz: b1d5de7320b4447d13458f6abc836617f9e7c2b8
4
+ data.tar.gz: 50e46b53d2765a7a347975795b4252bc78518548
5
5
  SHA512:
6
- metadata.gz: e8a6029d0c4866651966b69f3550a6ea66ac9648be020549a9d3a2a500186397e9656fa34c9b5d14e0b27c60fda317af010faa2e15a446fb785a335b62e82a26
7
- data.tar.gz: 91a646e5e0e506bd6c5623f57ed9d71114a8f95986f6426088a64b3e456f5b780d59547d8cd2b7d8e468025fb621c38fc0fcfd027cb22402f77c381db28c6397
6
+ metadata.gz: 7a2df21d05b478abc991f8c62280257b27a75829e59d58c427aaeadfa35dad8bc8bf436b0ee16a68f77fcb92f253cd69be267a565a5e729d8cbf6e6e7b1397ad
7
+ data.tar.gz: fda2a3f399fef85ac362ee39f77086790fde738b384ddd7bc566dca1bd2c338faae4cb0f56f8f3642a28ed008697253dabd9fd4c306f495293f7cfdcfba82ff4
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ module Triton
2
+ VERSION = "0.1.2"
3
+ end
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: triton-internal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Haggett
@@ -88,29 +88,19 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - "/Users/thomas/tdh/triton/Gemfile"
92
- - "/Users/thomas/tdh/triton/Gemfile.lock"
93
- - "/Users/thomas/tdh/triton/LICENSE"
94
- - "/Users/thomas/tdh/triton/README.md"
95
- - "/Users/thomas/tdh/triton/Rakefile"
96
- - "/Users/thomas/tdh/triton/bin/console"
97
- - "/Users/thomas/tdh/triton/bin/setup"
98
- - "/Users/thomas/tdh/triton/lib/triton.rb"
99
- - "/Users/thomas/tdh/triton/lib/triton/api_base.rb"
100
- - "/Users/thomas/tdh/triton/lib/triton/cnapi.rb"
101
- - "/Users/thomas/tdh/triton/lib/triton/imgapi.rb"
102
- - "/Users/thomas/tdh/triton/lib/triton/indifferent_hash.rb"
103
- - "/Users/thomas/tdh/triton/lib/triton/internal.rb"
104
- - "/Users/thomas/tdh/triton/lib/triton/napi.rb"
105
- - "/Users/thomas/tdh/triton/lib/triton/papi.rb"
106
- - "/Users/thomas/tdh/triton/lib/triton/remote_exception.rb"
107
- - "/Users/thomas/tdh/triton/lib/triton/version.rb"
108
- - "/Users/thomas/tdh/triton/lib/triton/vmapi.rb"
109
- - "/Users/thomas/tdh/triton/pkg/triton-internal-0.1.0.gem"
110
- - "/Users/thomas/tdh/triton/spec/api_base_spec.rb"
111
- - "/Users/thomas/tdh/triton/spec/spec_helper.rb"
112
- - "/Users/thomas/tdh/triton/spec/triton_spec.rb"
113
- - "/Users/thomas/tdh/triton/triton-internal.gemspec"
91
+ - LICENSE
92
+ - README.md
93
+ - lib/triton.rb
94
+ - lib/triton/api_base.rb
95
+ - lib/triton/cnapi.rb
96
+ - lib/triton/imgapi.rb
97
+ - lib/triton/indifferent_hash.rb
98
+ - lib/triton/internal.rb
99
+ - lib/triton/napi.rb
100
+ - lib/triton/papi.rb
101
+ - lib/triton/remote_exception.rb
102
+ - lib/triton/version.rb
103
+ - lib/triton/vmapi.rb
114
104
  homepage: https://github.com/joshado/triton-internal-gem
115
105
  licenses:
116
106
  - MIT
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in triton.gemspec
4
- gemspec
@@ -1,51 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- triton-internal (0.1.1)
5
- rest-client (~> 1.8)
6
- socksify (~> 1.7)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- diff-lcs (1.3)
12
- domain_name (0.5.20170404)
13
- unf (>= 0.0.5, < 1.0.0)
14
- http-cookie (1.0.3)
15
- domain_name (~> 0.5)
16
- mime-types (2.99.3)
17
- netrc (0.11.0)
18
- rake (10.5.0)
19
- rest-client (1.8.0)
20
- http-cookie (>= 1.0.2, < 2.0)
21
- mime-types (>= 1.16, < 3.0)
22
- netrc (~> 0.7)
23
- rspec (3.6.0)
24
- rspec-core (~> 3.6.0)
25
- rspec-expectations (~> 3.6.0)
26
- rspec-mocks (~> 3.6.0)
27
- rspec-core (3.6.0)
28
- rspec-support (~> 3.6.0)
29
- rspec-expectations (3.6.0)
30
- diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.6.0)
32
- rspec-mocks (3.6.0)
33
- diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.6.0)
35
- rspec-support (3.6.0)
36
- socksify (1.7.0)
37
- unf (0.1.4)
38
- unf_ext
39
- unf_ext (0.0.7.4)
40
-
41
- PLATFORMS
42
- ruby
43
-
44
- DEPENDENCIES
45
- bundler (~> 1.14)
46
- rake (~> 10.0)
47
- rspec (~> 3.0)
48
- triton-internal!
49
-
50
- BUNDLED WITH
51
- 1.14.6
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "triton/internal"
5
- require 'optparse'
6
-
7
- OptionParser.new do |o|
8
- o.on("--socks [host:]port", String, "Configures the library to use a SOCKS proxy at host:port (defaults host to localhost)") do |v|
9
- Triton.socks = v
10
- end
11
- o.on("--suffix suffix", String, "Specifies the triton hostname suffix to use") do |v|
12
- Triton.suffix = v
13
- end
14
- end.parse!(ARGV)
15
-
16
- require "irb"
17
- IRB.start(__FILE__)
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,3 +0,0 @@
1
- module Triton
2
- VERSION = "0.1.1"
3
- end
@@ -1,288 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "ApiMapping" do
4
-
5
- let(:fakeapi) do
6
- Class.new(Triton::ApiBase) do
7
- self.name = "fakeapi"
8
- call("TestMethod", {
9
- :method => :post,
10
- :path => "/testmethod/path"
11
- })
12
-
13
- call("GetMethod", {
14
- :path => "/testmethod/path"
15
- })
16
-
17
- call("GetThing", {
18
- :path => "/things/:thing/foo"
19
- })
20
-
21
- call("PostThing", {
22
- :method => :post,
23
- :path => "/things/:thing"
24
- })
25
-
26
- call("GetThingWithQueryString", {
27
- :path => "/things/:thing/foo?a=b"
28
- })
29
-
30
- call("SetTags", {
31
- :method => :post,
32
- :path => "/thing/:id/tag",
33
- :body_param => :metadata
34
- })
35
-
36
- end
37
- end
38
-
39
- describe "instance behaviour" do
40
-
41
- subject { fakeapi.new("TestMethod") }
42
-
43
- it "should memoise the request" do
44
- first_request = subject.request
45
- expect(subject.request.object_id).to eq(first_request.object_id)
46
- end
47
-
48
- it "should pass execute to the request" do
49
- expect(subject.request).to receive(:execute).and_return("{}")
50
- subject.execute
51
- end
52
-
53
- it "should have a shortcut to execute the method from the class" do
54
- expect(fakeapi).to respond_to(:execute)
55
- end
56
- end
57
-
58
- describe "init - when the call isn't defined" do
59
- it "should raise an exception if the call isn't recognised" do
60
- expect { fakeapi.new("Unknown") }.to raise_exception(Triton::ApiBase::UnknownCall)
61
- end
62
-
63
- it "should be a NoMethodError" do
64
- expect(Triton::ApiBase::UnknownCall.new).to be_a(NoMethodError)
65
- end
66
- end
67
-
68
- describe "response handling" do
69
- subject { fakeapi.new("TestMethod") }
70
-
71
- it "should decode the payload as JSON" do
72
- allow(subject.request).to receive(:execute).and_return('{"something": "here"}')
73
- expect(subject.execute).to eq({"something" => "here"})
74
- end
75
-
76
- it "should return a hash with indifferent key access" do
77
- allow(subject.request).to receive(:execute).and_return('{"something": "here", "nested": {"something": "inner"}}')
78
- expect(subject.execute[:something]).to eq("here")
79
- expect(subject.execute['something']).to eq("here")
80
- expect(subject.execute[:nested][:something]).to eq("inner")
81
- expect(subject.execute[:nested]['something']).to eq("inner")
82
- end
83
- end
84
-
85
- describe "response exception handling" do
86
- subject { fakeapi.new("TestMethod") }
87
-
88
- let(:exception) { RestClient::Exception.new(double("Response", :body => "body"))}
89
-
90
- before do
91
- # Simulate a RestClient exception when we execute
92
- allow(subject.request).to receive(:execute).and_raise(exception)
93
- end
94
-
95
- it "should re-raise the original RestClient exception if the body doesn't contain valid JSON" do
96
- expect { subject.execute }.to raise_exception(exception)
97
- end
98
-
99
- it "should raise a Triton::RemoteException if the JSON decoded, but doesn't contain a 'code' field" do
100
- allow(exception.response).to receive(:body).and_return("{}")
101
- expect { subject.execute }.to raise_exception(Triton::RemoteException)
102
- end
103
-
104
- it "should synthesize an exception class if a 'code' is present" do
105
- allow(exception.response).to receive(:body).and_return('{"code": "ItScrewedUp"}')
106
- expect { subject.execute }.to raise_exception(Triton::RemoteExceptions::ItScrewedUp)
107
- end
108
-
109
- it "should be possible to raise a RemoteException with a struct" do
110
- expect do
111
- raise Triton::RemoteExceptions::RemoteException, { 'code' => 'ResourceNotFound', 'message' => 'VM not found'}
112
- end.to raise_exception(Triton::RemoteExceptions::ResourceNotFound, 'VM not found')
113
- end
114
-
115
- it "should be possible to raise a RemoteException with a message directly" do
116
- expect do
117
- raise Triton::RemoteExceptions::ResourceNotFound, 'VM not found'
118
- end.to raise_exception(Triton::RemoteExceptions::ResourceNotFound, 'VM not found')
119
- end
120
-
121
- it "should be possible to raise a RemoteException from a mock with a message in a test" do
122
- object = Object.new
123
- allow(object).to receive(:crash).and_raise(Triton::RemoteExceptions::ResourceNotFound, 'VM not found')
124
-
125
- expect do
126
- object.crash
127
- end.to raise_exception(Triton::RemoteExceptions::ResourceNotFound, 'VM not found')
128
- end
129
- end
130
-
131
- describe "request" do
132
- subject { fakeapi.new("TestMethod").request }
133
-
134
- it "should build a RestClient request" do
135
- expect(subject).to be_a(RestClient::Request)
136
- end
137
-
138
- it "should use the specified name as the first part of the hostname" do
139
- expect(subject.url).to match(%r{^http://fakeapi})
140
- end
141
-
142
- it "should append the configured suffix to the hostname" do
143
- expect(subject.url).to match(%r{^http://fakeapi.test/})
144
- end
145
-
146
- it "should append the path to the url" do
147
- expect(URI.parse(subject.url).path).to eq("/testmethod/path")
148
- end
149
-
150
-
151
- it "should set the method" do
152
- expect(subject.method).to eq(:post)
153
- end
154
-
155
- it "should default the method to :get" do
156
- expect(fakeapi.new("GetMethod").request.method).to eq(:get)
157
- end
158
- end
159
-
160
- describe "path parametisation" do
161
- it "should replace any :<word> values with the associated argument" do
162
- expect(URI.parse(fakeapi.new("GetThing", :thing => "IDENT").request.url).path).to eq("/things/IDENT/foo")
163
- end
164
- it "should URL encode any value" do
165
- expect(URI.parse(fakeapi.new("GetThing", :thing => "IDE/NT").request.url).path).to eq("/things/IDE%2FNT/foo")
166
- end
167
-
168
- it "should exclude any arguments used to build the URL from the query string of GET requests" do
169
- request = fakeapi.new("GetThing", 'thing' => "123", :foo => "bar").request
170
- expect(URI.parse(request.url).query).to eq("foo=bar")
171
- end
172
- it "should exclude any arguments used to build the URL from the payload of non-get requests" do
173
- request = fakeapi.new("PostThing", 'thing' => "123", :foo => "bar").request
174
- expect(URI.parse(request.url).path).to eq("/things/123")
175
- expect(JSON.load(request.payload)).to eq("foo" => "bar")
176
- end
177
- end
178
-
179
- it "should accept application/json" do
180
- expect(fakeapi.new("GetThing", :thing => "IDENT").request.headers['Accept']).to eq("application/json")
181
- expect(fakeapi.new("TestMethod").request.headers['Accept']).to eq("application/json")
182
- end
183
-
184
- describe "arguments - GET requests" do
185
- subject { fakeapi.new("GetMethod", :foo=>"bar/baz", :bar=>"baz").request }
186
- it "should urlencode and append to the URL as a query string" do
187
- expect(URI.parse(subject.url).query).to eq("foo=bar%2Fbaz&bar=baz")
188
- end
189
-
190
- it "should append carefully if there is already a query string" do
191
- url = fakeapi.new("GetThingWithQueryString", :thing => 1, :foo=>"bar", :bar=>"foo/bar").request.url
192
- expect(URI.parse(url).query).to eq("a=b&foo=bar&bar=foo%2Fbar")
193
-
194
- end
195
-
196
- it "should not set a payload" do
197
- expect(subject.payload).to be_nil
198
- end
199
-
200
- it "should not set a Content-Type header" do
201
- expect(subject.headers["Content-Type"]).to be_nil
202
- end
203
- end
204
-
205
- describe "arguments - non-GET" do
206
- subject { fakeapi.new("TestMethod", 'some' => 'args', :live => :here).request }
207
-
208
- it "should set the Content-Body to application/json" do
209
- expect(subject.headers["Content-Type"]).to eq("application/json")
210
- end
211
- it "should serialize the arguments to JSON as the payload" do
212
- expect(JSON.load(subject.payload)).to eq({'some' => 'args', 'live' => 'here'})
213
- end
214
-
215
- end
216
-
217
- it "should generate a snake-case function call from the Api name" do
218
- expect(fakeapi).to respond_to(:get_method)
219
- end
220
-
221
-
222
- describe "camelise" do
223
- it "should return a camel_case string" do
224
- expect("foo".camelise).to eq("Foo")
225
- expect("foo_bar".camelise).to eq("FooBar")
226
- expect("foo_bar_baz".camelise).to eq("FooBarBaz")
227
- expect("foo______bar_baz".camelise).to eq("FooBarBaz")
228
- end
229
- it "should return nil if an unexpected string is encountered" do
230
- expect("something-wrong".camelise).to eq(nil)
231
- expect("Capsyousay".camelise).to eq(nil)
232
- expect("wow!".camelise).to eq(nil)
233
- end
234
- end
235
-
236
- describe "test_mode" do
237
- before do
238
- Triton.test_mode = true
239
- end
240
- it "should raise an exception if a request is attempted when test_mode is set" do
241
- expect do
242
- fakeapi.test_method()
243
- end.to raise_exception(Triton::TestModeLeak)
244
- end
245
-
246
- it "should include the Api call name in the exception" do
247
- expect do
248
- fakeapi.test_method()
249
- end.to raise_exception do |ex|
250
- expect(ex.message).to include("TestMethod")
251
- end
252
- end
253
-
254
- it "should include the call route in the exception" do
255
- expect do
256
- fakeapi.test_method()
257
- end.to raise_exception do |ex|
258
- expect(ex.message).to include("POST /testmethod/path")
259
- end
260
- end
261
-
262
- it "should include the parameters in the exception" do
263
- expect do
264
- fakeapi.test_method("param" => "value")
265
- end.to raise_exception do |ex|
266
- expect(ex.message).to include(%{"param": "value"})
267
- end
268
- end
269
- end
270
-
271
-
272
- describe "body_param option" do
273
-
274
- subject { fakeapi.new('SetTags', :id => "the-id", :other_param => "other_value", :key => 'value', :metadata => { "tag1" => "value1", "tag2" => "value2" })}
275
-
276
- it "should write the value of the body_param to the body" do
277
- expect(JSON.load(subject.request.payload)).to eq({ "tag1" => "value1", "tag2" => "value2" })
278
- end
279
-
280
- it "should set any additional parameters on the query-string" do
281
- expect(URI.parse(subject.request.url).query).to eq("other_param=other_value&key=value")
282
- end
283
-
284
- end
285
-
286
- end
287
-
288
-
@@ -1,16 +0,0 @@
1
- require "bundler/setup"
2
- require "triton/internal"
3
-
4
- RSpec.configure do |config|
5
- # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = ".rspec_status"
7
-
8
- config.before do
9
- Triton.test_mode = false
10
- Triton.suffix = "test"
11
- end
12
-
13
- config.expect_with :rspec do |c|
14
- c.syntax = :expect
15
- end
16
- end
@@ -1,32 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Triton do
4
- it "has a version number" do
5
- expect(Triton::VERSION).not_to be nil
6
- end
7
-
8
- it "should have a configurable suffix" do
9
- expect(Triton.suffix).to eq("test")
10
- Triton.suffix = "foo"
11
- expect(Triton.suffix).to eq("foo")
12
- end
13
-
14
- describe "socks config" do
15
- it "should accept host:port" do
16
- Triton.socks = "1.2.3.4:5678"
17
- expect(TCPSocket.socks_server).to eq("1.2.3.4")
18
- expect(TCPSocket.socks_port).to eq(5678)
19
- end
20
- it "should accept string 'port' and assume localhost" do
21
- Triton.socks = "5678"
22
- expect(TCPSocket.socks_server).to eq("127.0.0.1")
23
- expect(TCPSocket.socks_port).to eq(5678)
24
- end
25
- it "should accept an integer port, and assume localhost" do
26
- Triton.socks = 5678
27
- expect(TCPSocket.socks_server).to eq("127.0.0.1")
28
- expect(TCPSocket.socks_port).to eq(5678)
29
- end
30
- end
31
-
32
- end
@@ -1,30 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'triton/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "triton-internal"
8
- spec.version = Triton::VERSION
9
- spec.authors = ["Thomas Haggett"]
10
- spec.email = ["thomas-tritongem@haggett.org"]
11
- spec.licenses = ['MIT']
12
-
13
- spec.summary = %q{Library to wrap the Triton internal APIs}
14
- spec.description = %q{Library that wraps all of the Joyent Triton Internal APIs in a consistent ruby interface allowing easier calling and mocking.}
15
- spec.homepage = "https://github.com/joshado/triton-internal-gem"
16
-
17
- spec.files = Dir.glob(File.expand_path("../**/*", __FILE__)).reject do |f|
18
- f.match(%r{^(test|spec|features)/})
19
- end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_development_dependency "bundler", "~> 1.14"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.0"
27
-
28
- spec.add_dependency 'rest-client', "~> 1.8"
29
- spec.add_dependency 'socksify', "~> 1.7"
30
- end