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,171 @@
|
|
1
|
+
require "digest"
|
2
|
+
require "fileutils"
|
3
|
+
require "turbot/helpers"
|
4
|
+
|
5
|
+
module Turbot
|
6
|
+
module Updater
|
7
|
+
|
8
|
+
def self.error(message)
|
9
|
+
raise Turbot::Command::CommandFailed.new(message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.updating_lock_path
|
13
|
+
File.join(Turbot::Helpers.home_directory, ".turbot", "updating")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.installed_client_path
|
17
|
+
File.expand_path("../../..", __FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.updated_client_path
|
21
|
+
File.join(Turbot::Helpers.home_directory, ".turbot", "client")
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.latest_local_version
|
25
|
+
installed_version = client_version_from_path(installed_client_path)
|
26
|
+
updated_version = client_version_from_path(updated_client_path)
|
27
|
+
if compare_versions(updated_version, installed_version) > 0
|
28
|
+
updated_version
|
29
|
+
else
|
30
|
+
installed_version
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.client_version_from_path(path)
|
35
|
+
version_file = File.join(path, "lib/turbot/version.rb")
|
36
|
+
if File.exists?(version_file)
|
37
|
+
File.read(version_file).match(/VERSION = "([^"]+)"/)[1]
|
38
|
+
else
|
39
|
+
'0.0.0'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.disable(message=nil)
|
44
|
+
@disable = message if message
|
45
|
+
@disable
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.check_disabled!
|
49
|
+
if disable
|
50
|
+
Turbot::Helpers.error(disable)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.wait_for_lock(path, wait_for=5, check_every=0.5)
|
55
|
+
start = Time.now.to_i
|
56
|
+
while File.exists?(path)
|
57
|
+
sleep check_every
|
58
|
+
if (Time.now.to_i - start) > wait_for
|
59
|
+
Turbot::Helpers.error "Unable to acquire update lock"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
begin
|
63
|
+
FileUtils.touch path
|
64
|
+
ret = yield
|
65
|
+
ensure
|
66
|
+
FileUtils.rm_f path
|
67
|
+
end
|
68
|
+
ret
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.autoupdate?
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.update(url, autoupdate=false)
|
76
|
+
wait_for_lock(updating_lock_path, 5) do
|
77
|
+
require "excon"
|
78
|
+
require "turbot"
|
79
|
+
require "turbot/excon"
|
80
|
+
require "tmpdir"
|
81
|
+
require "zip/zip"
|
82
|
+
|
83
|
+
latest_version = Excon.get_with_redirect("http://assets.turbot.com/turbot-client/VERSION", :nonblock => false).body.chomp
|
84
|
+
|
85
|
+
if compare_versions(latest_version, latest_local_version) > 0
|
86
|
+
Dir.mktmpdir do |download_dir|
|
87
|
+
File.open("#{download_dir}/turbot.zip", "wb") do |file|
|
88
|
+
file.print Excon.get_with_redirect(url, :nonblock => false).body
|
89
|
+
end
|
90
|
+
|
91
|
+
hash = Digest::SHA256.file("#{download_dir}/turbot.zip").hexdigest
|
92
|
+
official_hash = Excon.get_with_redirect("https://toolbelt.turbot.com/update/hash", :nonblock => false).body.chomp
|
93
|
+
|
94
|
+
error "Update hash signature mismatch" unless hash == official_hash
|
95
|
+
|
96
|
+
Zip::ZipFile.open("#{download_dir}/turbot.zip") do |zip|
|
97
|
+
zip.each do |entry|
|
98
|
+
target = File.join(download_dir, entry.to_s)
|
99
|
+
FileUtils.mkdir_p File.dirname(target)
|
100
|
+
zip.extract(entry, target) { true }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
FileUtils.rm "#{download_dir}/turbot.zip"
|
105
|
+
|
106
|
+
old_version = latest_local_version
|
107
|
+
new_version = client_version_from_path(download_dir)
|
108
|
+
|
109
|
+
if compare_versions(new_version, old_version) < 0 && !autoupdate
|
110
|
+
Turbot::Helpers.error("Installed version (#{old_version}) is newer than the latest available update (#{new_version})")
|
111
|
+
end
|
112
|
+
|
113
|
+
FileUtils.rm_rf updated_client_path
|
114
|
+
FileUtils.mkdir_p File.dirname(updated_client_path)
|
115
|
+
FileUtils.cp_r download_dir, updated_client_path
|
116
|
+
|
117
|
+
new_version
|
118
|
+
end
|
119
|
+
else
|
120
|
+
false # already up to date
|
121
|
+
end
|
122
|
+
end
|
123
|
+
ensure
|
124
|
+
FileUtils.rm_f(updating_lock_path)
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.compare_versions(first_version, second_version)
|
128
|
+
first_version.split('.').map {|part| Integer(part) rescue part} <=> second_version.split('.').map {|part| Integer(part) rescue part}
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.inject_libpath
|
132
|
+
old_version = client_version_from_path(installed_client_path)
|
133
|
+
new_version = client_version_from_path(updated_client_path)
|
134
|
+
|
135
|
+
if compare_versions(new_version, old_version) > 0
|
136
|
+
$:.unshift File.join(updated_client_path, "lib")
|
137
|
+
vendored_gems = Dir[File.join(updated_client_path, "vendor", "gems", "*")]
|
138
|
+
vendored_gems.each do |vendored_gem|
|
139
|
+
$:.unshift File.join(vendored_gem, "lib")
|
140
|
+
end
|
141
|
+
load('turbot/updater.rb') # reload updated updater
|
142
|
+
end
|
143
|
+
|
144
|
+
background_update!
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.last_autoupdate_path
|
148
|
+
File.join(Turbot::Helpers.home_directory, ".turbot", "autoupdate.last")
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.background_update!
|
152
|
+
# if we've updated in the last 300 seconds, dont try again
|
153
|
+
if File.exists?(last_autoupdate_path)
|
154
|
+
return if (Time.now.to_i - File.mtime(last_autoupdate_path).to_i) < 300
|
155
|
+
end
|
156
|
+
log_path = File.join(Turbot::Helpers.home_directory, '.turbot', 'autoupdate.log')
|
157
|
+
FileUtils.mkdir_p File.dirname(log_path)
|
158
|
+
turbot_binary = File.expand_path($0)
|
159
|
+
pid = if defined?(RUBY_VERSION) and RUBY_VERSION =~ /^1\.8\.\d+/
|
160
|
+
fork do
|
161
|
+
exec("\"#{turbot_binary}\" update &> #{log_path} 2>&1")
|
162
|
+
end
|
163
|
+
else
|
164
|
+
spawn("\"#{turbot_binary}\" update", {:err => log_path, :out => log_path})
|
165
|
+
end
|
166
|
+
Process.detach(pid)
|
167
|
+
FileUtils.mkdir_p File.dirname(last_autoupdate_path)
|
168
|
+
FileUtils.touch last_autoupdate_path
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
data/lib/turbot.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "turbot/client"
|
2
|
+
require "turbot/updater"
|
3
|
+
require "turbot/version"
|
4
|
+
require "turbot_api"
|
5
|
+
require "turbot/errors"
|
6
|
+
|
7
|
+
module Turbot
|
8
|
+
|
9
|
+
USER_AGENT = "turbot-gem/#{Turbot::VERSION} (#{RUBY_PLATFORM}) ruby/#{RUBY_VERSION}"
|
10
|
+
|
11
|
+
def self.user_agent
|
12
|
+
@@user_agent ||= USER_AGENT
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.user_agent=(agent)
|
16
|
+
@@user_agent = agent
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|