Class: Cloud66::Utils::Config
- Inherits:
-
Object
- Object
- Cloud66::Utils::Config
- 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
-
#agent_uid ⇒ Object
Returns the value of attribute agent_uid.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#is_aws ⇒ Object
Returns the value of attribute is_aws.
-
#is_gc ⇒ Object
Returns the value of attribute is_gc.
-
#log ⇒ Object
Returns the value of attribute log.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize ⇒ Config
constructor
load up the config at startup.
- #is_agent_configured? ⇒ Boolean
- #save ⇒ Object
Constructor Details
#initialize ⇒ Config
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_uid ⇒ Object
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_key ⇒ Object
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_url ⇒ Object
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 |
#disabled ⇒ Object
Returns the value of attribute disabled.
10 11 12 |
# File 'lib/cloud66_agent/utils/config.rb', line 10 def disabled @disabled end |
#is_aws ⇒ Object
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_gc ⇒ Object
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 |
#log ⇒ Object
Returns the value of attribute log.
10 11 12 |
# File 'lib/cloud66_agent/utils/config.rb', line 10 def log @log end |
#log_level ⇒ Object
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_key ⇒ Object
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
#delete ⇒ Object
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
33 34 35 |
# File 'lib/cloud66_agent/utils/config.rb', line 33 def is_agent_configured? return !@agent_uid.nil? && !@agent_uid.empty? end |
#save ⇒ Object
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 |