turbot 0.1.36 → 0.2.3
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 +4 -4
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/.yardopts +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +44 -25
- data/Rakefile +16 -0
- data/appveyor.yml +35 -0
- data/bin/turbot +2 -16
- data/data/schema.json +134 -0
- data/{templates → data/templates}/LICENSE.txt +0 -0
- data/{templates → data/templates}/manifest.json +0 -0
- data/{templates → data/templates}/python/scraper.py +0 -0
- data/{templates → data/templates}/ruby/scraper.rb +0 -0
- data/dist/deb.rake +32 -0
- data/dist/gem.rake +16 -0
- data/dist/manifest.rake +9 -0
- data/dist/pkg.rake +60 -0
- data/dist/resources/deb/control +10 -0
- data/dist/resources/deb/postinst +45 -0
- data/dist/resources/deb/turbot +25 -0
- data/dist/resources/deb/turbot-release-key.txt +30 -0
- data/dist/resources/pkg/Distribution.erb +15 -0
- data/dist/resources/pkg/PackageInfo.erb +6 -0
- data/dist/resources/pkg/postinstall +45 -0
- data/dist/resources/pkg/turbot +24 -0
- data/dist/resources/tgz/turbot +24 -0
- data/dist/rpm.rake +35 -0
- data/dist/tgz.rake +26 -0
- data/dist/zip.rake +40 -0
- data/lib/turbot.rb +18 -15
- data/lib/turbot/cli.rb +10 -27
- data/lib/turbot/command.rb +59 -212
- data/lib/turbot/command/auth.rb +72 -34
- data/lib/turbot/command/base.rb +22 -61
- data/lib/turbot/command/bots.rb +251 -300
- data/lib/turbot/command/help.rb +57 -110
- data/lib/turbot/command/version.rb +6 -10
- data/lib/turbot/handlers/base_handler.rb +21 -0
- data/lib/turbot/handlers/dump_handler.rb +10 -0
- data/lib/turbot/handlers/preview_handler.rb +30 -0
- data/lib/turbot/handlers/validation_handler.rb +17 -0
- data/lib/turbot/helpers.rb +14 -482
- data/lib/turbot/helpers/api_helper.rb +41 -0
- data/lib/turbot/helpers/netrc_helper.rb +66 -0
- data/lib/turbot/helpers/shell_helper.rb +36 -0
- data/lib/turbot/version.rb +1 -1
- data/spec/fixtures/bad_permissions +0 -0
- data/spec/fixtures/empty +0 -0
- data/spec/fixtures/netrc +6 -0
- data/spec/spec_helper.rb +17 -219
- data/spec/support/bot_helper.rb +102 -0
- data/spec/support/command_helper.rb +20 -0
- data/spec/support/custom_matchers.rb +5 -0
- data/spec/support/fixture_helper.rb +9 -0
- data/spec/support/netrc_helper.rb +21 -0
- data/spec/turbot/command/auth_spec.rb +202 -20
- data/spec/turbot/command/base_spec.rb +22 -58
- data/spec/turbot/command/bots_spec.rb +580 -89
- data/spec/turbot/command/help_spec.rb +32 -75
- data/spec/turbot/command/version_spec.rb +11 -10
- data/spec/turbot/command_spec.rb +55 -87
- data/spec/turbot/helpers_spec.rb +28 -44
- data/turbot.gemspec +31 -0
- metadata +88 -178
- data/data/cacert.pem +0 -3988
- data/lib/turbot/auth.rb +0 -315
- data/lib/turbot/client.rb +0 -757
- data/lib/turbot/client/cisaurus.rb +0 -25
- data/lib/turbot/client/pgbackups.rb +0 -113
- data/lib/turbot/client/rendezvous.rb +0 -111
- data/lib/turbot/client/ssl_endpoint.rb +0 -25
- data/lib/turbot/client/turbot_postgresql.rb +0 -148
- data/lib/turbot/command/ssl.rb +0 -43
- data/lib/turbot/deprecated.rb +0 -5
- data/lib/turbot/deprecated/help.rb +0 -38
- data/lib/turbot/distribution.rb +0 -9
- data/lib/turbot/errors.rb +0 -28
- data/lib/turbot/excon.rb +0 -11
- data/lib/turbot/helpers/log_displayer.rb +0 -70
- data/lib/turbot/helpers/pg_dump_restore.rb +0 -115
- data/lib/turbot/helpers/turbot_postgresql.rb +0 -213
- data/lib/turbot/plugin.rb +0 -165
- data/lib/turbot/updater.rb +0 -171
- data/lib/vendor/turbot/okjson.rb +0 -598
- data/spec/helper/legacy_help.rb +0 -16
- data/spec/helper/pg_dump_restore_spec.rb +0 -67
- data/spec/spec.opts +0 -1
- data/spec/support/display_message_matcher.rb +0 -49
- data/spec/support/dummy_api.rb +0 -120
- data/spec/support/openssl_mock_helper.rb +0 -8
- data/spec/support/organizations_mock_helper.rb +0 -11
- data/spec/turbot/auth_spec.rb +0 -214
- data/spec/turbot/client/pgbackups_spec.rb +0 -43
- data/spec/turbot/client/rendezvous_spec.rb +0 -62
- data/spec/turbot/client/ssl_endpoint_spec.rb +0 -48
- data/spec/turbot/client/turbot_postgresql_spec.rb +0 -71
- data/spec/turbot/client_spec.rb +0 -548
- data/spec/turbot/helpers/turbot_postgresql_spec.rb +0 -181
- data/spec/turbot/plugin_spec.rb +0 -172
- 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
         | 
    
        data/lib/turbot/command/ssl.rb
    DELETED
    
    | @@ -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
         |