Class: Deploio::Commands::PostgreSQL

Inherits:
Thor
  • Object
show all
Includes:
SharedOptions
Defined in:
lib/deploio/commands/postgresql.rb

Instance Method Summary collapse

Methods included from SharedOptions

included

Instance Method Details

#info(name) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/deploio/commands/postgresql.rb', line 50

def info(name)
  setup_options
  resolver = PgDatabaseResolver.new(nctl_client: @nctl)
  db_ref = resolver.resolve(database_name: name)
  data = @nctl.get_pg_database(db_ref)

  if options[:json]
    puts JSON.pretty_generate(data)
    return
  end

  kind = data["kind"]
   = data["metadata"] || {}
  spec = data["spec"] || {}
  for_provider = spec["forProvider"] || {}
  status = data["status"] || {}
  at_provider = status["atProvider"] || {}

  Output.header("PostgreSQL Database: #{db_ref.full_name}")
  puts

  Output.header("General")
  Output.table([
    ["Name", presence(["name"])],
    ["Project", presence(["namespace"])],
    ["Kind", presence(kind, default: "-")],
    ["Version", presence(for_provider["version"], default: "?")],
    ["FQDN", presence(at_provider["fqdn"])],
    ["Size", presence(at_provider["size"], default: "-")]
  ])

  puts

  Output.header("Status")
  conditions = status["conditions"] || []
  ready_condition = conditions.find { |c| c["type"] == "Ready" }
  synced_condition = conditions.find { |c| c["type"] == "Synced" }

  Output.table([
    ["Ready", presence(ready_condition&.dig("status"))],
    ["Synced", presence(synced_condition&.dig("status"))]
  ])

  if for_provider["allowedCIDRs"].is_a?(Array)
    puts

    Output.header("Access")
    Output.table([
      ["Allowed CIDRs", for_provider["allowedCIDRs"].join(", ")]
    ])

    puts

    Output.header("SSH Keys")
    for_provider["sshKeys"].each do |key|
      puts "- #{key}"
    end
  end
rescue Deploio::Error => e
  Output.error(e.message)
  exit 1
end

#listObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/deploio/commands/postgresql.rb', line 13

def list
  setup_options
  raw_dbs = @nctl.get_all_pg_databases

  if options[:json]
    puts JSON.pretty_generate(raw_dbs)
    return
  end

  if raw_dbs.empty?
    Output.warning("No PostgreSQL databases found") unless merged_options[:dry_run]
    return
  end

  resolver = PgDatabaseResolver.new(nctl_client: @nctl)

  rows = raw_dbs.map do |pg|
    kind = pg["kind"] || ""
     = pg["metadata"] || {}
    spec = pg["spec"] || {}
    for_provider = spec["forProvider"] || {}
    version = for_provider["version"]
    namespace = ["namespace"] || ""
    name = ["name"] || ""

    [
      resolver.short_name_for(namespace, name),
      project_from_namespace(namespace, resolver.current_org),
      presence(kind, default: "-"),
      presence(version, default: "?")
    ]
  end

  Output.table(rows, headers: ["NAME", "PROJECT", "KIND", "VERSION"])
end