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



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

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



230
231
232
# File 'lib/epc/config.rb', line 230

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

.get_solution_value(path, value) ⇒ Object



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

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)


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

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

.is_solution_dir?(dirname) ⇒ Boolean

Returns:

  • (Boolean)


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

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.



162
163
164
# File 'lib/epc/config.rb', line 162

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

.set_project_value(path, key, value) ⇒ Object



234
235
236
237
238
239
# File 'lib/epc/config.rb', line 234

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



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

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



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

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



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

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



225
226
227
228
# File 'lib/epc/config.rb', line 225

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

.update_solution_directory(path) ⇒ Object



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

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



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

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



166
167
168
# File 'lib/epc/config.rb', line 166

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



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/epc/config.rb', line 209

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