Class: Harbor::CLI::Servers

Inherits:
Object
  • Object
show all
Defined in:
lib/harbor/cli/servers.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, config) ⇒ Servers

Returns a new instance of Servers.



6
7
8
9
10
# File 'lib/harbor/cli/servers.rb', line 6

def initialize(options, config)
  @options = options
  @config = config
  @tools = Harbor::Tools.new(config)
end

Instance Method Details

#audit(project_name = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/harbor/cli/servers.rb', line 37

def audit(project_name = nil)
  # Audit reads from the local SQLite audit.db. It's a pure local read,
  # not a fleet/host operation, so it doesn't go through the kernel
  # boundary (per premise P2: the kernel is for "anything that touches
  # a host or the fleet"). It emits no events because viewing history
  # isn't itself an auditable operation.
  audit_log = AuditLog.new(@config.audit_db_path)
  entries = audit_log.query(project: project_name, limit: @options["limit"] || 20)

  if entries.empty?
    $stdout.puts "No audit entries found."
    return
  end

  $stdout.puts format("%-20s %-12s %-12s %-10s %-8s %s", "Timestamp", "Project", "Operation", "Dest", "Status", "Duration")
  $stdout.puts "-" * 80

  entries.each do |e|
    duration = e["duration_ms"] ? "#{e['duration_ms']}ms" : "-"
    $stdout.puts format("%-20s %-12s %-12s %-10s %-8s %s",
      e["timestamp"][0..18], e["project"], e["operation"],
      e["destination"] || "-", e["status"], duration)
  end
ensure
  audit_log&.close
end

#details(project_name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/harbor/cli/servers.rb', line 24

def details(project_name)
  output = @tools.call(
    "harbor_details",
    { "project" => project_name, "destination" => @options["destination"] },
    actor: cli_actor,
    origin: :cli
  )
  $stdout.puts output
rescue Harbor::Error => e
  $stderr.puts "#{e.class.name.split('::').last}: #{e.message}"
  exit 1
end

#status(project_name = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/harbor/cli/servers.rb', line 12

def status(project_name = nil)
  if project_name
    show_project_status(project_name)
  else
    @config.projects.each do |project|
      $stdout.puts "#{project.name}:"
      show_project_status(project.name)
      $stdout.puts ""
    end
  end
end