Sha256: 8304961b5cd48de758ae6853b41488fe82271751de05d87727c3a3d73a68ca4b
Contents?: true
Size: 1.78 KB
Versions: 6
Compression:
Stored size: 1.78 KB
Contents
require 'cloud66_agent/utils/vital_signs' module Cloud66 module Utils class Config # default conf dir CONFIG_PATH = "/etc/cloud66/cloud66_agent.yml" attr_accessor :api_url, :api_key, :secret_key, :agent_uid, :disabled, :is_aws, :is_gc, :log, :log_level # load up the config at startup 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 def is_agent_configured? return !@agent_uid.nil? && !@agent_uid.empty? end 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 def delete File.delete(CONFIG_PATH) if File.exists?(CONFIG_PATH) end private def load raise "config not found" unless File.exists?(CONFIG_PATH) config = YAML::load(File.open(CONFIG_PATH)) @api_url = config['api_url'] @api_key = config['api_key'] @secret_key = config['secret_key'] @agent_uid = config['agent_uid'] @disabled = config['disabled'] @is_aws = config['is_aws'] @is_gc = config['is_gc'] @log = config['log'] @log_level = config['log_level'] rescue # we can't load the file end end end end
Version data entries
6 entries across 6 versions & 1 rubygems