Class: Cmd::Authen

Inherits:
Object
  • Object
show all
Defined in:
lib/cmd/authen.rb

Class Method Summary collapse

Class Method Details

.check_config_file_existsObject



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

.clientObject



32
33
34
# File 'lib/cmd/authen.rb', line 32

def self.client
	@@client ||= DropletKit::Client.new(access_token: get_token)
end

.get_tokenObject



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'

	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