Class: EPC::Config

Inherits:
Object show all
Defined in:
lib/epc/config.rb

Constant Summary collapse

DEFAULT_TARGET =
'localhost:3000'
SCOPE =

Server Paths

'/api/v1'
TOKENS_PATH =
"#{SCOPE}/tokens"
SOLUTIONS_PATH =
"#{SCOPE}/solutions"
PROJECTS_PATH =
"#{SCOPE}/projects"
PUSHES_PATH =
"#{SCOPE}/pushes"
USERS_PATH =
"#{SCOPE}/users"
BUILDS_PATH =
"#{SCOPE}/builds"
PULLS_PATH =
"#{SCOPE}/pulls"
DEPLOYMENTS_PATH =
"#{SCOPE}/deployments"
CONFIGURATIONS_PATH =
"#{SCOPE}/config_values"
RUNTIMES_PATH =
"#{SCOPE}/runtime_envs"
SERVICE_TYPES_PATH =
"#{SCOPE}/service_types"
SERVICE_DEFINITIONS_PATH =
"#{SCOPE}/service_definitions"
DEPLOYMENT_CONFIGS_PATH =
"#{SCOPE}/deployment_configs"
DEPLOYMENT_STAGES_PATH =
"#{SCOPE}/deployment_stages"
DEPENDENCIES_PATH =
"#{SCOPE}/dependency_definitions"
LIBRARIES_PATH =
"#{SCOPE}/libraries"
LIBRARY_LANGUAGES_PATH =
"#{SCOPE}/library_languages"
LIBRARY_SETS_PATH =
"#{SCOPE}/library_sets"
SERVICE_VERSIONS_PATH =
"#{SCOPE}/service_versions"
PROJECT_TYPES_PATH =
"#{SCOPE}/project_types"
GROUPS_PATH =
"#{SCOPE}/user_groups"
ROLES_PATH =
"#{SCOPE}/roles"
PERMISSIONS_PATH =
"#{SCOPE}/permissions"
GRANTS_PATH =
"#{SCOPE}/grants"
OBJECT_TYPES_PATH =
"#{SCOPE}/object_type_identifiers"
MONITORED_PATH =
"#{SCOPE}/monitored"
METRICS_PATH =
"#{SCOPE}/metrics"
INSTANCES_PATH =
"#{SCOPE}/deployed_projects"
PLUGINS_PATH =
"#{SCOPE}/plugins"
ENTITY_PROPERTIES_PATH =
"#{SCOPE}/entity_properties"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.auth_tokenObject

Returns the value of attribute auth_token.



7
8
9
# File 'lib/epc/config.rb', line 7

def auth_token
  @auth_token
end

.caller_fileObject

Returns the value of attribute caller_file.



7
8
9
# File 'lib/epc/config.rb', line 7

def caller_file
  @caller_file
end

.caller_idObject

Returns the value of attribute caller_id.



7
8
9
# File 'lib/epc/config.rb', line 7

def caller_id
  @caller_id
end

.solutions_projectsObject

Returns the value of attribute solutions_projects.



7
8
9
# File 'lib/epc/config.rb', line 7

def solutions_projects
  @solutions_projects
end

.solutions_projects_fileObject

Returns the value of attribute solutions_projects_file.



7
8
9
# File 'lib/epc/config.rb', line 7

def solutions_projects_file
  @solutions_projects_file
end

.target_fileObject

Returns the value of attribute target_file.



7
8
9
# File 'lib/epc/config.rb', line 7

def target_file
  @target_file
end

.target_urlObject

Returns the value of attribute target_url.



7
8
9
# File 'lib/epc/config.rb', line 7

def target_url
  @target_url
end

.token_fileObject

Returns the value of attribute token_file.



7
8
9
# File 'lib/epc/config.rb', line 7

def token_file
  @token_file
end

.usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/epc/config.rb', line 7

def username
  @username
end

.username_fileObject

Returns the value of attribute username_file.



7
8
9
# File 'lib/epc/config.rb', line 7

def username_file
  @username_file
end

Class Method Details

.add_solution(solution_name, solution_id) ⇒ Object



185
186
187
188
189
# File 'lib/epc/config.rb', line 185

def add_solution(solution_name, solution_id)
  file = File.join(File.expand_path(solution_name), ".epc_solution")
  write_content_as_json(file, {:name => solution_name, :id => solution_id})
  FileUtils.chmod(0600, file)
end

.get_project_value(path, value) ⇒ Object



242
243
244
# File 'lib/epc/config.rb', line 242

def get_project_value(path, value)
  return read_content_as_json(path + "/.epc_project")[value] rescue nil
end

.get_solution_value(path, value) ⇒ Object



191
192
193
# File 'lib/epc/config.rb', line 191

def get_solution_value(path, value)
  return read_content_as_json(File.join(path, ".epc_solution"))[value] rescue nil
end

.is_project_dir?(dirname) ⇒ Boolean

Returns:

  • (Boolean)


260
261
262
# File 'lib/epc/config.rb', line 260

def is_project_dir?(dirname)
  return File.exists?(File.join(File.expand_path(dirname), ".epc_project"))
end

.is_solution_dir?(dirname) ⇒ Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/epc/config.rb', line 202

def is_solution_dir?(dirname)
  return File.exists?(File.join(File.expand_path(dirname), ".epc_solution"))
end

.module_exists?(class_name) ⇒ Boolean

Returns:

  • (Boolean)


143
144
145
146
147
# File 'lib/epc/config.rb', line 143

def module_exists?(class_name)
  return EPC::Command.const_defined?(class_name)
rescue NameError
  return false
end

.read_content_as_json(file) ⇒ Object

Solutions Projects Management These convenience methods are here to keep each command from having to know the structure of the file. This also gives Config control over when to re-write the file.



174
175
176
# File 'lib/epc/config.rb', line 174

def read_content_as_json(file)
  return JSON.parse(File.read(file)) rescue {}
end

.remove_auth_tokenObject



139
140
141
# File 'lib/epc/config.rb', line 139

def remove_auth_token
  FileUtils.rm_f(File.expand_path(token_file))
end

.remove_usernameObject



103
104
105
# File 'lib/epc/config.rb', line 103

def remove_username
  FileUtils.rm_f(File.expand_path(username_file))
end

.say_err(statement) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/epc/config.rb', line 149

def say_err( statement )
  statement = statement.to_str
  return unless statement.length > 0

  if statement[-1, 1] == " " or statement[-1, 1] == "\t"
    STDERR.print(statement)
    STDERR.flush  
  else
    STDERR.puts(statement)
  end
end

.set_project_value(path, key, value) ⇒ Object



246
247
248
249
250
251
# File 'lib/epc/config.rb', line 246

def set_project_value(path, key, value)
  path += "/.epc_project"
  content = read_content_as_json(path)
  content[key] = value
  write_content_as_json(path, content)
end

.set_solution_value(path, key, value) ⇒ Object



195
196
197
198
199
200
# File 'lib/epc/config.rb', line 195

def set_solution_value(path, key, value)
  path += "/.epc_solution"
  content = read_content_as_json(path)
  content[key] = value
  write_content_as_json(path, content)
end

.store_auth_token(token) ⇒ Object



133
134
135
136
137
# File 'lib/epc/config.rb', line 133

def store_auth_token(token)
  file = File.expand_path(token_file)
  File.open(file, 'w+') { |f| f.puts(token) }
  FileUtils.chmod(0600, file)
end

.store_caller_id(caller_id) ⇒ Object



87
88
89
90
91
# File 'lib/epc/config.rb', line 87

def store_caller_id(caller_id)
  file = File.expand_path(caller_file)
  File.open(file, 'w+') { |f| f.puts(caller_id) }
  FileUtils.chmod(0600, file)
end

.store_target_url(url) ⇒ Object



66
67
68
69
70
# File 'lib/epc/config.rb', line 66

def store_target_url(url)
  file = File.expand_path(target_file)
  File.open(file, 'w+') { |f| f.puts(url) }
  FileUtils.chmod(0600, file)
end

.store_username(username) ⇒ Object



97
98
99
100
101
# File 'lib/epc/config.rb', line 97

def store_username(username)
  file = File.expand_path(username_file)
  File.open(file, 'w+') { |f| f.puts(username) }
  FileUtils.chmod(0600, file)
end

.underscore(camel_cased_word) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/epc/config.rb', line 161

def underscore(camel_cased_word)
  camel_cased_word.to_s.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end

.update_project_directory(path) ⇒ Object



253
254
255
256
257
258
# File 'lib/epc/config.rb', line 253

def update_project_directory(path)
  parent_dir = File.join(path, "..")
  new_name = get_project_value(path, "name")
  new_path = File.join(parent_dir, new_name)
  FileUtils.mv path, new_path unless path.split("/").last == new_name
end

.update_project_metadata(data, path) ⇒ Object



237
238
239
240
# File 'lib/epc/config.rb', line 237

def (data, path)
  set_project_value(path, "id", data[:id])
  set_project_value(path, "name", data[:name])
end

.update_solution_directory(path) ⇒ Object



212
213
214
215
216
217
# File 'lib/epc/config.rb', line 212

def update_solution_directory(path)
  parent_dir = File.join(path, "../")
  new_name = get_solution_value(path, "name")
  new_path = File.join(parent_dir, new_name)
  (FileUtils.mv(path, new_path) unless path.split("/").last == new_name) rescue ""
end

.update_solution_metadata(data, path) ⇒ Object



206
207
208
209
210
# File 'lib/epc/config.rb', line 206

def (data, path)
  set_solution_value(path, "id", data[:id])
  set_solution_value(path, "name", data[:name])

end

.write_content_as_json(file, content) ⇒ Object



178
179
180
# File 'lib/epc/config.rb', line 178

def write_content_as_json(file, content)
  File.open(file, "w+") {|f| f.puts(content.to_json)}
end

.write_project_metadata(project_id, client, base_path = nil) ⇒ Object

PROJECT METHODS



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/epc/config.rb', line 221

def (project_id, client, base_path = nil)
  attributes = [:id, :name, :solution_id, :project_type]
  status, response, headers = client.get(PROJECTS_PATH + "/#{project_id}")
  if status.failure? || response.empty?
    raise Exception, "cannot retrieve project details"
  end
   = response.keep_if{|k,v| attributes.include?(k)}
  if base_path.nil?
    file = File.join(File.expand_path([:name]), ".epc_project")
  else
    file = File.join(base_path, ".epc_project")
  end
  write_content_as_json(file, )
  FileUtils.chmod(0600, file)
end