turbot 0.1.36 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +15 -0
  5. data/.yardopts +3 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +22 -0
  8. data/README.md +44 -25
  9. data/Rakefile +16 -0
  10. data/appveyor.yml +35 -0
  11. data/bin/turbot +2 -16
  12. data/data/schema.json +134 -0
  13. data/{templates → data/templates}/LICENSE.txt +0 -0
  14. data/{templates → data/templates}/manifest.json +0 -0
  15. data/{templates → data/templates}/python/scraper.py +0 -0
  16. data/{templates → data/templates}/ruby/scraper.rb +0 -0
  17. data/dist/deb.rake +32 -0
  18. data/dist/gem.rake +16 -0
  19. data/dist/manifest.rake +9 -0
  20. data/dist/pkg.rake +60 -0
  21. data/dist/resources/deb/control +10 -0
  22. data/dist/resources/deb/postinst +45 -0
  23. data/dist/resources/deb/turbot +25 -0
  24. data/dist/resources/deb/turbot-release-key.txt +30 -0
  25. data/dist/resources/pkg/Distribution.erb +15 -0
  26. data/dist/resources/pkg/PackageInfo.erb +6 -0
  27. data/dist/resources/pkg/postinstall +45 -0
  28. data/dist/resources/pkg/turbot +24 -0
  29. data/dist/resources/tgz/turbot +24 -0
  30. data/dist/rpm.rake +35 -0
  31. data/dist/tgz.rake +26 -0
  32. data/dist/zip.rake +40 -0
  33. data/lib/turbot.rb +18 -15
  34. data/lib/turbot/cli.rb +10 -27
  35. data/lib/turbot/command.rb +59 -212
  36. data/lib/turbot/command/auth.rb +72 -34
  37. data/lib/turbot/command/base.rb +22 -61
  38. data/lib/turbot/command/bots.rb +251 -300
  39. data/lib/turbot/command/help.rb +57 -110
  40. data/lib/turbot/command/version.rb +6 -10
  41. data/lib/turbot/handlers/base_handler.rb +21 -0
  42. data/lib/turbot/handlers/dump_handler.rb +10 -0
  43. data/lib/turbot/handlers/preview_handler.rb +30 -0
  44. data/lib/turbot/handlers/validation_handler.rb +17 -0
  45. data/lib/turbot/helpers.rb +14 -482
  46. data/lib/turbot/helpers/api_helper.rb +41 -0
  47. data/lib/turbot/helpers/netrc_helper.rb +66 -0
  48. data/lib/turbot/helpers/shell_helper.rb +36 -0
  49. data/lib/turbot/version.rb +1 -1
  50. data/spec/fixtures/bad_permissions +0 -0
  51. data/spec/fixtures/empty +0 -0
  52. data/spec/fixtures/netrc +6 -0
  53. data/spec/spec_helper.rb +17 -219
  54. data/spec/support/bot_helper.rb +102 -0
  55. data/spec/support/command_helper.rb +20 -0
  56. data/spec/support/custom_matchers.rb +5 -0
  57. data/spec/support/fixture_helper.rb +9 -0
  58. data/spec/support/netrc_helper.rb +21 -0
  59. data/spec/turbot/command/auth_spec.rb +202 -20
  60. data/spec/turbot/command/base_spec.rb +22 -58
  61. data/spec/turbot/command/bots_spec.rb +580 -89
  62. data/spec/turbot/command/help_spec.rb +32 -75
  63. data/spec/turbot/command/version_spec.rb +11 -10
  64. data/spec/turbot/command_spec.rb +55 -87
  65. data/spec/turbot/helpers_spec.rb +28 -44
  66. data/turbot.gemspec +31 -0
  67. metadata +88 -178
  68. data/data/cacert.pem +0 -3988
  69. data/lib/turbot/auth.rb +0 -315
  70. data/lib/turbot/client.rb +0 -757
  71. data/lib/turbot/client/cisaurus.rb +0 -25
  72. data/lib/turbot/client/pgbackups.rb +0 -113
  73. data/lib/turbot/client/rendezvous.rb +0 -111
  74. data/lib/turbot/client/ssl_endpoint.rb +0 -25
  75. data/lib/turbot/client/turbot_postgresql.rb +0 -148
  76. data/lib/turbot/command/ssl.rb +0 -43
  77. data/lib/turbot/deprecated.rb +0 -5
  78. data/lib/turbot/deprecated/help.rb +0 -38
  79. data/lib/turbot/distribution.rb +0 -9
  80. data/lib/turbot/errors.rb +0 -28
  81. data/lib/turbot/excon.rb +0 -11
  82. data/lib/turbot/helpers/log_displayer.rb +0 -70
  83. data/lib/turbot/helpers/pg_dump_restore.rb +0 -115
  84. data/lib/turbot/helpers/turbot_postgresql.rb +0 -213
  85. data/lib/turbot/plugin.rb +0 -165
  86. data/lib/turbot/updater.rb +0 -171
  87. data/lib/vendor/turbot/okjson.rb +0 -598
  88. data/spec/helper/legacy_help.rb +0 -16
  89. data/spec/helper/pg_dump_restore_spec.rb +0 -67
  90. data/spec/spec.opts +0 -1
  91. data/spec/support/display_message_matcher.rb +0 -49
  92. data/spec/support/dummy_api.rb +0 -120
  93. data/spec/support/openssl_mock_helper.rb +0 -8
  94. data/spec/support/organizations_mock_helper.rb +0 -11
  95. data/spec/turbot/auth_spec.rb +0 -214
  96. data/spec/turbot/client/pgbackups_spec.rb +0 -43
  97. data/spec/turbot/client/rendezvous_spec.rb +0 -62
  98. data/spec/turbot/client/ssl_endpoint_spec.rb +0 -48
  99. data/spec/turbot/client/turbot_postgresql_spec.rb +0 -71
  100. data/spec/turbot/client_spec.rb +0 -548
  101. data/spec/turbot/helpers/turbot_postgresql_spec.rb +0 -181
  102. data/spec/turbot/plugin_spec.rb +0 -172
  103. data/spec/turbot/updater_spec.rb +0 -44
@@ -1,25 +0,0 @@
1
- require "turbot/client"
2
-
3
- class Turbot::Client::Cisaurus
4
-
5
- include Turbot::Helpers
6
-
7
- def initialize(uri)
8
- require 'rest_client'
9
- @uri = URI.parse(uri)
10
- end
11
-
12
- def authenticated_resource(path)
13
- host = "#{@uri.scheme}://#{@uri.host}"
14
- host += ":#{@uri.port}" if @uri.port
15
- RestClient::Resource.new("#{host}#{path}", "", Turbot::Auth.api_key)
16
- end
17
-
18
- def copy_slug(from, to)
19
- authenticated_resource("/v1/bots/#{from}/copy/#{to}").post(json_encode("description" => "Forked from #{from}"), :content_type => :json).headers[:location]
20
- end
21
-
22
- def job_done?(job_location)
23
- 202 != authenticated_resource(job_location).get.code
24
- end
25
- end
@@ -1,113 +0,0 @@
1
- require "turbot/client"
2
-
3
- class Turbot::Client::Pgbackups
4
-
5
- include Turbot::Helpers
6
-
7
- def initialize(uri)
8
- require 'rest_client'
9
- @uri = URI.parse(uri)
10
- end
11
-
12
- def authenticated_resource(path)
13
- host = "#{@uri.scheme}://#{@uri.host}"
14
- host += ":#{@uri.port}" if @uri.port
15
- RestClient::Resource.new("#{host}#{path}",
16
- :user => @uri.user,
17
- :password => @uri.password,
18
- :headers => {:x_turbot_gem_version => Turbot::Client.version}
19
- )
20
- end
21
-
22
- def create_transfer(from_url, from_name, to_url, to_name, opts={})
23
- # opts[:expire] => true will delete the oldest backup if at the plan limit
24
- resource = authenticated_resource("/client/transfers")
25
- params = {:from_url => from_url, :from_name => from_name, :to_url => to_url, :to_name => to_name}.merge opts
26
- json_decode post(resource, params).body
27
- end
28
-
29
- def get_transfers
30
- resource = authenticated_resource("/client/transfers")
31
- json_decode get(resource).body
32
- end
33
-
34
- def get_transfer(id)
35
- resource = authenticated_resource("/client/transfers/#{id}")
36
- json_decode get(resource).body
37
- end
38
-
39
- def get_backups(opts={})
40
- resource = authenticated_resource("/client/backups")
41
- json_decode get(resource).body
42
- end
43
-
44
- def get_backup(name, opts={})
45
- name = URI.escape(name)
46
- resource = authenticated_resource("/client/backups/#{name}")
47
- json_decode get(resource).body
48
- end
49
-
50
- def get_latest_backup
51
- resource = authenticated_resource("/client/latest_backup")
52
- json_decode get(resource).body
53
- end
54
-
55
- def delete_backup(name)
56
- name = URI.escape(name)
57
- begin
58
- resource = authenticated_resource("/client/backups/#{name}")
59
- delete(resource).body
60
- true
61
- rescue RestClient::ResourceNotFound => e
62
- false
63
- end
64
- end
65
-
66
- private
67
-
68
- def get(resource)
69
- check_errors do
70
- response = resource.get
71
- display_turbot_warning response
72
- response
73
- end
74
- end
75
-
76
- def post(resource, params)
77
- check_errors do
78
- response = resource.post(params)
79
- display_turbot_warning response
80
- response
81
- end
82
- end
83
-
84
- def delete(resource)
85
- check_errors do
86
- response = resource.delete
87
- display_turbot_warning response
88
- response
89
- end
90
- end
91
-
92
- def check_errors
93
- yield
94
- rescue RestClient::Unauthorized
95
- error "Invalid PGBACKUPS_URL"
96
- end
97
-
98
- def display_turbot_warning(response)
99
- warning = response.headers[:x_turbot_warning]
100
- display warning if warning
101
- response
102
- end
103
-
104
- end
105
-
106
- module Pgbackups
107
- class Client < Turbot::Client::Pgbackups
108
- def initialize(*args)
109
- Turbot::Helpers.deprecate "Pgbackups::Client has been deprecated. Please use Turbot::Client::Pgbackups instead."
110
- super
111
- end
112
- end
113
- end
@@ -1,111 +0,0 @@
1
- require "timeout"
2
- require "socket"
3
- require "uri"
4
- require "turbot/auth"
5
- require "turbot/client"
6
- require "turbot/helpers"
7
-
8
- class Turbot::Client::Rendezvous
9
-
10
- include Turbot::Helpers
11
-
12
- attr_reader :rendezvous_url, :connect_timeout, :activity_timeout, :input, :output, :on_connect
13
-
14
- def initialize(opts)
15
- @rendezvous_url = opts[:rendezvous_url]
16
- @connect_timeout = opts[:connect_timeout]
17
- @activity_timeout = opts[:activity_timeout]
18
- @input = opts[:input]
19
- @output = opts[:output]
20
- end
21
-
22
- def on_connect(&blk)
23
- @on_connect = blk if block_given?
24
- @on_connect
25
- end
26
-
27
- def start
28
- uri = URI.parse(rendezvous_url)
29
- host, port, secret = uri.host, uri.port, uri.path[1..-1]
30
-
31
- ssl_socket = Timeout.timeout(connect_timeout) do
32
- ssl_context = OpenSSL::SSL::SSLContext.new
33
- ssl_context.ssl_version = :TLSv1
34
-
35
- if Turbot::Auth.verify_host?(host)
36
- ssl_context.ca_file = File.expand_path("../../../../data/cacert.pem", __FILE__)
37
- ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
38
- end
39
-
40
- tcp_socket = TCPSocket.open(host, port)
41
- ssl_socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl_context)
42
- ssl_socket.connect
43
- ssl_socket.puts(secret)
44
- ssl_socket.readline
45
- ssl_socket
46
- end
47
-
48
- on_connect.call if on_connect
49
-
50
- readables = [input, ssl_socket].compact
51
-
52
- begin
53
- loop do
54
- if o = IO.select(readables, nil, nil, activity_timeout)
55
- if (input && (o.first.first == input))
56
- begin
57
- data = input.readpartial(10000)
58
- rescue EOFError
59
- ssl_socket.write(4.chr)
60
- ssl_socket.flush
61
- readables.delete(input)
62
- next
63
- end
64
- if running_on_windows?
65
- data.gsub!("\r\n", "\n") # prevent double CRs
66
- end
67
- ssl_socket.write(data)
68
- ssl_socket.flush
69
- elsif (o.first.first == ssl_socket)
70
- begin
71
- data = ssl_socket.readpartial(10000)
72
- rescue EOFError
73
- break
74
- end
75
- output.write(fixup(data))
76
- end
77
- else
78
- raise(Timeout::Error.new)
79
- end
80
- end
81
- rescue Interrupt
82
- ssl_socket.write(3.chr)
83
- ssl_socket.flush
84
- retry
85
- rescue SignalException => e
86
- if Signal.list["QUIT"] == e.signo
87
- ssl_socket.write(28.chr)
88
- ssl_socket.flush
89
- retry
90
- end
91
- raise
92
- rescue Errno::EIO
93
- end
94
- end
95
-
96
- private
97
-
98
- def fixup(data)
99
- return nil if ! data
100
- if data.respond_to?(:force_encoding)
101
- data.force_encoding('utf-8') if data.respond_to?(:force_encoding)
102
- end
103
- if running_on_windows?
104
- begin
105
- data.gsub!(/\e\[[\d;]+m/, '')
106
- rescue # ignore failed gsub, for instance when non-utf8
107
- end
108
- end
109
- output.isatty ? data : data.gsub(/\cM/,"")
110
- end
111
- end
@@ -1,25 +0,0 @@
1
- class Turbot::Client
2
- def ssl_endpoint_add(bot, pem, key)
3
- json_decode(post("bots/#{bot}/ssl-endpoints", :accept => :json, :pem => pem, :key => key).to_s)
4
- end
5
-
6
- def ssl_endpoint_info(bot, cname)
7
- json_decode(get("bots/#{bot}/ssl-endpoints/#{escape(cname)}", :accept => :json).to_s)
8
- end
9
-
10
- def ssl_endpoint_list(bot)
11
- json_decode(get("bots/#{bot}/ssl-endpoints", :accept => :json).to_s)
12
- end
13
-
14
- def ssl_endpoint_remove(bot, cname)
15
- json_decode(delete("bots/#{bot}/ssl-endpoints/#{escape(cname)}", :accept => :json).to_s)
16
- end
17
-
18
- def ssl_endpoint_rollback(bot, cname)
19
- json_decode(post("bots/#{bot}/ssl-endpoints/#{escape(cname)}/rollback", :accept => :json).to_s)
20
- end
21
-
22
- def ssl_endpoint_update(bot, cname, pem, key)
23
- json_decode(put("bots/#{bot}/ssl-endpoints/#{escape(cname)}", :accept => :json, :pem => pem, :key => key).to_s)
24
- end
25
- end
@@ -1,148 +0,0 @@
1
- require "turbot/client"
2
-
3
- class Turbot::Client::TurbotPostgresql
4
- Version = 11
5
-
6
- include Turbot::Helpers
7
-
8
- @headers = { :x_turbot_gem_version => Turbot::Client.version }
9
-
10
- def self.add_headers(headers)
11
- @headers.merge! headers
12
- end
13
-
14
- def self.headers
15
- @headers
16
- end
17
-
18
- attr_reader :attachment
19
- def initialize(attachment)
20
- @attachment = attachment
21
- require 'rest_client'
22
- end
23
-
24
- def turbot_postgresql_host
25
- if attachment.starter_plan?
26
- determine_host(ENV["TURBOT_POSTGRESQL_HOST"], "postgres-starter-api.turbot.com")
27
- else
28
- if ENV['SHOGUN']
29
- "shogun-#{ENV['SHOGUN']}.turbotapp.com"
30
- else
31
- determine_host(ENV["TURBOT_POSTGRESQL_HOST"], "postgres-api.turbot.com")
32
- end
33
- end
34
- end
35
-
36
- def resource_name
37
- attachment.resource_name
38
- end
39
-
40
- def turbot_postgresql_resource
41
- RestClient::Resource.new(
42
- "https://#{turbot_postgresql_host}/client/v11/databases",
43
- :user => Turbot::Auth.user,
44
- :password => Turbot::Auth.password,
45
- :headers => self.class.headers
46
- )
47
- end
48
-
49
- def ingress
50
- http_put "#{resource_name}/ingress"
51
- end
52
-
53
- def reset
54
- http_put "#{resource_name}/reset"
55
- end
56
-
57
- def rotate_credentials
58
- http_post "#{resource_name}/credentials_rotation"
59
- end
60
-
61
- def get_database(extended=false)
62
- query = extended ? '?extended=true' : ''
63
- http_get resource_name + query
64
- end
65
-
66
- def get_wait_status
67
- http_get "#{resource_name}/wait_status"
68
- end
69
-
70
- def unfollow
71
- http_put "#{resource_name}/unfollow"
72
- end
73
-
74
- protected
75
-
76
- def sym_keys(c)
77
- if c.is_a?(Array)
78
- c.map { |e| sym_keys(e) }
79
- else
80
- c.inject({}) do |h, (k, v)|
81
- h[k.to_sym] = v; h
82
- end
83
- end
84
- end
85
-
86
- def checking_client_version
87
- begin
88
- yield
89
- rescue RestClient::BadRequest => e
90
- if message = json_decode(e.response.to_s)["upgrade_message"]
91
- abort(message)
92
- else
93
- raise e
94
- end
95
- end
96
- end
97
-
98
- def display_turbot_warning(response)
99
- warning = response.headers[:x_turbot_warning]
100
- display warning if warning
101
- response
102
- end
103
-
104
- def http_get(path)
105
- checking_client_version do
106
- retry_on_exception(RestClient::Exception) do
107
- response = turbot_postgresql_resource[path].get
108
- display_turbot_warning response
109
- sym_keys(json_decode(response.to_s))
110
- end
111
- end
112
- end
113
-
114
- def http_post(path, payload = {})
115
- checking_client_version do
116
- response = turbot_postgresql_resource[path].post(json_encode(payload))
117
- display_turbot_warning response
118
- sym_keys(json_decode(response.to_s))
119
- end
120
- end
121
-
122
- def http_put(path, payload = {})
123
- checking_client_version do
124
- response = turbot_postgresql_resource[path].put(json_encode(payload))
125
- display_turbot_warning response
126
- sym_keys(json_decode(response.to_s))
127
- end
128
- end
129
-
130
- private
131
-
132
- def determine_host(value, default)
133
- if value.nil?
134
- default
135
- else
136
- "#{value}.turbotapp.com"
137
- end
138
- end
139
- end
140
-
141
- module TurbotPostgresql
142
- class Client < Turbot::Client::TurbotPostgresql
143
- def initialize(*args)
144
- Turbot::Helpers.deprecate "TurbotPostgresql::Client has been deprecated. Please use Turbot::Client::TurbotPostgresql instead."
145
- super
146
- end
147
- end
148
- end
@@ -1,43 +0,0 @@
1
- require "turbot/command/base"
2
-
3
- module Turbot::Command
4
-
5
- # DEPRECATED: see `turbot certs` instead
6
- #
7
- # manage ssl certificates for an bot
8
- #
9
- class Ssl < Base
10
-
11
- # ssl
12
- #
13
- # list legacy certificates for an bot
14
- #
15
- def index
16
- api.get_domains(bot).body.each do |domain|
17
- if cert = domain['cert']
18
- display "#{domain['domain']} has a SSL certificate registered to #{cert['subject']} which expires on #{format_date(cert['expires_at'])}"
19
- else
20
- display "#{domain['domain']} has no certificate"
21
- end
22
- end
23
- end
24
-
25
- # ssl:add PEM KEY
26
- #
27
- # DEPRECATED: see `turbot certs:add` instead
28
- #
29
- def add
30
- $stderr.puts " ! `turbot ssl:add` has been deprecated. Please use the SSL Endpoint add-on and the `turbot certs` commands instead."
31
- $stderr.puts " ! SSL Endpoint documentation is available at: https://devcenter.turbot.com/articles/ssl-endpoint"
32
- end
33
-
34
- # ssl:clear
35
- #
36
- # remove legacy ssl certificates from an bot
37
- #
38
- def clear
39
- turbot.clear_ssl(bot)
40
- display "Cleared certificates for #{bot}"
41
- end
42
- end
43
- end