Class: Captive::DashboardClient

Inherits:
Object
  • Object
show all
Defined in:
lib/captive/dashboard_client.rb

Constant Summary collapse

DASHBOARD_URL =
"https://dashboard.captive.dev"
TOKEN_PATH =
File.expand_path("~/.config/captive/token")
PAGE_SIZE =
500

Instance Method Summary collapse

Instance Method Details

#logs(app, start_at: nil, end_at: nil, limit: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/captive/dashboard_client.rb', line 16

def logs(app, start_at: nil, end_at: nil, limit: nil)
  token = read_token

  if start_at || end_at
    fetch_all(app, token, start_at:, end_at:)
  else
    uri      = build_uri(app, limit: limit || PAGE_SIZE)
    response = get(uri, token)
    page, _  = extract_page(handle_response(response))
    page
  end
end

#record_activity(app, kind:, command: nil, session: nil) ⇒ Object

Signale au dashboard un accès ouvert sur l'app. L'acteur n'est pas transmis : le dashboard le dérive du token, ce qui le rend infalsifiable côté client.



31
32
33
34
35
36
37
38
# File 'lib/captive/dashboard_client.rb', line 31

def record_activity(app, kind:, command: nil, session: nil)
  uri  = URI.parse("#{DASHBOARD_URL}/api/apps/#{URI.encode_uri_component(app)}/activity")
  body = { kind: kind }
  body[:command] = command if command
  body[:session] = session if session

  post(uri, read_token, body)
end