Class: Bastille::CLI::Token
- Inherits:
-
Thor
- Object
- Thor
- Bastille::CLI::Token
- Includes:
- Common
- Defined in:
- lib/bastille/cli/token.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.description ⇒ Object
10 11 12 |
# File 'lib/bastille/cli/token.rb', line 10 def self.description 'Provides the user with tools to create and view their bastille token' end |
.usage ⇒ Object
6 7 8 |
# File 'lib/bastille/cli/token.rb', line 6 def self.usage 'token [TASK]' end |
Instance Method Details
#delete ⇒ Object
48 49 50 51 52 |
# File 'lib/bastille/cli/token.rb', line 48 def delete if yes? 'Are you sure you want to delete your token? This cannot be undone.' store.delete! end end |
#new ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bastille/cli/token.rb', line 15 def new if store.exist? say 'Found a local token in ~/.bastille. Aborting new token generation. Run `bastille token delete` and run this command again to generate a new token.', :yellow else if yes? 'This action will require you to authenticate with Github. Are you sure you want to generate a new token?', :red username = ask 'Github username: ' password = ask 'Password: ' do |q| q.echo = false end domain = ask 'Where is the bastille server?: ' name = ask 'What should we call this bastille token? This can be anything: ' if store.generate(username, password, domain, name) say 'Your token has been generated and authorized with github. It is stored in ~/.bastille. <3', :green else say 'The username and password entered do not match. Sorry. :(', :red end end end end |
#show ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bastille/cli/token.rb', line 36 def show if store.exist? max_number_of_spaces = store.keys.map(&:to_s).sort { |a,b| a.length <=> b.length }.last.length + 1 store.each do |key, value| say " #{key}#{' ' * (max_number_of_spaces - key.to_s.length)}: #{value}" end else say 'There is no token.', :red end end |
#validate ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bastille/cli/token.rb', line 55 def validate if store.exist? say 'Validating your token with the bastille server...', :green if store.authenticate say 'Your token is valid. \m/', :green else say "Github says you aren't who you say you are. o_O", :red end else say 'Could not validate your token. There is no token at ~/.bastille. Try running `bastille token new` to generate a new token.', :red end end |