Class: Legion::CLI::ConnectCommand

Inherits:
Thor
  • Object
show all
Defined in:
lib/legion/cli/connect_command.rb

Constant Summary collapse

PROVIDERS =
%w[microsoft github google].freeze
STATE_COLORS =
{ 'connected' => :green, 'revoked' => :red, 'not connected' => :yellow }.freeze

Instance Method Summary collapse

Instance Method Details

#disconnect(provider) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/legion/cli/connect_command.rb', line 45

def disconnect(provider)
  unless PROVIDERS.include?(provider)
    say "Unknown provider: #{provider}. Valid: #{PROVIDERS.join(', ')}", :red
    return
  end

  say "Disconnected #{provider} account.", :green
end

#githubObject



30
31
32
# File 'lib/legion/cli/connect_command.rb', line 30

def github
  say 'GitHub connection not yet implemented.', :yellow
end

#microsoftObject



19
20
21
22
23
24
25
26
# File 'lib/legion/cli/connect_command.rb', line 19

def microsoft
  say 'Delegating to Teams OAuth2 browser auth...', :blue
  forwarded = ['teams']
  forwarded += ['--tenant_id', options[:tenant_id]] if options[:tenant_id]
  forwarded += ['--client_id', options[:client_id]] if options[:client_id]
  forwarded += ['--scopes', options[:scope]] if options[:scope]
  Legion::CLI::Auth.start(forwarded)
end

#statusObject



35
36
37
38
39
40
41
42
# File 'lib/legion/cli/connect_command.rb', line 35

def status
  require 'legion/auth/token_manager'

  PROVIDERS.each do |provider|
    state = provider_state(provider)
    say "  #{provider}: #{state}", STATE_COLORS.fetch(state, :yellow)
  end
end