Class: RooOnRails::Checks::Papertrail::Token

Inherits:
Base
  • Object
show all
Defined in:
lib/roo_on_rails/checks/papertrail/token.rb

Overview

Output context:

  • papertrail.client: a connected Papertrail client

Instance Method Summary collapse

Methods inherited from Base

requires, #run

Methods included from Helpers

#bold, included

Constructor Details

#initialize(papertrail_client: nil, **options) ⇒ Token

Returns a new instance of Token.



15
16
17
18
# File 'lib/roo_on_rails/checks/papertrail/token.rb', line 15

def initialize(papertrail_client: nil, **options)
  @papertrail_client = papertrail_client || PapertrailClient
  super(**options)
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/roo_on_rails/checks/papertrail/token.rb', line 24

def call
  status, token = shell.run 'git config papertrail.token'
  fail! 'no Papertrail API token configured' if token.strip.empty? || !status
  token.strip!

  client = @papertrail_client.new(token: token)
  begin
    client.list_destinations
  rescue Faraday::ClientError => e
    fail! "connecting to Papertrail failed (#{e.message})"
  end

  pass "connected to Papertrail's API"
  context.papertrail!.client = client
end

#fixObject



40
41
42
43
44
45
46
# File 'lib/roo_on_rails/checks/papertrail/token.rb', line 40

def fix
  say 'Enter your Papertrail API token:'
  say 'This can be found at https://papertrailapp.com/account/profile'
  say '(the token will not be echoed on the terminal; paste and press enter)'
  token = IO.console.getpass.strip
  system "git config papertrail.token #{Shellwords.shellescape token}"
end

#introObject



20
21
22
# File 'lib/roo_on_rails/checks/papertrail/token.rb', line 20

def intro
  'Obtaining Papertrail auth token...'
end