Class: Azuki::Client::AzukiPostgresql

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/azuki/client/azuki_postgresql.rb

Direct Known Subclasses

AzukiPostgresql::Client

Constant Summary collapse

Version =
11

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#action, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty

Constructor Details

#initialize(attachment) ⇒ AzukiPostgresql

Returns a new instance of AzukiPostgresql.



19
20
21
22
23
24
25
# 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

Instance Attribute Details

#attachmentObject (readonly)

Returns the value of attribute attachment.



18
19
20
# File 'lib/azuki/client/azuki_postgresql.rb', line 18

def attachment
  @attachment
end

Class Method Details

.add_headers(headers) ⇒ Object



10
11
12
# File 'lib/azuki/client/azuki_postgresql.rb', line 10

def self.add_headers(headers)
  @headers.merge! headers
end

.headersObject



14
15
16
# File 'lib/azuki/client/azuki_postgresql.rb', line 14

def self.headers
  @headers
end

Instance Method Details

#azuki_postgresql_hostObject



27
28
29
30
31
32
33
34
35
36
37
# 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_resourceObject



43
44
45
46
47
48
49
50
# 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) ⇒ Object



64
65
66
67
# 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_statusObject



69
70
71
# File 'lib/azuki/client/azuki_postgresql.rb', line 69

def get_wait_status
  http_get "#{resource_name}/wait_status"
end

#ingressObject



52
53
54
# File 'lib/azuki/client/azuki_postgresql.rb', line 52

def ingress
  http_put "#{resource_name}/ingress"
end

#resetObject



56
57
58
# File 'lib/azuki/client/azuki_postgresql.rb', line 56

def reset
  http_put "#{resource_name}/reset"
end

#resource_nameObject



39
40
41
# File 'lib/azuki/client/azuki_postgresql.rb', line 39

def resource_name
  attachment.resource_name
end

#rotate_credentialsObject



60
61
62
# File 'lib/azuki/client/azuki_postgresql.rb', line 60

def rotate_credentials
  http_post "#{resource_name}/credentials_rotation"
end

#unfollowObject



73
74
75
# File 'lib/azuki/client/azuki_postgresql.rb', line 73

def unfollow
  http_put "#{resource_name}/unfollow"
end