Class: Boxen::Preflight::Creds

Inherits:
Boxen::Preflight show all
Defined in:
lib/boxen/preflight/creds.rb

Instance Attribute Summary

Attributes inherited from Check

#config

Instance Method Summary collapse

Methods inherited from Check

#abort, checks, #initialize, register, run, #warn

Constructor Details

This class inherits a constructor from Boxen::Check

Instance Method Details

#basic?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/boxen/preflight/creds.rb', line 11

def basic?
  config.api.user rescue nil
end

#ok?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/boxen/preflight/creds.rb', line 15

def ok?
  basic? && token?
end

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/boxen/preflight/creds.rb', line 28

def run
  console = HighLine.new

  warn "Hey, I need your current GitHub credentials to continue."

  config. = console.ask "GitHub login: " do |q|
    q.default = config. || config.user
  end

  config.password = console.ask "GitHub password: " do |q|
    q.echo = "*"
  end

  unless basic?
    puts # i <3 vertical whitespace

    abort "Sorry, I can't auth you on GitHub.",
      "Please check your credentials and teams and give it another try."
  end

  # Okay, the basic creds are good, let's deal with an OAuth token.

  unless auth = config.api.authorizations.detect { |a| a.note == "Boxen" }
    auth = config.api.create_authorization \
      :note => "Boxen", :scopes => %w(repo user)
  end

  # Reset the token for later.

  config.token = auth.token
end

#token?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/boxen/preflight/creds.rb', line 19

def token?
  return unless config.token

  tapi = Octokit::Client.new \
    :login => config., :oauth_token => config.token

  tapi.user rescue nil
end