class Rockette::Viewer

View resources

Public Class Methods

new() click to toggle source
# File lib/rockette/controller/viewer.rb, line 10
def initialize
  @conf = Psych.load(File.read(CONF))
  @pastel = Pastel.new
  @prompt = TTY::Prompt.new
  @spinner = TTY::Spinner.new # ("[:spinner] Loading APEX environments ...", format: pulse_2)
  @view_actions = { "🏔  APEX Environments" => 1, "🎭 Registered Applications" => 2, "⬅️  Go Back" => 3 }
end

Public Instance Methods

ape_e_i(uri) click to toggle source
# File lib/rockette/controller/viewer.rb, line 51
def ape_e_i(uri)
  response = Rester.new(url: uri).rest_try
  bail unless response
  abort padder("#{uri} didn't work. Received: #{response.code}") unless response.code == 200
  response
end
applications(url) click to toggle source
# File lib/rockette/controller/viewer.rb, line 58
def applications(url)
  uri = "#{url}deploy/apps"
  response = ape_e_i(uri)
  JSON.parse(response.body)["items"]
end
do_action(action) click to toggle source
# File lib/rockette/controller/viewer.rb, line 31
def do_action(action)
  case action
  when 1
    puts
    environments unless @table_env
    @spinner.auto_spin
    sleep(1)
    @spinner.stop
    puts @table_env.render(:ascii)
    puts
  when 2
    puts
    registered unless @table_reg
    puts @table_reg.render(:ascii)
    puts
  else
    puts "\nI don't understand that command.\n\n"
  end
end
environments() click to toggle source
# File lib/rockette/controller/viewer.rb, line 64
def environments
  uri = "#{@conf["rockette"]["controller_url"]}deploy/environments/"
  response = ape_e_i(uri)
  @table_env = TTY::Table.new(header: ["Environment Name", "API", "Domain", "Owner", "Workspace"])
  items = JSON.parse(response.body)["items"]
  items.each { |h| @table_env << [h["name"], h["deployment_api"], h["domain"], h["owner"], h["workspace"]] }
end
launch!() click to toggle source
# File lib/rockette/controller/viewer.rb, line 18
def launch!
  puts padder("You can view environments or registered applications")
  puts

  # input/action loop
  loop do
    action = @prompt.select("Which would you like to see?", @view_actions)
    break if action == 3

    do_action(action)
  end
end
registered() click to toggle source
# File lib/rockette/controller/viewer.rb, line 72
def registered
  uri = "#{@conf["rockette"]["controller_url"]}deploy/registered_apps/"
  response = ape_e_i(uri)
  @table_reg = TTY::Table.new(header: ["Registered Name", "Source App ID", "Source URI", "Target App ID",
                                       "Target URI"])
  JSON.parse(response.body)["items"].each do |h|
    @table_reg << [h["registered_name"], h["src_app_id"], h["src_url"], h["tgt_app_id"], h["tgt_url"]]
  end
end