Module: Aptible::CLI::Helpers::Token
Instance Method Summary collapse
-
#current_token_hash ⇒ Object
rubocop:enable MethodLength.
- #fetch_token ⇒ Object
-
#save_token(token) ⇒ Object
rubocop:disable MethodLength.
- #token_file ⇒ Object
Instance Method Details
#current_token_hash ⇒ Object
rubocop:enable MethodLength
31 32 33 34 35 |
# File 'lib/aptible/cli/helpers/token.rb', line 31 def current_token_hash JSON.parse(File.read(token_file)) rescue {} end |
#fetch_token ⇒ Object
7 8 9 10 11 |
# File 'lib/aptible/cli/helpers/token.rb', line 7 def fetch_token @token ||= current_token_hash[Aptible::Auth.configuration.root_url] return @token if @token fail Thor::Error, 'Could not read token: please run aptible login' end |
#save_token(token) ⇒ Object
rubocop:disable MethodLength
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/aptible/cli/helpers/token.rb', line 14 def save_token(token) hash = current_token_hash.merge( Aptible::Auth.configuration.root_url => token ) FileUtils.mkdir_p(File.dirname(token_file)) File.open(token_file, 'w') do |file| file.puts hash.to_json end rescue raise Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip Could not write token to #{token_file}, please check filesystem permissions ERR end |
#token_file ⇒ Object
37 38 39 |
# File 'lib/aptible/cli/helpers/token.rb', line 37 def token_file File.join ENV['HOME'], '.aptible', 'tokens.json' end |