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.
Files changed (71) hide show
  1. checksums.yaml +15 -0
  2. data/README.md +36 -0
  3. data/bin/turbot +17 -0
  4. data/data/cacert.pem +3988 -0
  5. data/lib/turbot/auth.rb +315 -0
  6. data/lib/turbot/cli.rb +38 -0
  7. data/lib/turbot/client/cisaurus.rb +25 -0
  8. data/lib/turbot/client/pgbackups.rb +113 -0
  9. data/lib/turbot/client/rendezvous.rb +111 -0
  10. data/lib/turbot/client/ssl_endpoint.rb +25 -0
  11. data/lib/turbot/client/turbot_postgresql.rb +148 -0
  12. data/lib/turbot/client.rb +757 -0
  13. data/lib/turbot/command/auth.rb +85 -0
  14. data/lib/turbot/command/base.rb +192 -0
  15. data/lib/turbot/command/bots.rb +326 -0
  16. data/lib/turbot/command/config.rb +123 -0
  17. data/lib/turbot/command/help.rb +179 -0
  18. data/lib/turbot/command/keys.rb +115 -0
  19. data/lib/turbot/command/logs.rb +34 -0
  20. data/lib/turbot/command/ssl.rb +43 -0
  21. data/lib/turbot/command/status.rb +51 -0
  22. data/lib/turbot/command/update.rb +47 -0
  23. data/lib/turbot/command/version.rb +23 -0
  24. data/lib/turbot/command.rb +304 -0
  25. data/lib/turbot/deprecated/help.rb +38 -0
  26. data/lib/turbot/deprecated.rb +5 -0
  27. data/lib/turbot/distribution.rb +9 -0
  28. data/lib/turbot/errors.rb +28 -0
  29. data/lib/turbot/excon.rb +11 -0
  30. data/lib/turbot/helpers/log_displayer.rb +70 -0
  31. data/lib/turbot/helpers/pg_dump_restore.rb +115 -0
  32. data/lib/turbot/helpers/turbot_postgresql.rb +213 -0
  33. data/lib/turbot/helpers.rb +521 -0
  34. data/lib/turbot/plugin.rb +165 -0
  35. data/lib/turbot/updater.rb +171 -0
  36. data/lib/turbot/version.rb +3 -0
  37. data/lib/turbot.rb +19 -0
  38. data/lib/vendor/turbot/okjson.rb +598 -0
  39. data/spec/helper/legacy_help.rb +16 -0
  40. data/spec/helper/pg_dump_restore_spec.rb +67 -0
  41. data/spec/schemas/dummy_schema.json +12 -0
  42. data/spec/spec.opts +1 -0
  43. data/spec/spec_helper.rb +220 -0
  44. data/spec/support/display_message_matcher.rb +49 -0
  45. data/spec/support/dummy_api.rb +120 -0
  46. data/spec/support/openssl_mock_helper.rb +8 -0
  47. data/spec/support/organizations_mock_helper.rb +11 -0
  48. data/spec/turbot/auth_spec.rb +214 -0
  49. data/spec/turbot/client/pgbackups_spec.rb +43 -0
  50. data/spec/turbot/client/rendezvous_spec.rb +62 -0
  51. data/spec/turbot/client/ssl_endpoint_spec.rb +48 -0
  52. data/spec/turbot/client/turbot_postgresql_spec.rb +71 -0
  53. data/spec/turbot/client_spec.rb +548 -0
  54. data/spec/turbot/command/auth_spec.rb +38 -0
  55. data/spec/turbot/command/base_spec.rb +66 -0
  56. data/spec/turbot/command/bots_spec.rb +54 -0
  57. data/spec/turbot/command/config_spec.rb +143 -0
  58. data/spec/turbot/command/help_spec.rb +90 -0
  59. data/spec/turbot/command/keys_spec.rb +117 -0
  60. data/spec/turbot/command/logs_spec.rb +60 -0
  61. data/spec/turbot/command/status_spec.rb +48 -0
  62. data/spec/turbot/command/version_spec.rb +16 -0
  63. data/spec/turbot/command_spec.rb +131 -0
  64. data/spec/turbot/helpers/turbot_postgresql_spec.rb +181 -0
  65. data/spec/turbot/helpers_spec.rb +48 -0
  66. data/spec/turbot/plugin_spec.rb +172 -0
  67. data/spec/turbot/updater_spec.rb +44 -0
  68. data/templates/manifest.json +7 -0
  69. data/templates/scraper.py +5 -0
  70. data/templates/scraper.rb +6 -0
  71. metadata +199 -0
@@ -0,0 +1,148 @@
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