epc 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +1 -0
- data/Gemfile +22 -0
- data/Rakefile +67 -0
- data/Rakefile.gem +1 -0
- data/bin/epc +10 -0
- data/lib/epc.rb +126 -0
- data/lib/epc/client/base_client.rb +80 -0
- data/lib/epc/client/http_client.rb +19 -0
- data/lib/epc/client/json_client.rb +48 -0
- data/lib/epc/command/archive_project_command.rb +24 -0
- data/lib/epc/command/archive_solution_command.rb +21 -0
- data/lib/epc/command/attach_library_command.rb +82 -0
- data/lib/epc/command/attach_libraryset_command.rb +32 -0
- data/lib/epc/command/attach_runtime_command.rb +27 -0
- data/lib/epc/command/base_command.rb +451 -0
- data/lib/epc/command/bind_service_command.rb +35 -0
- data/lib/epc/command/build_command.rb +83 -0
- data/lib/epc/command/config/create_config_command.rb +55 -0
- data/lib/epc/command/copy_deployment_command.rb +21 -0
- data/lib/epc/command/create_command.rb +13 -0
- data/lib/epc/command/create_dependency_command.rb +43 -0
- data/lib/epc/command/define_service_command.rb +37 -0
- data/lib/epc/command/delete_config_command.rb +63 -0
- data/lib/epc/command/delete_dependency_command.rb +40 -0
- data/lib/epc/command/delete_group_command.rb +40 -0
- data/lib/epc/command/delete_library_command.rb +30 -0
- data/lib/epc/command/delete_librarylanguage_command.rb +40 -0
- data/lib/epc/command/delete_libraryset_command.rb +40 -0
- data/lib/epc/command/delete_project_command.rb +54 -0
- data/lib/epc/command/delete_role_command.rb +25 -0
- data/lib/epc/command/delete_serviceversion_command.rb +52 -0
- data/lib/epc/command/delete_solution_command.rb +39 -0
- data/lib/epc/command/delete_user_command.rb +31 -0
- data/lib/epc/command/deploy_command.rb +142 -0
- data/lib/epc/command/deployment/create_deployment_command.rb +82 -0
- data/lib/epc/command/detach_library_command.rb +35 -0
- data/lib/epc/command/detach_libraryset_command.rb +8 -0
- data/lib/epc/command/group/create_group_command.rb +21 -0
- data/lib/epc/command/info_command.rb +11 -0
- data/lib/epc/command/library/create_library_command.rb +45 -0
- data/lib/epc/command/librarylanguage/create_librarylanguage_command.rb +24 -0
- data/lib/epc/command/libraryset/create_libraryset_command.rb +54 -0
- data/lib/epc/command/list_approvals_command.rb +27 -0
- data/lib/epc/command/list_attachedlibraries_command.rb +42 -0
- data/lib/epc/command/list_boundservices_command.rb +40 -0
- data/lib/epc/command/list_config_command.rb +60 -0
- data/lib/epc/command/list_dependencies_command.rb +43 -0
- data/lib/epc/command/list_deployments_command.rb +68 -0
- data/lib/epc/command/list_groups_command.rb +19 -0
- data/lib/epc/command/list_libraries_command.rb +19 -0
- data/lib/epc/command/list_librarylanguages_command.rb +19 -0
- data/lib/epc/command/list_librarysets_command.rb +26 -0
- data/lib/epc/command/list_objectroles_command.rb +25 -0
- data/lib/epc/command/list_objecttypes_command.rb +20 -0
- data/lib/epc/command/list_permissiongroups_command.rb +20 -0
- data/lib/epc/command/list_projects_command.rb +36 -0
- data/lib/epc/command/list_projecttypes_command.rb +20 -0
- data/lib/epc/command/list_rolepermissions_command.rb +21 -0
- data/lib/epc/command/list_roles_command.rb +26 -0
- data/lib/epc/command/list_runtimes_command.rb +16 -0
- data/lib/epc/command/list_service_types_command.rb +19 -0
- data/lib/epc/command/list_servicedefinitions_command.rb +19 -0
- data/lib/epc/command/list_serviceversions_command.rb +21 -0
- data/lib/epc/command/list_solutions_command.rb +25 -0
- data/lib/epc/command/list_stages_command.rb +21 -0
- data/lib/epc/command/list_users_command.rb +26 -0
- data/lib/epc/command/list_versions_command.rb +39 -0
- data/lib/epc/command/login_command.rb +32 -0
- data/lib/epc/command/logout_command.rb +20 -0
- data/lib/epc/command/objectrole/create_objectrole_command.rb +19 -0
- data/lib/epc/command/project/create_project_command.rb +78 -0
- data/lib/epc/command/pull_command.rb +209 -0
- data/lib/epc/command/push_command.rb +194 -0
- data/lib/epc/command/refresh_solution_command.rb +71 -0
- data/lib/epc/command/renew_command.rb +19 -0
- data/lib/epc/command/request_passwordchange_command.rb +23 -0
- data/lib/epc/command/role/create_role_command.rb +17 -0
- data/lib/epc/command/serviceversion/create_serviceversion_command.rb +33 -0
- data/lib/epc/command/show_deployment_command.rb +57 -0
- data/lib/epc/command/show_group_command.rb +35 -0
- data/lib/epc/command/show_libraryset_command.rb +54 -0
- data/lib/epc/command/show_project_command.rb +74 -0
- data/lib/epc/command/show_projecttype_command.rb +18 -0
- data/lib/epc/command/show_role_command.rb +46 -0
- data/lib/epc/command/show_solution_command.rb +54 -0
- data/lib/epc/command/show_user_command.rb +42 -0
- data/lib/epc/command/solution/create_solution_command.rb +34 -0
- data/lib/epc/command/solution/list_solutions_command.rb +25 -0
- data/lib/epc/command/solution/update_solution_command.rb +43 -0
- data/lib/epc/command/submit_deployment_command.rb +19 -0
- data/lib/epc/command/target_command.rb +26 -0
- data/lib/epc/command/unarchive_project_command.rb +23 -0
- data/lib/epc/command/unarchive_solution_command.rb +21 -0
- data/lib/epc/command/unbind_service_command.rb +42 -0
- data/lib/epc/command/undefine_service_command.rb +33 -0
- data/lib/epc/command/undeploy_command.rb +106 -0
- data/lib/epc/command/update_config_command.rb +62 -0
- data/lib/epc/command/update_deploymentproject_command.rb +54 -0
- data/lib/epc/command/update_group_command.rb +43 -0
- data/lib/epc/command/update_librarylanguage_command.rb +28 -0
- data/lib/epc/command/update_libraryset_command.rb +80 -0
- data/lib/epc/command/update_project_command.rb +49 -0
- data/lib/epc/command/update_role_command.rb +47 -0
- data/lib/epc/command/update_rolepermissions_command.rb +83 -0
- data/lib/epc/command/update_solution_command.rb +45 -0
- data/lib/epc/command/update_user_command.rb +57 -0
- data/lib/epc/command/user/create_user_command.rb +27 -0
- data/lib/epc/command/vote_deployment_command.rb +29 -0
- data/lib/epc/config.rb +245 -0
- data/lib/epc/error/basic_error.rb +6 -0
- data/lib/epc/error/fatal_error.rb +6 -0
- data/lib/epc/error/input_error.rb +6 -0
- data/lib/epc/error/internal_error.rb +6 -0
- data/lib/epc/help.rb +292 -0
- data/lib/epc/persistent_attributes.rb +18 -0
- data/lib/epc/runner.rb +177 -0
- data/lib/epc/tabular_outputter.rb +161 -0
- data/lib/epc/version.rb +3 -0
- data/lib/fixnum.rb +9 -0
- data/lib/object.rb +13 -0
- data/test/command/archive_project_command_test.rb +41 -0
- data/test/command/archive_solution_command_test.rb +40 -0
- data/test/command/attach_library_command_test.rb +124 -0
- data/test/command/attach_libraryset_command_test.rb +49 -0
- data/test/command/attach_runtime_command_test.rb +44 -0
- data/test/command/base_command_test.rb +276 -0
- data/test/command/bind_service_command_test.rb +46 -0
- data/test/command/build_command_test.rb +103 -0
- data/test/command/copy_deployment_command_test.rb +38 -0
- data/test/command/create_config_command_test.rb +124 -0
- data/test/command/create_dependency_command_test.rb +55 -0
- data/test/command/create_deployment_command_test.rb +136 -0
- data/test/command/create_group_command_test.rb +34 -0
- data/test/command/create_library_command_test.rb +61 -0
- data/test/command/create_librarylanguage_command_test.rb +51 -0
- data/test/command/create_libraryset_command_test.rb +81 -0
- data/test/command/create_objectrole_command_test.rb +37 -0
- data/test/command/create_project_command_test.rb +102 -0
- data/test/command/create_role_command_test.rb +31 -0
- data/test/command/create_serviceversion_command_test.rb +60 -0
- data/test/command/create_solution_command_test.rb +70 -0
- data/test/command/create_user_command_test.rb +54 -0
- data/test/command/define_service_command_test.rb +55 -0
- data/test/command/delete_config_command_test.rb +82 -0
- data/test/command/delete_dependency_command_test.rb +50 -0
- data/test/command/delete_group_command_test.rb +56 -0
- data/test/command/delete_library_command_test.rb +43 -0
- data/test/command/delete_librarylanguage_command_test.rb +55 -0
- data/test/command/delete_libraryset_command_test.rb +55 -0
- data/test/command/delete_project_command_test.rb +76 -0
- data/test/command/delete_role_command_test.rb +41 -0
- data/test/command/delete_serviceversion_command_test.rb +53 -0
- data/test/command/delete_solution_command_test.rb +79 -0
- data/test/command/delete_user_command_test.rb +56 -0
- data/test/command/deploy_command_test.rb +185 -0
- data/test/command/detach_library_command_test.rb +53 -0
- data/test/command/info_command_test.rb +17 -0
- data/test/command/list_approvals_command_test.rb +41 -0
- data/test/command/list_boundservices_command_test.rb +46 -0
- data/test/command/list_config_command_test.rb +72 -0
- data/test/command/list_dependencies_command_test.rb +46 -0
- data/test/command/list_deployments_command_test.rb +112 -0
- data/test/command/list_deploymentstages_command_test.rb +44 -0
- data/test/command/list_libraries_command_test.rb +42 -0
- data/test/command/list_librarylanguages_command_test.rb +34 -0
- data/test/command/list_librarysets_command_test.rb +33 -0
- data/test/command/list_objectroles_command_test.rb +41 -0
- data/test/command/list_objecttypes_command_test.rb +25 -0
- data/test/command/list_permissiongroups_command_test.rb +25 -0
- data/test/command/list_projects_command_test.rb +63 -0
- data/test/command/list_projecttypes_command_test.rb +39 -0
- data/test/command/list_rolepermissions_command_test.rb +39 -0
- data/test/command/list_roles_command_test.rb +46 -0
- data/test/command/list_runtimes_command_test.rb +30 -0
- data/test/command/list_service_types_command_test.rb +44 -0
- data/test/command/list_servicedefinitions_command_test.rb +44 -0
- data/test/command/list_serviceversions_command_test.rb +47 -0
- data/test/command/list_solutions_command_test.rb +48 -0
- data/test/command/list_users_command_test.rb +33 -0
- data/test/command/login_command_test.rb +83 -0
- data/test/command/logout_command_test.rb +30 -0
- data/test/command/pull_command_test.rb +229 -0
- data/test/command/push_command_test.rb +246 -0
- data/test/command/refresh_solution_command_test.rb +35 -0
- data/test/command/renew_command_test.rb +43 -0
- data/test/command/request_passwordchange_command_test.rb +31 -0
- data/test/command/show_group_command_test.rb +50 -0
- data/test/command/show_libraryset_command_test.rb +51 -0
- data/test/command/show_project_command_test.rb +57 -0
- data/test/command/show_projecttype_command_test.rb +46 -0
- data/test/command/show_role_command_test.rb +37 -0
- data/test/command/show_solution_command_test.rb +59 -0
- data/test/command/show_user_command_test.rb +50 -0
- data/test/command/submit_deployment_command_test.rb +37 -0
- data/test/command/target_command_test.rb +58 -0
- data/test/command/unarchive_project_command_test.rb +45 -0
- data/test/command/unarchive_solution_command_test.rb +43 -0
- data/test/command/unbind_service_command_test.rb +48 -0
- data/test/command/undefine_service_command_test.rb +49 -0
- data/test/command/update_config_command_test.rb +74 -0
- data/test/command/update_deploymentproject_command_test.rb +77 -0
- data/test/command/update_group_command_test.rb +69 -0
- data/test/command/update_librarylanguage_command_test.rb +43 -0
- data/test/command/update_libraryset_command_test.rb +113 -0
- data/test/command/update_project_command_test.rb +56 -0
- data/test/command/update_role_command_test.rb +42 -0
- data/test/command/update_rolepermissions_command_test.rb +54 -0
- data/test/command/update_solution_command_test.rb +58 -0
- data/test/command/update_user_command_test.rb +76 -0
- data/test/command/vote_deployment_command_test.rb +33 -0
- data/test/config_test.rb +70 -0
- data/test/successful_test.rb +21 -0
- data/test/test_files/pom.xml +273 -0
- data/test/test_helper.rb +25 -0
- metadata +470 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
module EPC::Command
|
2
|
+
class UpdateSolutionCommand < BaseCommand
|
3
|
+
UPDATABLE_ATTRIBUTES = ["name"]
|
4
|
+
|
5
|
+
def execute(*args)
|
6
|
+
path = "."
|
7
|
+
path = File.expand_path(path)
|
8
|
+
path = project_solution_path(path)
|
9
|
+
|
10
|
+
|
11
|
+
solution_id, solution_name = infer_solution_context(@options[:solution_name], path)
|
12
|
+
|
13
|
+
raise FatalError, "Solution could not be determined" if solution_id.nil?
|
14
|
+
|
15
|
+
args_hash = {}
|
16
|
+
args.each do |arg|
|
17
|
+
key, val = arg.split("=")
|
18
|
+
args_hash[key] = val
|
19
|
+
end
|
20
|
+
|
21
|
+
unless @options[:file].nil?
|
22
|
+
args_hash = EPC::Config.read_content_as_json(@options[:file]).merge(args_hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
args_hash.each do |attr, val|
|
26
|
+
if !UPDATABLE_ATTRIBUTES.include?(attr)
|
27
|
+
args_hash.delete(attr)
|
28
|
+
say("Cannot update #{attr}. Updatable attributes are: #{UPDATABLE_ATTRIBUTES.join(',')}")
|
29
|
+
next
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
unless args_hash.empty?
|
35
|
+
status, response, message = client.put(EPC::Config::SOLUTIONS_PATH + "/#{solution_id}", args_hash)
|
36
|
+
if status.failure?
|
37
|
+
say("Update failed with: [#{response['message']}]")
|
38
|
+
else
|
39
|
+
say("Update succesful")
|
40
|
+
end
|
41
|
+
return status
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module EPC::Command
|
2
|
+
class UpdateUserCommand < BaseCommand
|
3
|
+
|
4
|
+
def execute(user = nil)
|
5
|
+
|
6
|
+
raise FatalError, "You need to specify a user id/email" if user.nil?
|
7
|
+
|
8
|
+
if @options[:password].present?
|
9
|
+
if numeric?(user)
|
10
|
+
email = get_resource_attribute(EPC::Config::USERS_PATH, :email, :id, user.to_i)
|
11
|
+
else
|
12
|
+
email = user
|
13
|
+
end
|
14
|
+
raise FatalError, "User could not be determined" if email.blank?
|
15
|
+
|
16
|
+
raise FatalError, "You need to specify the password change token with the --token option" if @options[:token].blank?
|
17
|
+
|
18
|
+
status, response, headers = client.put(EPC::Config::USERS_PATH + "/#{email}/change_password", {:token => @options[:token], :password => @options[:password]})
|
19
|
+
|
20
|
+
if status.successful?
|
21
|
+
say("Password change successful")
|
22
|
+
else
|
23
|
+
say("Request failed: [#{response[:message]}]")
|
24
|
+
end
|
25
|
+
|
26
|
+
return status
|
27
|
+
end
|
28
|
+
|
29
|
+
if @options[:email].present? || @options[:name].present?
|
30
|
+
if numeric?(user)
|
31
|
+
user_id = user.to_i
|
32
|
+
else
|
33
|
+
user_id = get_resource_id(EPC::Config::USERS_PATH, :email, user)
|
34
|
+
end
|
35
|
+
|
36
|
+
raise FatalError, "User could not be determined" if user_id.blank?
|
37
|
+
|
38
|
+
params = {}
|
39
|
+
params[:email] = @options[:email] if @options[:email].present?
|
40
|
+
params[:name] = @options[:name] if @options[:name].present?
|
41
|
+
|
42
|
+
status, response, headers = client.put(EPC::Config::USERS_PATH + "/#{user_id}", params)
|
43
|
+
|
44
|
+
if status.successful?
|
45
|
+
say("User updated")
|
46
|
+
else
|
47
|
+
say("Request failed: [#{response[:message]}]")
|
48
|
+
end
|
49
|
+
|
50
|
+
return status
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module EPC::Command
|
2
|
+
class CreateUserCommand < BaseCommand
|
3
|
+
def execute(*params)
|
4
|
+
|
5
|
+
email = params[1]
|
6
|
+
|
7
|
+
raise FatalError, "You must supply an email address" if email.blank?
|
8
|
+
|
9
|
+
password = options[:password]
|
10
|
+
password = ask("Password: ") { |q| q.echo = '*' } unless password
|
11
|
+
|
12
|
+
params = {}
|
13
|
+
params[:email] = email
|
14
|
+
params[:password] = password
|
15
|
+
params[:name] = @options[:name] if @options[:name].present?
|
16
|
+
|
17
|
+
status, response, headers = client.post("#{EPC::Config::USERS_PATH}", params)
|
18
|
+
if status.successful? && response
|
19
|
+
say("Successfully created the user with [#{target_url}]")
|
20
|
+
elsif response
|
21
|
+
say("User creation failed [#{response[:message]}].")
|
22
|
+
end
|
23
|
+
return status
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module EPC::Command
|
2
|
+
class VoteDeploymentCommand < BaseCommand
|
3
|
+
|
4
|
+
def execute(deployment_id = nil)
|
5
|
+
approved = false
|
6
|
+
command_usage = EPC::Help::COMMAND_USAGES[:deny_deployment]
|
7
|
+
|
8
|
+
if @options[:approval] == "approve"
|
9
|
+
approved = true
|
10
|
+
command_usage = EPC::Help::COMMAND_USAGES[:approve_deployment]
|
11
|
+
end
|
12
|
+
|
13
|
+
if deployment_id.nil?
|
14
|
+
say("You must specify a deployment id.")
|
15
|
+
say(command_usage)
|
16
|
+
return 1
|
17
|
+
end
|
18
|
+
|
19
|
+
status, response, headers = client.put(EPC::Config::DEPLOYMENTS_PATH + "/#{deployment_id}/vote", {:approved => approved})
|
20
|
+
if status.successful?
|
21
|
+
say("Deployment [#{deployment_id}] has been #{approved ? "approved" : "rejected"} by you.")
|
22
|
+
else
|
23
|
+
say("Request failed: [#{response[:message]}]")
|
24
|
+
end
|
25
|
+
return status
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/epc/config.rb
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EPC
|
5
|
+
class Config
|
6
|
+
class << self
|
7
|
+
attr_accessor :target_file, :target_url, :caller_file, :caller_id,
|
8
|
+
:token_file, :auth_token, :solutions_projects_file, :solutions_projects, :username_file, :username
|
9
|
+
end
|
10
|
+
|
11
|
+
DEFAULT_TARGET = 'localhost:3000'
|
12
|
+
|
13
|
+
# Server Paths
|
14
|
+
SCOPE = '/api/v1'
|
15
|
+
TOKENS_PATH = "#{SCOPE}/tokens"
|
16
|
+
SOLUTIONS_PATH = "#{SCOPE}/solutions"
|
17
|
+
PROJECTS_PATH = "#{SCOPE}/projects"
|
18
|
+
PUSHES_PATH = "#{SCOPE}/pushes"
|
19
|
+
USERS_PATH = "#{SCOPE}/users"
|
20
|
+
BUILDS_PATH = "#{SCOPE}/builds"
|
21
|
+
PULLS_PATH = "#{SCOPE}/pulls"
|
22
|
+
DEPLOYMENTS_PATH = "#{SCOPE}/deployments"
|
23
|
+
CONFIGURATIONS_PATH = "#{SCOPE}/config_values"
|
24
|
+
RUNTIMES_PATH = "#{SCOPE}/runtime_envs"
|
25
|
+
SERVICE_TYPES_PATH = "#{SCOPE}/service_types"
|
26
|
+
SERVICE_DEFINITIONS_PATH = "#{SCOPE}/service_definitions"
|
27
|
+
DEPLOYMENT_CONFIGS_PATH = "#{SCOPE}/deployment_configs"
|
28
|
+
DEPLOYMENT_STAGES_PATH = "#{SCOPE}/deployment_stages"
|
29
|
+
DEPENDENCIES_PATH = "#{SCOPE}/dependency_definitions"
|
30
|
+
LIBRARIES_PATH = "#{SCOPE}/libraries"
|
31
|
+
LIBRARY_LANGUAGES_PATH = "#{SCOPE}/library_languages"
|
32
|
+
LIBRARY_SETS_PATH = "#{SCOPE}/library_sets"
|
33
|
+
SERVICE_VERSIONS_PATH = "#{SCOPE}/service_versions"
|
34
|
+
PROJECT_TYPES_PATH = "#{SCOPE}/project_types"
|
35
|
+
GROUPS_PATH = "#{SCOPE}/user_groups"
|
36
|
+
ROLES_PATH = "#{SCOPE}/roles"
|
37
|
+
PERMISSIONS_PATH = "#{SCOPE}/permissions"
|
38
|
+
GRANTS_PATH = "#{SCOPE}/grants"
|
39
|
+
OBJECT_TYPES_PATH = "#{SCOPE}/object_type_identifiers"
|
40
|
+
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def target_file
|
44
|
+
@target_file || '~/.epc_target'
|
45
|
+
end
|
46
|
+
|
47
|
+
def target_url
|
48
|
+
# return @target_url if @target_url
|
49
|
+
|
50
|
+
file = File.expand_path(target_file)
|
51
|
+
if File.exists?(file)
|
52
|
+
@target_url = File.read(file).strip!
|
53
|
+
else
|
54
|
+
@target_url = DEFAULT_TARGET
|
55
|
+
end
|
56
|
+
@target_url = "http://#{@target_url}" unless @target_url =~ /^https?/
|
57
|
+
@target_url = @target_url.gsub(/\/+$/, '')
|
58
|
+
|
59
|
+
@target_url
|
60
|
+
end
|
61
|
+
|
62
|
+
def store_target_url(url)
|
63
|
+
file = File.expand_path(target_file)
|
64
|
+
File.open(file, 'w+') { |f| f.puts(url) }
|
65
|
+
FileUtils.chmod(0600, file)
|
66
|
+
end
|
67
|
+
|
68
|
+
def caller_file
|
69
|
+
@caller_file || '~/.epc_caller'
|
70
|
+
end
|
71
|
+
|
72
|
+
def caller_id
|
73
|
+
return @caller_id if @caller_id
|
74
|
+
|
75
|
+
file = File.expand_path(caller_file)
|
76
|
+
if File.exists?(file)
|
77
|
+
@caller_id = File.read(file).strip!
|
78
|
+
end
|
79
|
+
|
80
|
+
@caller_id
|
81
|
+
end
|
82
|
+
|
83
|
+
def store_caller_id(caller_id)
|
84
|
+
file = File.expand_path(caller_file)
|
85
|
+
File.open(file, 'w+') { |f| f.puts(caller_id) }
|
86
|
+
FileUtils.chmod(0600, file)
|
87
|
+
end
|
88
|
+
|
89
|
+
def username_file
|
90
|
+
@username_file || '~/.epc_user'
|
91
|
+
end
|
92
|
+
|
93
|
+
def store_username(username)
|
94
|
+
file = File.expand_path(username_file)
|
95
|
+
File.open(file, 'w+') { |f| f.puts(username) }
|
96
|
+
FileUtils.chmod(0600, file)
|
97
|
+
end
|
98
|
+
|
99
|
+
def remove_username
|
100
|
+
FileUtils.rm_f(File.expand_path(username_file))
|
101
|
+
end
|
102
|
+
|
103
|
+
def username
|
104
|
+
return @username if @username
|
105
|
+
|
106
|
+
file = File.expand_path(username_file)
|
107
|
+
if File.exists?(file)
|
108
|
+
@username = File.read(file).strip!
|
109
|
+
end
|
110
|
+
|
111
|
+
@username
|
112
|
+
end
|
113
|
+
|
114
|
+
def token_file
|
115
|
+
@token_file || '~/.epc_token'
|
116
|
+
end
|
117
|
+
|
118
|
+
def auth_token
|
119
|
+
return @auth_token if @auth_token
|
120
|
+
|
121
|
+
file = File.expand_path(token_file)
|
122
|
+
if File.exists?(file)
|
123
|
+
@auth_token = File.read(file).strip!
|
124
|
+
end
|
125
|
+
|
126
|
+
@auth_token
|
127
|
+
end
|
128
|
+
|
129
|
+
def store_auth_token(token)
|
130
|
+
file = File.expand_path(token_file)
|
131
|
+
File.open(file, 'w+') { |f| f.puts(token) }
|
132
|
+
FileUtils.chmod(0600, file)
|
133
|
+
end
|
134
|
+
|
135
|
+
def remove_auth_token
|
136
|
+
FileUtils.rm_f(File.expand_path(token_file))
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
def underscore(camel_cased_word)
|
141
|
+
camel_cased_word.to_s.gsub(/::/, '/').
|
142
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
143
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
144
|
+
tr("-", "_").
|
145
|
+
downcase
|
146
|
+
end
|
147
|
+
|
148
|
+
# Solutions Projects Management
|
149
|
+
# These convenience methods are here to keep each command from having to know
|
150
|
+
# the structure of the file. This also gives Config control over when to
|
151
|
+
# re-write the file.
|
152
|
+
#
|
153
|
+
def read_content_as_json(file)
|
154
|
+
return JSON.parse(File.read(file)) rescue {}
|
155
|
+
end
|
156
|
+
|
157
|
+
def write_content_as_json(file, content)
|
158
|
+
File.open(file, "w+") {|f| f.puts(content.to_json)}
|
159
|
+
end
|
160
|
+
|
161
|
+
# SOLUTION METHODS
|
162
|
+
|
163
|
+
|
164
|
+
def add_solution(solution_name, solution_id)
|
165
|
+
file = File.join(File.expand_path(solution_name), ".epc_solution")
|
166
|
+
write_content_as_json(file, {:name => solution_name, :id => solution_id})
|
167
|
+
FileUtils.chmod(0600, file)
|
168
|
+
end
|
169
|
+
|
170
|
+
def get_solution_value(path, value)
|
171
|
+
return read_content_as_json(File.join(path, ".epc_solution"))[value] rescue nil
|
172
|
+
end
|
173
|
+
|
174
|
+
def set_solution_value(path, key, value)
|
175
|
+
path += "/.epc_solution"
|
176
|
+
content = read_content_as_json(path)
|
177
|
+
content[key] = value
|
178
|
+
write_content_as_json(path, content)
|
179
|
+
end
|
180
|
+
|
181
|
+
def is_solution_dir?(dirname)
|
182
|
+
return File.exists?(File.join(File.expand_path(dirname), ".epc_solution"))
|
183
|
+
end
|
184
|
+
|
185
|
+
def update_solution_metadata(data, path)
|
186
|
+
set_solution_value(path, "id", data[:id])
|
187
|
+
set_solution_value(path, "name", data[:name])
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
def update_solution_directory(path)
|
192
|
+
parent_dir = File.join(path, "../")
|
193
|
+
new_name = get_solution_value(path, "name")
|
194
|
+
new_path = File.join(parent_dir, new_name)
|
195
|
+
(FileUtils.mv(path, new_path) unless path.split("/").last == new_name) rescue ""
|
196
|
+
end
|
197
|
+
|
198
|
+
# PROJECT METHODS
|
199
|
+
|
200
|
+
def write_project_metadata(project_id, client, base_path = nil)
|
201
|
+
attributes = [:id, :name, :solution_id, :project_type]
|
202
|
+
status, response, headers = client.get(PROJECTS_PATH + "/#{project_id}")
|
203
|
+
if status.failure? || response.empty?
|
204
|
+
raise Exception, "cannot retrieve project details"
|
205
|
+
end
|
206
|
+
metadata = response.keep_if{|k,v| attributes.include?(k)}
|
207
|
+
if base_path.nil?
|
208
|
+
file = File.join(File.expand_path(metadata[:name]), ".epc_project")
|
209
|
+
else
|
210
|
+
file = File.join(base_path, ".epc_project")
|
211
|
+
end
|
212
|
+
write_content_as_json(file, metadata)
|
213
|
+
FileUtils.chmod(0600, file)
|
214
|
+
end
|
215
|
+
|
216
|
+
def update_project_metadata(data, path)
|
217
|
+
set_project_value(path, "id", data[:id])
|
218
|
+
set_project_value(path, "name", data[:name])
|
219
|
+
end
|
220
|
+
|
221
|
+
def get_project_value(path, value)
|
222
|
+
return read_content_as_json(path + "/.epc_project")[value] rescue nil
|
223
|
+
end
|
224
|
+
|
225
|
+
def set_project_value(path, key, value)
|
226
|
+
path += "/.epc_project"
|
227
|
+
content = read_content_as_json(path)
|
228
|
+
content[key] = value
|
229
|
+
write_content_as_json(path, content)
|
230
|
+
end
|
231
|
+
|
232
|
+
def update_project_directory(path)
|
233
|
+
parent_dir = File.join(path, "..")
|
234
|
+
new_name = get_project_value(path, "name")
|
235
|
+
new_path = File.join(parent_dir, new_name)
|
236
|
+
FileUtils.mv path, new_path unless path.split("/").last == new_name
|
237
|
+
end
|
238
|
+
|
239
|
+
def is_project_dir?(dirname)
|
240
|
+
return File.exists?(File.join(File.expand_path(dirname), ".epc_project"))
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
data/lib/epc/help.rb
ADDED
@@ -0,0 +1,292 @@
|
|
1
|
+
module EPC
|
2
|
+
module Help
|
3
|
+
COMMAND_USAGES = {
|
4
|
+
:info => 'epc info',
|
5
|
+
:target => 'epc target <url>',
|
6
|
+
:login => 'epc login <email> [--passwd PASS]',
|
7
|
+
:list_solutions => 'epc list solutions',
|
8
|
+
:create_solution => 'epc create solution <name>',
|
9
|
+
:show_solution => 'epc show solution [SOLUTION]',
|
10
|
+
:update_solution => 'epc update solution [-s SOLUTION] name=value',
|
11
|
+
:delete_solution => 'epc delete solution SOLUTION',
|
12
|
+
:archive_solution => 'epc archive solution [SOLUTION]',
|
13
|
+
:unarchive_solution => 'epc unarchive solution [SOLUTION]',
|
14
|
+
:refresh_solution => 'epc refresh solution [SOLUTION]',
|
15
|
+
:list_projects => 'epc list projects [SOLUTION]',
|
16
|
+
:create_project => 'epc create project <name> [uri-name] <--type PROJECT_TYPE>',
|
17
|
+
:show_project => 'epc show project [-s SOLUTION] <PROJECT>',
|
18
|
+
:update_project => 'epc update project [-s SOLUTION] [-p PROJECT] <attribute=value>',
|
19
|
+
:delete_project => 'epc delete project [-s SOLUTION] [PROJECT] [--force]',
|
20
|
+
:attach_runtime => 'epc attach runtime <runtime_id> [-p PROJECT] [--stage STAGE]',
|
21
|
+
:list_servicetypes => 'epc list service-types',
|
22
|
+
:define_service => 'epc define service <-t service_type> <service_name>',
|
23
|
+
:undefine_service => 'epc undefine service <SERVICE>',
|
24
|
+
:list_servicedefinitions => 'epc list service-definitions',
|
25
|
+
:create_serviceversion => 'epc create service-version <label> <definition_name_or_id> [--up-script file] [--down-script file]',
|
26
|
+
:list_serviceversions => 'epc list service-versions',
|
27
|
+
:delete_serviceversion => 'epc delete service-version (<version_id>) || (<version_label> <definition_name>)',
|
28
|
+
:bind_service => 'epc bind service [-s SOLUTION] [-p PROJECT] <service version>',
|
29
|
+
:unbind_service => 'epc unbind service [-s SOLUTION] [-p PROJECT] <service version>',
|
30
|
+
:list_boundservices => 'epc list bound-services [-s SOLUTION] <PROJECT>',
|
31
|
+
:create_user => 'epc create user <email> [--name NAME]',
|
32
|
+
:push => 'epc push [PROJECT NAME] [--note NOTE] [--timeout value | --nopoll]',
|
33
|
+
:pull => 'epc pull [SOLUTION]',
|
34
|
+
:build => 'epc build [project_name=version] [--note NOTE] [--timeout value | --nopoll]',
|
35
|
+
:list_deploymentconfigs => 'epc list deployment-configs [--stage STAGE] [-p PROJECT]',
|
36
|
+
:list_stages => 'epc list stages',
|
37
|
+
:create_deployment => 'epc create deployment [-s SOLUTION] <stage name: development|testing|staging|production> [-p project_id:version:instances] [--replaces deployment_id]',
|
38
|
+
:show_deployment => 'epc show deployment <DEPLOYMENT_ID>',
|
39
|
+
:submit_deployment => 'epc submit deployment <DEPLOYMENT_ID>',
|
40
|
+
:list_deployments => 'epc list deployments [-s SOLUTION] [-S STAGE] [-u DEPLOYER]',
|
41
|
+
:copy_deployment => 'epc copy deployment <DEPLOYMENT_ID> <STAGE>',
|
42
|
+
:approve_deployment => 'epc approve deployment <DEPLOYMENT_ID>',
|
43
|
+
:deny_deployment => 'epc deny deployment <DEPLOYMENT_ID>',
|
44
|
+
:create_dependency => 'epc create dependency [PROJECT] [-s SOLUTION] <--depends DEPENDENCY> <--runtime | --compile>',
|
45
|
+
:list_dependencies => 'epc list dependencies [-s SOLUTION] [PROJECT]',
|
46
|
+
:delete_dependency => 'epc delete dependency [-s SOLUTION] [-p PROJECT] <DEPENDENCY_ID>',
|
47
|
+
:create_library => 'epc create library <name> <language> <version> <group> [-f file] [--scope runtime | compile | provided | test]',
|
48
|
+
:list_libraries => 'epc list libraries',
|
49
|
+
:delete_library => 'epc delete library <name> <version> <group>',
|
50
|
+
:attach_library => 'epc attach library [-s SOLUTION] [-p PROJECT] <name> <version> <group> [-f FILE] [--pom POM FILE]',
|
51
|
+
:detach_library => 'epc detach library [-s SOLUTION] [-p PROJECT] <LIBRARY>',
|
52
|
+
:deploy => 'epc deploy [stage] [-d DEPLOYMENT_ID] [--timeout value | --nopoll]',
|
53
|
+
:undeploy => 'epc undeploy [-s SOLUTION] <DEPLOYMENT_ID>',
|
54
|
+
:list_approvals => 'epc list approvals <DEPLOYMENT_ID>',
|
55
|
+
:renew => 'epc renew',
|
56
|
+
:logout => 'epc logout',
|
57
|
+
:create_config => 'epc create config <TargetType:TargetId> [--required] [--no_override] [--value-type TYPE] name=value',
|
58
|
+
:list_config => 'epc list config <TargetType:TargetType>',
|
59
|
+
:list_projecttypes => 'epc list project-types',
|
60
|
+
:show_projecttype => 'epc show project-type <project_type_id>',
|
61
|
+
:update_deploymentproject => 'epc update deployment-project <DEPLOYMENT_ID> <PROJECT> [--instances instance_count] [--uris comma_separated_uris]',
|
62
|
+
:list_versions => 'epc list versions [-s SOLUTION] PROJECT',
|
63
|
+
:update_config => 'epc update config <--org | --runtime | --stage | --solution | --project | --user id> [--required] [--no_override] name=value',
|
64
|
+
:archive_project => 'epc archive project [-s SOLUTION] PROJECT',
|
65
|
+
:unarchive_project => 'epc unarchive project [-s SOLUTION] PROJECT',
|
66
|
+
:list_attachedlibraries => 'epc list attached-libraries [-s SOLUTION] [PROJECT] [--json]',
|
67
|
+
:create_group => 'epc create group <name>',
|
68
|
+
:delete_group => 'epc delete group <GROUP>',
|
69
|
+
:list_groups => 'epc list groups',
|
70
|
+
:update_group => 'epc update group <GROUP> [--add-user USER_ID] [--remove-user USER_ID]',
|
71
|
+
:show_group => 'epc show group <groupId>|<groupName>',
|
72
|
+
:list_roles => 'epc list roles [--user user_id]',
|
73
|
+
:list_objectroles => 'epc list object-roles <ObjectType:ObjectId>',
|
74
|
+
:delete_role => 'epc delete role',
|
75
|
+
:update_role => 'epc update role <ROLE> [--add-user USER_ID] [--remove-user USER_ID]',
|
76
|
+
:create_role => 'epc create role <name>',
|
77
|
+
:create_objectrole => 'epc create role <name> <ObjectType:ObjectId>',
|
78
|
+
:show_role => 'epc show role <roleId>|<roleName>',
|
79
|
+
:list_users => 'epc list users',
|
80
|
+
:delete_user => 'epc delete user <user_id>|<email>',
|
81
|
+
:show_user => 'epc show user <user_id>|<email>',
|
82
|
+
:create_librarylanguage => 'epc create library-language <name>',
|
83
|
+
:list_librarylanguages => 'epc list library-languages',
|
84
|
+
:delete_librarylanguage => 'epc delete library-language <language>',
|
85
|
+
:update_librarylanguage => 'epc update library-language <language> <new-name>',
|
86
|
+
:create_libraryset => 'epc create library-set <name> <language> [--file file]',
|
87
|
+
:show_libraryset => 'epc show library-set <name>|<id> [--json]',
|
88
|
+
:list_librarysets => 'epc show library-sets',
|
89
|
+
:update_libraryset => 'epc update library-set name|id [--add-library id|name:version:group] [--remove-library id|name:version:group] [--file file]',
|
90
|
+
:delete_libraryset => 'epc delete library-set name|id [-y]',
|
91
|
+
:attach_libraryset => 'epc attach library-set name|id [-s solution] [-p project]',
|
92
|
+
:detach_libraryset => 'epc detach library-set name|id [-s solution] [-p project]',
|
93
|
+
:request_passwordchange => 'epc request password-change <email>',
|
94
|
+
:update_user => 'epc update user <user_id>|<email> [--passwd password] [--token token] [--email new_email] [--name new_name]',
|
95
|
+
:list_rolepermissions => 'epc list role-permissions',
|
96
|
+
:update_rolepermissions => 'epc update role-permissions <--add-grant ObjectType:action:ObjectId> <--remove-grant ObjectType:action:ObjectId> [--file json]',
|
97
|
+
:list_permissiongroups => 'epc list permission-groups',
|
98
|
+
:list_objecttypes => 'epc list object-types'
|
99
|
+
}
|
100
|
+
|
101
|
+
def display_usage
|
102
|
+
say(usage)
|
103
|
+
exit
|
104
|
+
end
|
105
|
+
|
106
|
+
def display_verbose_usage
|
107
|
+
say(verbose_usage)
|
108
|
+
end
|
109
|
+
|
110
|
+
def display_command_usage(*commands)
|
111
|
+
if commands.empty?
|
112
|
+
say verbose_usage
|
113
|
+
return
|
114
|
+
end
|
115
|
+
key = commands.join('_').gsub("-", "").to_sym
|
116
|
+
if COMMAND_USAGES.keys.include?(key)
|
117
|
+
say("Usage: #{COMMAND_USAGES[key]}")
|
118
|
+
else
|
119
|
+
say("No such command: #{commands.join(' ')}")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def usage
|
126
|
+
"Usage: epc command [<args>] [command_options]\n"
|
127
|
+
end
|
128
|
+
|
129
|
+
def verbose_usage
|
130
|
+
<<-USAGE
|
131
|
+
|
132
|
+
#{usage}
|
133
|
+
|
134
|
+
Currently available epc commands are:
|
135
|
+
|
136
|
+
Getting Started
|
137
|
+
target Sets a new target
|
138
|
+
login Logs user into the target system
|
139
|
+
|
140
|
+
|
141
|
+
Solutions
|
142
|
+
list solutions Lists the solutions that the current user has
|
143
|
+
access to
|
144
|
+
show solution Retrieves details about the solution
|
145
|
+
create solution Creates a solution with the given name
|
146
|
+
update solution Updates the attribute of the solution
|
147
|
+
delete solution Deletes the solution from the system and removes
|
148
|
+
local metadata files.
|
149
|
+
Does not remove local directories.
|
150
|
+
archive solution Archives the solution. Arabeline, kschived solution do
|
151
|
+
not appear when listing solutions.
|
152
|
+
unarchive solution Archives solution.
|
153
|
+
The solution will appear in solution listings.
|
154
|
+
refresh solution Retrieves and stores attributes for a solution.
|
155
|
+
|
156
|
+
pull Downloads and extracts a solution skeleton
|
157
|
+
|
158
|
+
|
159
|
+
Projects
|
160
|
+
list projects Lists projects.
|
161
|
+
create project Creates a project with the given name and
|
162
|
+
assigns it to a solution
|
163
|
+
show project Retrieves details about the project.
|
164
|
+
update project Updates the specified attributes.
|
165
|
+
delete project Deletes the project.Removes only the
|
166
|
+
metadata files.
|
167
|
+
All other files are left intact.
|
168
|
+
epc create dependency Creates a dependency such as parent_name_or_id will
|
169
|
+
depend on dependency_name_or_id.
|
170
|
+
You can choose between a runtime dependency
|
171
|
+
or a compilation dependency.
|
172
|
+
epc list dependencies Lists the projects that the current project
|
173
|
+
depends on.
|
174
|
+
epc delete dependencies Deletes the specified dependency.
|
175
|
+
epc bind service Binds the service to the project.
|
176
|
+
epc unbind service Unbinds the service from the project.
|
177
|
+
epc list bound-services Lists the services bound to the project
|
178
|
+
attach runtime Sets the runtime environment the project
|
179
|
+
will run on at deployment.
|
180
|
+
list project-types Lists available project types.
|
181
|
+
show project-type Show details about a project type
|
182
|
+
list versions Lists the project versions.
|
183
|
+
|
184
|
+
|
185
|
+
Services
|
186
|
+
list service-types List available service types provided by ePaas
|
187
|
+
define service Defines a service
|
188
|
+
undefine service Undefines a service
|
189
|
+
list service-definitions Lists services
|
190
|
+
create service-version Creates a service version from an existing
|
191
|
+
service definition.
|
192
|
+
list service-versions Lists all service versions defined.
|
193
|
+
delete service-version Deletes the specified service version.
|
194
|
+
|
195
|
+
|
196
|
+
Deployments
|
197
|
+
push Zips the project and pushes it to the
|
198
|
+
build manager repository
|
199
|
+
build Builds a previously pushed project
|
200
|
+
show deployment Retrieves detailed information about
|
201
|
+
the deployment
|
202
|
+
list stages Lists available stages for deploying.
|
203
|
+
create deployment Creates a deployment for a solution
|
204
|
+
and the given stage
|
205
|
+
list deployments Lists all deployments created
|
206
|
+
approve deployment Approves the specified deployment
|
207
|
+
deny deployment Denies the specified deployment
|
208
|
+
deploy Deploys a previously created deployment
|
209
|
+
list approvals List approvals needed by the deployment
|
210
|
+
copy deployment Copies a previously created deployment
|
211
|
+
to the specified stage
|
212
|
+
update deployment-project Updates projects from a deployment. Can
|
213
|
+
change the number of instances a project
|
214
|
+
is deployed to with --instances, or
|
215
|
+
change the uris where the project will be
|
216
|
+
accessible with --uris.
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
Libraries
|
221
|
+
create library Creates a library with the given parameters
|
222
|
+
list libraries Lists available libraries
|
223
|
+
delete library Deletes the library
|
224
|
+
list attached-libraries Lists attached libraries
|
225
|
+
attach library Attaches the library to the project.
|
226
|
+
detach library Detaches the library from the project.
|
227
|
+
create library-language Creates a new language for libraries.
|
228
|
+
list library-languages Lists library languages defined.
|
229
|
+
delete library-language Deletes a library language
|
230
|
+
update library-language Updates a library language
|
231
|
+
create library-set Creates a library set
|
232
|
+
show library-set Retrieves details about a library-set
|
233
|
+
list library-sets Lists library sets defined
|
234
|
+
update library-set Allows adding/removing of libraries from
|
235
|
+
the set
|
236
|
+
delete library-set Deletes a library-set
|
237
|
+
attach library-set Attaches the libraries in the set to the
|
238
|
+
specified project
|
239
|
+
|
240
|
+
detach library-set Detaches the libraries in the set from
|
241
|
+
the specified project
|
242
|
+
|
243
|
+
|
244
|
+
Configuration
|
245
|
+
list config Lists all configuration options
|
246
|
+
create config Sets the value of of <key>
|
247
|
+
update config Updates the value of <key> with <value>
|
248
|
+
remove config Removes <key>
|
249
|
+
|
250
|
+
Roles
|
251
|
+
create role Creates a role
|
252
|
+
list roles Lists roles available
|
253
|
+
delete role Deletes a role
|
254
|
+
update role Adds/removes user to a role
|
255
|
+
show role Retrieves details about the role
|
256
|
+
list role-permissions List permission that are grantable to a role
|
257
|
+
update role-permissions Adds/removes grants to a role
|
258
|
+
list object-roles Lists roles that belong to a specified object
|
259
|
+
list permission-groups Lists permission groups
|
260
|
+
list object-types Lists available objects in the system
|
261
|
+
|
262
|
+
Users
|
263
|
+
list users List users
|
264
|
+
show user Retrieves details about the user
|
265
|
+
delete user Deletes a user
|
266
|
+
update user Allows changing of a users email
|
267
|
+
or password
|
268
|
+
create group Creates a user group
|
269
|
+
delete group Deletes an empty group
|
270
|
+
list groups Lists user groups
|
271
|
+
update group Allows you to add or remove users from
|
272
|
+
the group
|
273
|
+
show group Retrieves details about the group
|
274
|
+
request password-change Sends a request for a password change to
|
275
|
+
the server. The user will receive an
|
276
|
+
email with the password change token.
|
277
|
+
|
278
|
+
|
279
|
+
Administration
|
280
|
+
create user Creates a new user account with the target system
|
281
|
+
renew Refreshes the current user login
|
282
|
+
session with the target system
|
283
|
+
logout Logs current user out of the target system
|
284
|
+
|
285
|
+
|
286
|
+
Help
|
287
|
+
help Shows the usage for the command
|
288
|
+
|
289
|
+
USAGE
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|