Class: PoolParty::Default

Inherits:
Object show all
Includes:
Dslify
Defined in:
lib/poolparty/poolparty/default.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.access_keyObject

Get the access_key



55
56
57
# File 'lib/poolparty/poolparty/default.rb', line 55

def access_key
  @access_key ||= load_access_keys_from_environment_var || load_keys_from_file[:access_key]
end

.custom_modules_directoriesObject



142
143
144
145
146
147
148
# File 'lib/poolparty/poolparty/default.rb', line 142

def custom_modules_directories
  [
    "/var/poolparty/modules",
    "/etc/poolparty/modules",
    "#{Dir.pwd}/modules"
  ].select {|d| d if viable_directory?(d) }
end

.custom_monitor_directoriesObject



134
135
136
137
138
139
140
# File 'lib/poolparty/poolparty/default.rb', line 134

def custom_monitor_directories
  [
    "/var/poolparty/monitors",
    "/etc/poolparty/monitors",
    "#{Dir.pwd}/monitors"
  ].select {|d| d if viable_directory?(d) }
end

.get_working_key_file_locationsObject

Get the instance first instance file that exists on the system from the expected places denoted in the local_instances_list_file_locations



93
94
95
# File 'lib/poolparty/poolparty/default.rb', line 93

def get_working_key_file_locations
  key_file_locations.reject {|f| f unless ::File.file?(f) }.first
end

.key_file_locationsObject

Expected places for the instances.list to be located at on the machine



97
98
99
100
101
102
103
104
105
# File 'lib/poolparty/poolparty/default.rb', line 97

def key_file_locations
  [
    ".ppkeys",
    "#{Default.base_config_directory}/.ppkeys",
    "#{Default.storage_directory}/ppkeys",          
    "~/.ppkeys",
    "ppkeys"
  ]
end

.load_access_keys_from_environment_varObject



58
59
60
# File 'lib/poolparty/poolparty/default.rb', line 58

def load_access_keys_from_environment_var
  [ ENV["AWS_ACCESS_KEY"], ENV["AWS_ACCESS_KEY_ID"]].reject {|a| a.nil? }.first
end

.load_keys_from_fileObject



70
71
72
# File 'lib/poolparty/poolparty/default.rb', line 70

def load_keys_from_file
  @keys ||= get_working_key_file_locations ? YAML::load( read_keyfile ) : {}
end

.load_secret_access_keys_from_environment_varObject



64
65
66
# File 'lib/poolparty/poolparty/default.rb', line 64

def load_secret_access_keys_from_environment_var
  [ ENV["AWS_SECRET_ACCESS_KEY"] ].reject {|a| a.nil? }.first
end

.logger_locationObject



122
123
124
125
126
127
128
# File 'lib/poolparty/poolparty/default.rb', line 122

def logger_location
  [
      "/var/log/poolparty"
  ].select do |dir|
    dir if viable_directory?(dir)
  end.first
end

.method_missing(m, *a, &block) ⇒ Object



48
49
50
# File 'lib/poolparty/poolparty/default.rb', line 48

def method_missing(m,*a,&block)
  default_options.include?(m) ? default_options[m] : super
end

.optionsObject



51
52
53
# File 'lib/poolparty/poolparty/default.rb', line 51

def options
  default_options
end

.pool_logger_locationObject

Assume the logs will be at the pool.log location within the logger_location set above



131
132
133
# File 'lib/poolparty/poolparty/default.rb', line 131

def pool_logger_location
  ::File.join(logger_location, "poolparty.log")
end

.properties_hash_fileObject



106
107
108
109
110
111
112
113
114
# File 'lib/poolparty/poolparty/default.rb', line 106

def properties_hash_file
  [
    Default.base_config_directory,
    Dir.pwd
  ].collect do |dir|
    full_dir = ::File.join(dir, Default.properties_hash_filename)
    full_dir if ::File.file?(full_dir)
  end.compact.first || "#{Default.base_config_directory}/#{Default.properties_hash_filename}"
end

.read_keyfileObject



67
68
69
# File 'lib/poolparty/poolparty/default.rb', line 67

def read_keyfile
  open(get_working_key_file_locations).read
end

.reset!Object



87
88
89
# File 'lib/poolparty/poolparty/default.rb', line 87

def reset!
  @keys = nil
end

.secret_access_keyObject



61
62
63
# File 'lib/poolparty/poolparty/default.rb', line 61

def secret_access_key
  @secret_access_key ||= load_secret_access_keys_from_environment_var || load_keys_from_file[:secret_access_key]
end

.storage_directoryObject



115
116
117
118
119
120
121
# File 'lib/poolparty/poolparty/default.rb', line 115

def storage_directory
  [
      "/var/poolparty"
  ].select do |dir|
    dir if viable_directory?(dir)
  end.first || ::File.join( "/tmp/poolparty")
end

.store_keys_in_fileObject

Store the keys in a yaml format to give the master access So that the master has access to the files



75
76
77
78
79
# File 'lib/poolparty/poolparty/default.rb', line 75

def store_keys_in_file
  unless access_key.nil? || secret_access_key.nil?
    write_to_file( key_file_locations.first, YAML::dump({:access_key => access_key, :secret_access_key => secret_access_key}))        
  end
end

.store_keys_in_file_for(obj = nil) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/poolparty/poolparty/default.rb', line 80

def store_keys_in_file_for(obj=nil)
  if obj
    @access_key = obj.access_key
    @secret_access_key = obj.secret_access_key
  end
  store_keys_in_file
end

.viable_directory?(dir) ⇒ Boolean

Only return true if the directory we are reading is both readable and exists

Returns:

  • (Boolean)


151
152
153
# File 'lib/poolparty/poolparty/default.rb', line 151

def viable_directory?(dir)
  ::File.directory?(dir) && ::File.readable?(dir)
end

Instance Method Details

#optionsObject



42
43
44
# File 'lib/poolparty/poolparty/default.rb', line 42

def options
  default_options
end