turbot 0.0.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 +15 -0
- data/README.md +36 -0
- data/bin/turbot +17 -0
- data/data/cacert.pem +3988 -0
- data/lib/turbot/auth.rb +315 -0
- data/lib/turbot/cli.rb +38 -0
- data/lib/turbot/client/cisaurus.rb +25 -0
- data/lib/turbot/client/pgbackups.rb +113 -0
- data/lib/turbot/client/rendezvous.rb +111 -0
- data/lib/turbot/client/ssl_endpoint.rb +25 -0
- data/lib/turbot/client/turbot_postgresql.rb +148 -0
- data/lib/turbot/client.rb +757 -0
- data/lib/turbot/command/auth.rb +85 -0
- data/lib/turbot/command/base.rb +192 -0
- data/lib/turbot/command/bots.rb +326 -0
- data/lib/turbot/command/config.rb +123 -0
- data/lib/turbot/command/help.rb +179 -0
- data/lib/turbot/command/keys.rb +115 -0
- data/lib/turbot/command/logs.rb +34 -0
- data/lib/turbot/command/ssl.rb +43 -0
- data/lib/turbot/command/status.rb +51 -0
- data/lib/turbot/command/update.rb +47 -0
- data/lib/turbot/command/version.rb +23 -0
- data/lib/turbot/command.rb +304 -0
- data/lib/turbot/deprecated/help.rb +38 -0
- data/lib/turbot/deprecated.rb +5 -0
- data/lib/turbot/distribution.rb +9 -0
- data/lib/turbot/errors.rb +28 -0
- data/lib/turbot/excon.rb +11 -0
- data/lib/turbot/helpers/log_displayer.rb +70 -0
- data/lib/turbot/helpers/pg_dump_restore.rb +115 -0
- data/lib/turbot/helpers/turbot_postgresql.rb +213 -0
- data/lib/turbot/helpers.rb +521 -0
- data/lib/turbot/plugin.rb +165 -0
- data/lib/turbot/updater.rb +171 -0
- data/lib/turbot/version.rb +3 -0
- data/lib/turbot.rb +19 -0
- data/lib/vendor/turbot/okjson.rb +598 -0
- data/spec/helper/legacy_help.rb +16 -0
- data/spec/helper/pg_dump_restore_spec.rb +67 -0
- data/spec/schemas/dummy_schema.json +12 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +220 -0
- data/spec/support/display_message_matcher.rb +49 -0
- data/spec/support/dummy_api.rb +120 -0
- data/spec/support/openssl_mock_helper.rb +8 -0
- data/spec/support/organizations_mock_helper.rb +11 -0
- data/spec/turbot/auth_spec.rb +214 -0
- data/spec/turbot/client/pgbackups_spec.rb +43 -0
- data/spec/turbot/client/rendezvous_spec.rb +62 -0
- data/spec/turbot/client/ssl_endpoint_spec.rb +48 -0
- data/spec/turbot/client/turbot_postgresql_spec.rb +71 -0
- data/spec/turbot/client_spec.rb +548 -0
- data/spec/turbot/command/auth_spec.rb +38 -0
- data/spec/turbot/command/base_spec.rb +66 -0
- data/spec/turbot/command/bots_spec.rb +54 -0
- data/spec/turbot/command/config_spec.rb +143 -0
- data/spec/turbot/command/help_spec.rb +90 -0
- data/spec/turbot/command/keys_spec.rb +117 -0
- data/spec/turbot/command/logs_spec.rb +60 -0
- data/spec/turbot/command/status_spec.rb +48 -0
- data/spec/turbot/command/version_spec.rb +16 -0
- data/spec/turbot/command_spec.rb +131 -0
- data/spec/turbot/helpers/turbot_postgresql_spec.rb +181 -0
- data/spec/turbot/helpers_spec.rb +48 -0
- data/spec/turbot/plugin_spec.rb +172 -0
- data/spec/turbot/updater_spec.rb +44 -0
- data/templates/manifest.json +7 -0
- data/templates/scraper.py +5 -0
- data/templates/scraper.rb +6 -0
- metadata +199 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "spec_helper"
|
3
|
+
require "turbot/client/rendezvous"
|
4
|
+
require "support/openssl_mock_helper"
|
5
|
+
|
6
|
+
describe Turbot::Client, "rendezvous" do
|
7
|
+
before do
|
8
|
+
@rendezvous = Turbot::Client::Rendezvous.new({
|
9
|
+
:rendezvous_url => "https://turbot.local:1234/secret",
|
10
|
+
:output => $stdout
|
11
|
+
})
|
12
|
+
end
|
13
|
+
context "fixup" do
|
14
|
+
it "null" do
|
15
|
+
@rendezvous.send(:fixup, nil).should be_nil
|
16
|
+
end
|
17
|
+
it "an empty string" do
|
18
|
+
@rendezvous.send(:fixup, "").should eq ""
|
19
|
+
end
|
20
|
+
it "hash" do
|
21
|
+
@rendezvous.send(:fixup, { :x => :y }).should eq({ :x => :y })
|
22
|
+
end
|
23
|
+
it "default English UTF-8 data" do
|
24
|
+
@rendezvous.send(:fixup, "turbot").should eq "turbot"
|
25
|
+
end
|
26
|
+
it "default Japanese UTF-8 encoded data" do
|
27
|
+
@rendezvous.send(:fixup, "愛しています").should eq "愛しています"
|
28
|
+
end
|
29
|
+
if RUBY_VERSION >= "1.9"
|
30
|
+
it "ISO-8859-1 force-encoded data" do
|
31
|
+
@rendezvous.send(:fixup, "Хероку".force_encoding("ISO-8859-1")).should eq "Хероку".force_encoding("UTF-8")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context "with mock ssl" do
|
36
|
+
before :each do
|
37
|
+
mock_openssl
|
38
|
+
@ssl_socket_mock.should_receive(:puts).with("secret")
|
39
|
+
@ssl_socket_mock.should_receive(:readline).and_return(nil)
|
40
|
+
end
|
41
|
+
it "should connect to host:post" do
|
42
|
+
TCPSocket.should_receive(:open).with("turbot.local", 1234).and_return(@tcp_socket_mock)
|
43
|
+
IO.stub(:select).and_return(nil)
|
44
|
+
@ssl_socket_mock.stub(:write)
|
45
|
+
@ssl_socket_mock.stub(:flush) { raise Timeout::Error }
|
46
|
+
lambda { @rendezvous.start }.should raise_error(Timeout::Error)
|
47
|
+
end
|
48
|
+
it "should callback on_connect" do
|
49
|
+
@rendezvous.on_connect do
|
50
|
+
raise "on_connect"
|
51
|
+
end
|
52
|
+
TCPSocket.should_receive(:open).and_return(@tcp_socket_mock)
|
53
|
+
lambda { @rendezvous.start }.should raise_error("on_connect")
|
54
|
+
end
|
55
|
+
it "should fixup received data" do
|
56
|
+
TCPSocket.should_receive(:open).and_return(@tcp_socket_mock)
|
57
|
+
@ssl_socket_mock.should_receive(:readpartial).and_return("The quick brown fox jumps over the lazy dog")
|
58
|
+
@rendezvous.stub(:fixup) { |data| raise "received: #{data}" }
|
59
|
+
lambda { @rendezvous.start }.should raise_error("received: The quick brown fox jumps over the lazy dog")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "turbot/client/ssl_endpoint"
|
3
|
+
|
4
|
+
describe Turbot::Client, "ssl endpoints" do
|
5
|
+
before do
|
6
|
+
@client = Turbot::Client.new(nil, nil)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "adds an ssl endpoint" do
|
10
|
+
stub_request(:post, "https://api.turbot.com/bots/example/ssl-endpoints").
|
11
|
+
with(:body => { :accept => "json", :pem => "pem content", :key => "key content" }).
|
12
|
+
to_return(:body => %{ {"cname": "tokyo-1050" } })
|
13
|
+
@client.ssl_endpoint_add("example", "pem content", "key content").should == { "cname" => "tokyo-1050" }
|
14
|
+
end
|
15
|
+
|
16
|
+
it "gets info on an ssl endpoint" do
|
17
|
+
stub_request(:get, "https://api.turbot.com/bots/example/ssl-endpoints/tokyo-1050").
|
18
|
+
to_return(:body => %{ {"cname": "tokyo-1050" } })
|
19
|
+
@client.ssl_endpoint_info("example", "tokyo-1050").should == { "cname" => "tokyo-1050" }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "lists ssl endpoints for an bot" do
|
23
|
+
stub_request(:get, "https://api.turbot.com/bots/example/ssl-endpoints").
|
24
|
+
to_return(:body => %{ [{"cname": "tokyo-1050" }, {"cname": "tokyo-1051" }] })
|
25
|
+
@client.ssl_endpoint_list("example").should == [
|
26
|
+
{ "cname" => "tokyo-1050" },
|
27
|
+
{ "cname" => "tokyo-1051" },
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
it "removes an ssl endpoint" do
|
32
|
+
stub_request(:delete, "https://api.turbot.com/bots/example/ssl-endpoints/tokyo-1050")
|
33
|
+
@client.ssl_endpoint_remove("example", "tokyo-1050")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "rolls back an ssl endpoint" do
|
37
|
+
stub_request(:post, "https://api.turbot.com/bots/example/ssl-endpoints/tokyo-1050/rollback").
|
38
|
+
to_return(:body => %{ {"cname": "tokyo-1050" } })
|
39
|
+
@client.ssl_endpoint_rollback("example", "tokyo-1050").should == { "cname" => "tokyo-1050" }
|
40
|
+
end
|
41
|
+
|
42
|
+
it "updates an ssl endpoint" do
|
43
|
+
stub_request(:put, "https://api.turbot.com/bots/example/ssl-endpoints/tokyo-1050").
|
44
|
+
with(:body => { :accept => "json", :pem => "pem content", :key => "key content" }).
|
45
|
+
to_return(:body => %{ {"cname": "tokyo-1050" } })
|
46
|
+
@client.ssl_endpoint_update("example", "tokyo-1050", "pem content", "key content").should == { "cname" => "tokyo-1050" }
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "turbot/client/turbot_postgresql"
|
3
|
+
require "digest"
|
4
|
+
|
5
|
+
describe Turbot::Client::TurbotPostgresql do
|
6
|
+
include Turbot::Helpers
|
7
|
+
|
8
|
+
before do
|
9
|
+
Turbot::Auth.stub :user => 'user@example.com', :password => 'apitoken'
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:attachment) { double('attachment', :resource_name => 'something-something-42', :starter_plan? => false) }
|
13
|
+
let(:client) { Turbot::Client::TurbotPostgresql.new(attachment) }
|
14
|
+
|
15
|
+
describe 'api choosing' do
|
16
|
+
it "sends an ingress request to the client for production plans" do
|
17
|
+
attachment.stub! :starter_plan? => false
|
18
|
+
host = 'postgres-api.turbot.com'
|
19
|
+
url = "https://user@example.com:apitoken@#{host}/client/v11/databases/#{attachment.resource_name}/ingress"
|
20
|
+
|
21
|
+
stub_request(:put, url).to_return(
|
22
|
+
:body => json_encode({"message" => "ok"}),
|
23
|
+
:status => 200
|
24
|
+
)
|
25
|
+
|
26
|
+
client.ingress
|
27
|
+
|
28
|
+
a_request(:put, url).should have_been_made.once
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sends an ingress request to the client for production plans" do
|
32
|
+
attachment.stub! :starter_plan? => true
|
33
|
+
host = 'postgres-starter-api.turbot.com'
|
34
|
+
url = "https://user@example.com:apitoken@#{host}/client/v11/databases/#{attachment.resource_name}/ingress"
|
35
|
+
|
36
|
+
stub_request(:put, url).to_return(
|
37
|
+
:body => json_encode({"message" => "ok"}),
|
38
|
+
:status => 200
|
39
|
+
)
|
40
|
+
|
41
|
+
client.ingress
|
42
|
+
|
43
|
+
a_request(:put, url).should have_been_made.once
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#get_database' do
|
48
|
+
let(:url) { "https://user@example.com:apitoken@postgres-api.turbot.com/client/v11/databases/#{attachment.resource_name}" }
|
49
|
+
|
50
|
+
it 'works without the extended option' do
|
51
|
+
stub_request(:get, url).to_return :body => '{}'
|
52
|
+
client.get_database
|
53
|
+
a_request(:get, url).should have_been_made.once
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'works with the extended option' do
|
57
|
+
url2 = url + '?extended=true'
|
58
|
+
stub_request(:get, url2).to_return :body => '{}'
|
59
|
+
client.get_database(true)
|
60
|
+
a_request(:get, url2).should have_been_made.once
|
61
|
+
end
|
62
|
+
|
63
|
+
it "retries on error, then raises" do
|
64
|
+
stub_request(:get, url).to_return(:body => "error", :status => 500)
|
65
|
+
client.stub(:sleep)
|
66
|
+
lambda { client.get_database }.should raise_error RestClient::InternalServerError
|
67
|
+
a_request(:get, url).should have_been_made.times(4)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|