class Azuki::Client::AzukiPostgresql
Constants
- Version
Attributes
attachment[R]
Public Class Methods
add_headers(headers)
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 10 def self.add_headers(headers) @headers.merge! headers end
headers()
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 14 def self.headers @headers end
new(attachment)
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 19 def initialize(attachment) @attachment = attachment if attachment.resource_name == 'SHARED_DATABASE' error('This command is not available for shared database') end require 'rest_client' end
Public Instance Methods
azuki_postgresql_host()
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 27 def azuki_postgresql_host if attachment.starter_plan? ENV["AZUKI_POSTGRESQL_HOST"] || "postgres-starter-api" else if ENV['SHOGUN'] "shogun-#{ENV['SHOGUN']}" else ENV["AZUKI_POSTGRESQL_HOST"] || "postgres-api" end end end
azuki_postgresql_resource()
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 43 def azuki_postgresql_resource RestClient::Resource.new( "https://#{azuki_postgresql_host}.azukiapp.com/client/v11/databases", :user => Azuki::Auth.user, :password => Azuki::Auth.password, :headers => self.class.headers ) end
get_database(extended=false)
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 64 def get_database(extended=false) query = extended ? '?extended=true' : '' http_get resource_name + query end
get_wait_status()
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 69 def get_wait_status http_get "#{resource_name}/wait_status" end
ingress()
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 52 def ingress http_put "#{resource_name}/ingress" end
reset()
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 56 def reset http_put "#{resource_name}/reset" end
resource_name()
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 39 def resource_name attachment.resource_name end
rotate_credentials()
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 60 def rotate_credentials http_post "#{resource_name}/credentials_rotation" end
unfollow()
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 73 def unfollow http_put "#{resource_name}/unfollow" end
Protected Instance Methods
checking_client_version() { || ... }
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 89 def checking_client_version begin yield rescue RestClient::BadRequest => e if message = json_decode(e.response.to_s)["upgrade_message"] abort(message) else raise e end end end
display_azuki_warning(response)
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 101 def display_azuki_warning(response) warning = response.headers[:x_azuki_warning] display warning if warning response end
http_get(path)
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 107 def http_get(path) checking_client_version do retry_on_exception(RestClient::Exception) do response = azuki_postgresql_resource[path].get display_azuki_warning response sym_keys(json_decode(response.to_s)) end end end
http_post(path, payload = {})
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 117 def http_post(path, payload = {}) checking_client_version do response = azuki_postgresql_resource[path].post(json_encode(payload)) display_azuki_warning response sym_keys(json_decode(response.to_s)) end end
http_put(path, payload = {})
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 125 def http_put(path, payload = {}) checking_client_version do response = azuki_postgresql_resource[path].put(json_encode(payload)) display_azuki_warning response sym_keys(json_decode(response.to_s)) end end
sym_keys(c)
click to toggle source
# File lib/azuki/client/azuki_postgresql.rb, line 79 def sym_keys(c) if c.is_a?(Array) c.map { |e| sym_keys(e) } else c.inject({}) do |h, (k, v)| h[k.to_sym] = v; h end end end