Class: Cloud66::Utils::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud66_agent/utils/config.rb

Constant Summary collapse

CONFIG_PATH =

default conf dir

"/etc/cloud66/cloud66_agent.yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

load up the config at startup



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cloud66_agent/utils/config.rb', line 21

def initialize
	load if File.exists?(CONFIG_PATH)

	# set defaults
	@log = @log.nil? ? "/var/log/cloud66_agent.log" : @log == "STDOUT" ? STDOUT : @log
	@log_level ||= 2
	@api_url ||= 'https://api.cloud66.com'
	@disabled ||= false
	@is_aws ||= false
	@is_gc ||= false
end

Instance Attribute Details

#agent_uidObject

Returns the value of attribute agent_uid.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def agent_uid
  @agent_uid
end

#api_keyObject

Returns the value of attribute api_key.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def api_key
  @api_key
end

#api_urlObject

Returns the value of attribute api_url.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def api_url
  @api_url
end

#disabledObject

Returns the value of attribute disabled.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def disabled
  @disabled
end

#is_awsObject

Returns the value of attribute is_aws.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def is_aws
  @is_aws
end

#is_gcObject

Returns the value of attribute is_gc.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def is_gc
  @is_gc
end

#logObject

Returns the value of attribute log.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def log
  @log
end

#log_levelObject

Returns the value of attribute log_level.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def log_level
  @log_level
end

#secret_keyObject

Returns the value of attribute secret_key.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def secret_key
  @secret_key
end

Instance Method Details

#deleteObject



56
57
58
# File 'lib/cloud66_agent/utils/config.rb', line 56

def delete
	File.delete(CONFIG_PATH) if File.exists?(CONFIG_PATH)
end

#is_agent_configured?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/cloud66_agent/utils/config.rb', line 33

def is_agent_configured?
	return !@agent_uid.nil? && !@agent_uid.empty?
end

#saveObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cloud66_agent/utils/config.rb', line 37

def save
	Dir.mkdir(CONFIG_PATH) if !FileTest::directory?(File.dirname(CONFIG_PATH))

	File.open(CONFIG_PATH, 'w+') do |out|
		data = {
			'api_url' => @api_url,
			'api_key' => @api_key,
			'secret_key' => @secret_key,
			'agent_uid' => @agent_uid,
			'disabled' => @disabled,
			'is_aws' => @is_aws,
			'is_gc' => @is_gc,
			'log' => @log == STDOUT ? "STDOUT" : @log,
			'log_level' => @log_level,
		}
		YAML::dump(data, out)
	end
end