Class: NeetoDeploy::CLI::Certificates::List

Inherits:
Base
  • Object
show all
Includes:
Constants, Session
Defined in:
lib/neeto_deploy/cli/certificates/list.rb

Constant Summary

Constants included from Session

Session::CONSOLE_EXECUTABLE

Instance Attribute Summary collapse

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods included from Constants

#certificates_url

Methods included from Session

#auth_headers, #console_executable_name, #json_auth_headers, #os, require_app_option, #send_delete_request, #send_get_request, #send_patch_request, #send_post_request

Methods inherited from Base

#create_config_dir

Constructor Details

#initialize(options:) ⇒ List

Returns a new instance of List.



18
19
20
21
# File 'lib/neeto_deploy/cli/certificates/list.rb', line 18

def initialize(options:)
  super()
  @app_slug = options[:app]
end

Instance Attribute Details

#app_slugObject (readonly)

Returns the value of attribute app_slug.



16
17
18
# File 'lib/neeto_deploy/cli/certificates/list.rb', line 16

def app_slug
  @app_slug
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/neeto_deploy/cli/certificates/list.rb', line 23

def run
  ui.execute_with_loading("Fetching certificates...") do
    @response = send_get_request(certificates_url, { app_slug: })
  end

  ui.error(@response["error"] || @response.message) and return unless @response.success?

  certificates = JSON.parse(@response.body)["certificates"]

  if certificates.nil? || certificates.empty?
    ui.info("No certificates found for #{app_slug}.")
    return
  end

  rows = certificates.map do |cert|
    domains = Array(cert["domains"]).map { |d| d["hostname"] }.join(", ")
    expiring_soon = cert["expires_before_30_days"] ? " (expiring soon)" : ""
    [cert["name"], cert["expiration"], domains + expiring_soon]
  end

  table = Terminal::Table.new(headings: ["Name", "Expiration", "Domains"], rows: rows)
  ui.info(table)
end