Class: EPC::Config
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"
Class Attribute Summary collapse
-
.auth_token ⇒ Object
Returns the value of attribute auth_token.
-
.caller_file ⇒ Object
Returns the value of attribute caller_file.
-
.caller_id ⇒ Object
Returns the value of attribute caller_id.
-
.solutions_projects ⇒ Object
Returns the value of attribute solutions_projects.
-
.solutions_projects_file ⇒ Object
Returns the value of attribute solutions_projects_file.
-
.target_file ⇒ Object
Returns the value of attribute target_file.
-
.target_url ⇒ Object
Returns the value of attribute target_url.
-
.token_file ⇒ Object
Returns the value of attribute token_file.
-
.username ⇒ Object
Returns the value of attribute username.
-
.username_file ⇒ Object
Returns the value of attribute username_file.
Class Method Summary collapse
- .add_solution(solution_name, solution_id) ⇒ Object
- .get_project_value(path, value) ⇒ Object
- .get_solution_value(path, value) ⇒ Object
- .is_project_dir?(dirname) ⇒ Boolean
- .is_solution_dir?(dirname) ⇒ Boolean
-
.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.
- .remove_auth_token ⇒ Object
- .remove_username ⇒ Object
- .set_project_value(path, key, value) ⇒ Object
- .set_solution_value(path, key, value) ⇒ Object
- .store_auth_token(token) ⇒ Object
- .store_caller_id(caller_id) ⇒ Object
- .store_target_url(url) ⇒ Object
- .store_username(username) ⇒ Object
- .underscore(camel_cased_word) ⇒ Object
- .update_project_directory(path) ⇒ Object
- .update_project_metadata(data, path) ⇒ Object
- .update_solution_directory(path) ⇒ Object
- .update_solution_metadata(data, path) ⇒ Object
- .write_content_as_json(file, content) ⇒ Object
-
.write_project_metadata(project_id, client, base_path = nil) ⇒ Object
PROJECT METHODS.
Class Attribute Details
.auth_token ⇒ Object
Returns the value of attribute auth_token.
7 8 9 |
# File 'lib/epc/config.rb', line 7 def auth_token @auth_token end |
.caller_file ⇒ Object
Returns the value of attribute caller_file.
7 8 9 |
# File 'lib/epc/config.rb', line 7 def caller_file @caller_file end |
.caller_id ⇒ Object
Returns the value of attribute caller_id.
7 8 9 |
# File 'lib/epc/config.rb', line 7 def caller_id @caller_id end |
.solutions_projects ⇒ Object
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_file ⇒ Object
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_file ⇒ Object
Returns the value of attribute target_file.
7 8 9 |
# File 'lib/epc/config.rb', line 7 def target_file @target_file end |
.target_url ⇒ Object
Returns the value of attribute target_url.
7 8 9 |
# File 'lib/epc/config.rb', line 7 def target_url @target_url end |
.token_file ⇒ Object
Returns the value of attribute token_file.
7 8 9 |
# File 'lib/epc/config.rb', line 7 def token_file @token_file end |
.username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/epc/config.rb', line 7 def username @username end |
.username_file ⇒ Object
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
167 168 169 170 171 |
# File 'lib/epc/config.rb', line 167 def add_solution(solution_name, solution_id) file = File.join(File.(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
224 225 226 |
# File 'lib/epc/config.rb', line 224 def get_project_value(path, value) return read_content_as_json(path + "/.epc_project")[value] rescue nil end |
.get_solution_value(path, value) ⇒ Object
173 174 175 |
# File 'lib/epc/config.rb', line 173 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
242 243 244 |
# File 'lib/epc/config.rb', line 242 def is_project_dir?(dirname) return File.exists?(File.join(File.(dirname), ".epc_project")) end |
.is_solution_dir?(dirname) ⇒ Boolean
184 185 186 |
# File 'lib/epc/config.rb', line 184 def is_solution_dir?(dirname) return File.exists?(File.join(File.(dirname), ".epc_solution")) 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.
156 157 158 |
# File 'lib/epc/config.rb', line 156 def read_content_as_json(file) return JSON.parse(File.read(file)) rescue {} end |
.remove_auth_token ⇒ Object
138 139 140 |
# File 'lib/epc/config.rb', line 138 def remove_auth_token FileUtils.rm_f(File.(token_file)) end |
.remove_username ⇒ Object
102 103 104 |
# File 'lib/epc/config.rb', line 102 def remove_username FileUtils.rm_f(File.(username_file)) end |
.set_project_value(path, key, value) ⇒ Object
228 229 230 231 232 233 |
# File 'lib/epc/config.rb', line 228 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
177 178 179 180 181 182 |
# File 'lib/epc/config.rb', line 177 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
132 133 134 135 136 |
# File 'lib/epc/config.rb', line 132 def store_auth_token(token) file = File.(token_file) File.open(file, 'w+') { |f| f.puts(token) } FileUtils.chmod(0600, file) end |
.store_caller_id(caller_id) ⇒ Object
86 87 88 89 90 |
# File 'lib/epc/config.rb', line 86 def store_caller_id(caller_id) file = File.(caller_file) File.open(file, 'w+') { |f| f.puts(caller_id) } FileUtils.chmod(0600, file) end |
.store_target_url(url) ⇒ Object
65 66 67 68 69 |
# File 'lib/epc/config.rb', line 65 def store_target_url(url) file = File.(target_file) File.open(file, 'w+') { |f| f.puts(url) } FileUtils.chmod(0600, file) end |
.store_username(username) ⇒ Object
96 97 98 99 100 |
# File 'lib/epc/config.rb', line 96 def store_username(username) file = File.(username_file) File.open(file, 'w+') { |f| f.puts(username) } FileUtils.chmod(0600, file) end |
.underscore(camel_cased_word) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/epc/config.rb', line 143 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
235 236 237 238 239 240 |
# File 'lib/epc/config.rb', line 235 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
219 220 221 222 |
# File 'lib/epc/config.rb', line 219 def (data, path) set_project_value(path, "id", data[:id]) set_project_value(path, "name", data[:name]) end |
.update_solution_directory(path) ⇒ Object
194 195 196 197 198 199 |
# File 'lib/epc/config.rb', line 194 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
188 189 190 191 192 |
# File 'lib/epc/config.rb', line 188 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
160 161 162 |
# File 'lib/epc/config.rb', line 160 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
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/epc/config.rb', line 203 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.([:name]), ".epc_project") else file = File.join(base_path, ".epc_project") end write_content_as_json(file, ) FileUtils.chmod(0600, file) end |