class Cmd::Authen
Public Class Methods
check_config_file_exists()
click to toggle source
# File lib/cmd/authen.rb, line 4 def self.check_config_file_exists if !File.exists?(ENV['HOME'] + "/.digitalocean/config") puts "Miss DigitalOcean config, please init your config " + "docli config create".red exit end end
client()
click to toggle source
# File lib/cmd/authen.rb, line 32 def self.client @@client ||= DropletKit::Client.new(access_token: get_token) end
get_token()
click to toggle source
# File lib/cmd/authen.rb, line 11 def self.get_token file_config = ENV['HOME'] + '/.digitalocean/config' exception_message = "Miss the DO config files, please run: " + "docli digitalocean config create".red + " to create a new config file" unless File.exist?(file_config) puts exception_message exit end file_data = {} File.open(file_config, 'r') do |file| file.each_line do |line| line_data = line.split(' = ') file_data[line_data[0]] = line_data[1] end end return file_data['DO_TOKEN'] end