Class: Cmd::Authen
- Inherits:
-
Object
- Object
- Cmd::Authen
- Defined in:
- lib/cmd/authen.rb
Class Method Summary collapse
Class Method Details
.check_config_file_exists ⇒ Object
4 5 6 7 8 9 |
# 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 ⇒ Object
32 33 34 |
# File 'lib/cmd/authen.rb', line 32 def self.client @@client ||= DropletKit::Client.new(access_token: get_token) end |
.get_token ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cmd/authen.rb', line 11 def self.get_token file_config = ENV['HOME'] + '/.digitalocean/config' = "Miss the DO config files, please run: " + "docli digitalocean config create".red + " to create a new config file" unless File.exist?(file_config) puts 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 |