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.
Files changed (215) hide show
  1. data/CHANGELOG +1 -0
  2. data/Gemfile +22 -0
  3. data/Rakefile +67 -0
  4. data/Rakefile.gem +1 -0
  5. data/bin/epc +10 -0
  6. data/lib/epc.rb +126 -0
  7. data/lib/epc/client/base_client.rb +80 -0
  8. data/lib/epc/client/http_client.rb +19 -0
  9. data/lib/epc/client/json_client.rb +48 -0
  10. data/lib/epc/command/archive_project_command.rb +24 -0
  11. data/lib/epc/command/archive_solution_command.rb +21 -0
  12. data/lib/epc/command/attach_library_command.rb +82 -0
  13. data/lib/epc/command/attach_libraryset_command.rb +32 -0
  14. data/lib/epc/command/attach_runtime_command.rb +27 -0
  15. data/lib/epc/command/base_command.rb +451 -0
  16. data/lib/epc/command/bind_service_command.rb +35 -0
  17. data/lib/epc/command/build_command.rb +83 -0
  18. data/lib/epc/command/config/create_config_command.rb +55 -0
  19. data/lib/epc/command/copy_deployment_command.rb +21 -0
  20. data/lib/epc/command/create_command.rb +13 -0
  21. data/lib/epc/command/create_dependency_command.rb +43 -0
  22. data/lib/epc/command/define_service_command.rb +37 -0
  23. data/lib/epc/command/delete_config_command.rb +63 -0
  24. data/lib/epc/command/delete_dependency_command.rb +40 -0
  25. data/lib/epc/command/delete_group_command.rb +40 -0
  26. data/lib/epc/command/delete_library_command.rb +30 -0
  27. data/lib/epc/command/delete_librarylanguage_command.rb +40 -0
  28. data/lib/epc/command/delete_libraryset_command.rb +40 -0
  29. data/lib/epc/command/delete_project_command.rb +54 -0
  30. data/lib/epc/command/delete_role_command.rb +25 -0
  31. data/lib/epc/command/delete_serviceversion_command.rb +52 -0
  32. data/lib/epc/command/delete_solution_command.rb +39 -0
  33. data/lib/epc/command/delete_user_command.rb +31 -0
  34. data/lib/epc/command/deploy_command.rb +142 -0
  35. data/lib/epc/command/deployment/create_deployment_command.rb +82 -0
  36. data/lib/epc/command/detach_library_command.rb +35 -0
  37. data/lib/epc/command/detach_libraryset_command.rb +8 -0
  38. data/lib/epc/command/group/create_group_command.rb +21 -0
  39. data/lib/epc/command/info_command.rb +11 -0
  40. data/lib/epc/command/library/create_library_command.rb +45 -0
  41. data/lib/epc/command/librarylanguage/create_librarylanguage_command.rb +24 -0
  42. data/lib/epc/command/libraryset/create_libraryset_command.rb +54 -0
  43. data/lib/epc/command/list_approvals_command.rb +27 -0
  44. data/lib/epc/command/list_attachedlibraries_command.rb +42 -0
  45. data/lib/epc/command/list_boundservices_command.rb +40 -0
  46. data/lib/epc/command/list_config_command.rb +60 -0
  47. data/lib/epc/command/list_dependencies_command.rb +43 -0
  48. data/lib/epc/command/list_deployments_command.rb +68 -0
  49. data/lib/epc/command/list_groups_command.rb +19 -0
  50. data/lib/epc/command/list_libraries_command.rb +19 -0
  51. data/lib/epc/command/list_librarylanguages_command.rb +19 -0
  52. data/lib/epc/command/list_librarysets_command.rb +26 -0
  53. data/lib/epc/command/list_objectroles_command.rb +25 -0
  54. data/lib/epc/command/list_objecttypes_command.rb +20 -0
  55. data/lib/epc/command/list_permissiongroups_command.rb +20 -0
  56. data/lib/epc/command/list_projects_command.rb +36 -0
  57. data/lib/epc/command/list_projecttypes_command.rb +20 -0
  58. data/lib/epc/command/list_rolepermissions_command.rb +21 -0
  59. data/lib/epc/command/list_roles_command.rb +26 -0
  60. data/lib/epc/command/list_runtimes_command.rb +16 -0
  61. data/lib/epc/command/list_service_types_command.rb +19 -0
  62. data/lib/epc/command/list_servicedefinitions_command.rb +19 -0
  63. data/lib/epc/command/list_serviceversions_command.rb +21 -0
  64. data/lib/epc/command/list_solutions_command.rb +25 -0
  65. data/lib/epc/command/list_stages_command.rb +21 -0
  66. data/lib/epc/command/list_users_command.rb +26 -0
  67. data/lib/epc/command/list_versions_command.rb +39 -0
  68. data/lib/epc/command/login_command.rb +32 -0
  69. data/lib/epc/command/logout_command.rb +20 -0
  70. data/lib/epc/command/objectrole/create_objectrole_command.rb +19 -0
  71. data/lib/epc/command/project/create_project_command.rb +78 -0
  72. data/lib/epc/command/pull_command.rb +209 -0
  73. data/lib/epc/command/push_command.rb +194 -0
  74. data/lib/epc/command/refresh_solution_command.rb +71 -0
  75. data/lib/epc/command/renew_command.rb +19 -0
  76. data/lib/epc/command/request_passwordchange_command.rb +23 -0
  77. data/lib/epc/command/role/create_role_command.rb +17 -0
  78. data/lib/epc/command/serviceversion/create_serviceversion_command.rb +33 -0
  79. data/lib/epc/command/show_deployment_command.rb +57 -0
  80. data/lib/epc/command/show_group_command.rb +35 -0
  81. data/lib/epc/command/show_libraryset_command.rb +54 -0
  82. data/lib/epc/command/show_project_command.rb +74 -0
  83. data/lib/epc/command/show_projecttype_command.rb +18 -0
  84. data/lib/epc/command/show_role_command.rb +46 -0
  85. data/lib/epc/command/show_solution_command.rb +54 -0
  86. data/lib/epc/command/show_user_command.rb +42 -0
  87. data/lib/epc/command/solution/create_solution_command.rb +34 -0
  88. data/lib/epc/command/solution/list_solutions_command.rb +25 -0
  89. data/lib/epc/command/solution/update_solution_command.rb +43 -0
  90. data/lib/epc/command/submit_deployment_command.rb +19 -0
  91. data/lib/epc/command/target_command.rb +26 -0
  92. data/lib/epc/command/unarchive_project_command.rb +23 -0
  93. data/lib/epc/command/unarchive_solution_command.rb +21 -0
  94. data/lib/epc/command/unbind_service_command.rb +42 -0
  95. data/lib/epc/command/undefine_service_command.rb +33 -0
  96. data/lib/epc/command/undeploy_command.rb +106 -0
  97. data/lib/epc/command/update_config_command.rb +62 -0
  98. data/lib/epc/command/update_deploymentproject_command.rb +54 -0
  99. data/lib/epc/command/update_group_command.rb +43 -0
  100. data/lib/epc/command/update_librarylanguage_command.rb +28 -0
  101. data/lib/epc/command/update_libraryset_command.rb +80 -0
  102. data/lib/epc/command/update_project_command.rb +49 -0
  103. data/lib/epc/command/update_role_command.rb +47 -0
  104. data/lib/epc/command/update_rolepermissions_command.rb +83 -0
  105. data/lib/epc/command/update_solution_command.rb +45 -0
  106. data/lib/epc/command/update_user_command.rb +57 -0
  107. data/lib/epc/command/user/create_user_command.rb +27 -0
  108. data/lib/epc/command/vote_deployment_command.rb +29 -0
  109. data/lib/epc/config.rb +245 -0
  110. data/lib/epc/error/basic_error.rb +6 -0
  111. data/lib/epc/error/fatal_error.rb +6 -0
  112. data/lib/epc/error/input_error.rb +6 -0
  113. data/lib/epc/error/internal_error.rb +6 -0
  114. data/lib/epc/help.rb +292 -0
  115. data/lib/epc/persistent_attributes.rb +18 -0
  116. data/lib/epc/runner.rb +177 -0
  117. data/lib/epc/tabular_outputter.rb +161 -0
  118. data/lib/epc/version.rb +3 -0
  119. data/lib/fixnum.rb +9 -0
  120. data/lib/object.rb +13 -0
  121. data/test/command/archive_project_command_test.rb +41 -0
  122. data/test/command/archive_solution_command_test.rb +40 -0
  123. data/test/command/attach_library_command_test.rb +124 -0
  124. data/test/command/attach_libraryset_command_test.rb +49 -0
  125. data/test/command/attach_runtime_command_test.rb +44 -0
  126. data/test/command/base_command_test.rb +276 -0
  127. data/test/command/bind_service_command_test.rb +46 -0
  128. data/test/command/build_command_test.rb +103 -0
  129. data/test/command/copy_deployment_command_test.rb +38 -0
  130. data/test/command/create_config_command_test.rb +124 -0
  131. data/test/command/create_dependency_command_test.rb +55 -0
  132. data/test/command/create_deployment_command_test.rb +136 -0
  133. data/test/command/create_group_command_test.rb +34 -0
  134. data/test/command/create_library_command_test.rb +61 -0
  135. data/test/command/create_librarylanguage_command_test.rb +51 -0
  136. data/test/command/create_libraryset_command_test.rb +81 -0
  137. data/test/command/create_objectrole_command_test.rb +37 -0
  138. data/test/command/create_project_command_test.rb +102 -0
  139. data/test/command/create_role_command_test.rb +31 -0
  140. data/test/command/create_serviceversion_command_test.rb +60 -0
  141. data/test/command/create_solution_command_test.rb +70 -0
  142. data/test/command/create_user_command_test.rb +54 -0
  143. data/test/command/define_service_command_test.rb +55 -0
  144. data/test/command/delete_config_command_test.rb +82 -0
  145. data/test/command/delete_dependency_command_test.rb +50 -0
  146. data/test/command/delete_group_command_test.rb +56 -0
  147. data/test/command/delete_library_command_test.rb +43 -0
  148. data/test/command/delete_librarylanguage_command_test.rb +55 -0
  149. data/test/command/delete_libraryset_command_test.rb +55 -0
  150. data/test/command/delete_project_command_test.rb +76 -0
  151. data/test/command/delete_role_command_test.rb +41 -0
  152. data/test/command/delete_serviceversion_command_test.rb +53 -0
  153. data/test/command/delete_solution_command_test.rb +79 -0
  154. data/test/command/delete_user_command_test.rb +56 -0
  155. data/test/command/deploy_command_test.rb +185 -0
  156. data/test/command/detach_library_command_test.rb +53 -0
  157. data/test/command/info_command_test.rb +17 -0
  158. data/test/command/list_approvals_command_test.rb +41 -0
  159. data/test/command/list_boundservices_command_test.rb +46 -0
  160. data/test/command/list_config_command_test.rb +72 -0
  161. data/test/command/list_dependencies_command_test.rb +46 -0
  162. data/test/command/list_deployments_command_test.rb +112 -0
  163. data/test/command/list_deploymentstages_command_test.rb +44 -0
  164. data/test/command/list_libraries_command_test.rb +42 -0
  165. data/test/command/list_librarylanguages_command_test.rb +34 -0
  166. data/test/command/list_librarysets_command_test.rb +33 -0
  167. data/test/command/list_objectroles_command_test.rb +41 -0
  168. data/test/command/list_objecttypes_command_test.rb +25 -0
  169. data/test/command/list_permissiongroups_command_test.rb +25 -0
  170. data/test/command/list_projects_command_test.rb +63 -0
  171. data/test/command/list_projecttypes_command_test.rb +39 -0
  172. data/test/command/list_rolepermissions_command_test.rb +39 -0
  173. data/test/command/list_roles_command_test.rb +46 -0
  174. data/test/command/list_runtimes_command_test.rb +30 -0
  175. data/test/command/list_service_types_command_test.rb +44 -0
  176. data/test/command/list_servicedefinitions_command_test.rb +44 -0
  177. data/test/command/list_serviceversions_command_test.rb +47 -0
  178. data/test/command/list_solutions_command_test.rb +48 -0
  179. data/test/command/list_users_command_test.rb +33 -0
  180. data/test/command/login_command_test.rb +83 -0
  181. data/test/command/logout_command_test.rb +30 -0
  182. data/test/command/pull_command_test.rb +229 -0
  183. data/test/command/push_command_test.rb +246 -0
  184. data/test/command/refresh_solution_command_test.rb +35 -0
  185. data/test/command/renew_command_test.rb +43 -0
  186. data/test/command/request_passwordchange_command_test.rb +31 -0
  187. data/test/command/show_group_command_test.rb +50 -0
  188. data/test/command/show_libraryset_command_test.rb +51 -0
  189. data/test/command/show_project_command_test.rb +57 -0
  190. data/test/command/show_projecttype_command_test.rb +46 -0
  191. data/test/command/show_role_command_test.rb +37 -0
  192. data/test/command/show_solution_command_test.rb +59 -0
  193. data/test/command/show_user_command_test.rb +50 -0
  194. data/test/command/submit_deployment_command_test.rb +37 -0
  195. data/test/command/target_command_test.rb +58 -0
  196. data/test/command/unarchive_project_command_test.rb +45 -0
  197. data/test/command/unarchive_solution_command_test.rb +43 -0
  198. data/test/command/unbind_service_command_test.rb +48 -0
  199. data/test/command/undefine_service_command_test.rb +49 -0
  200. data/test/command/update_config_command_test.rb +74 -0
  201. data/test/command/update_deploymentproject_command_test.rb +77 -0
  202. data/test/command/update_group_command_test.rb +69 -0
  203. data/test/command/update_librarylanguage_command_test.rb +43 -0
  204. data/test/command/update_libraryset_command_test.rb +113 -0
  205. data/test/command/update_project_command_test.rb +56 -0
  206. data/test/command/update_role_command_test.rb +42 -0
  207. data/test/command/update_rolepermissions_command_test.rb +54 -0
  208. data/test/command/update_solution_command_test.rb +58 -0
  209. data/test/command/update_user_command_test.rb +76 -0
  210. data/test/command/vote_deployment_command_test.rb +33 -0
  211. data/test/config_test.rb +70 -0
  212. data/test/successful_test.rb +21 -0
  213. data/test/test_files/pom.xml +273 -0
  214. data/test/test_helper.rb +25 -0
  215. metadata +470 -0
@@ -0,0 +1,62 @@
1
+ module EPC::Command
2
+ class UpdateConfigCommand < BaseCommand
3
+
4
+
5
+ def execute(*args)
6
+ if args.empty?
7
+ say("You have to specify a key and its value.")
8
+ return 1
9
+ end
10
+
11
+ path = "."
12
+ path = File.expand_path(path)
13
+
14
+ @options[:required] = false if @options[:required].nil?
15
+
16
+ config_type, config_id = extract_configuration_level(path, @options)
17
+ request_path = EPC::Config::CONFIGURATIONS_PATH+"/#{config_type}/#{config_id}"
18
+
19
+ if ["solution", "project"].include?(config_type.downcase) && !@options[:stage].nil?
20
+ request_path += "/#{@options[:stage]}"
21
+ end
22
+
23
+ status, response, headers = client.get(request_path)
24
+
25
+ if status.failure?
26
+ say("Configuration retrieval failed with [#{response[:message]}]")
27
+ return status
28
+ end
29
+
30
+ keys = response
31
+
32
+ args.each do |arg|
33
+ name, value = arg.split("=")
34
+
35
+ key_id = keys.detect{|k| k[:name] == name}[:id] rescue nil
36
+
37
+ if key_id.nil?
38
+ say("Key does not exist.")
39
+ return 1
40
+ end
41
+
42
+ params = {
43
+ :name => name,
44
+ }
45
+ params[:value] = value unless value.nil?
46
+ params[:required] = @options[:required]
47
+ params[:no_override] = @options[:no_override] unless @options[:no_override].nil?
48
+
49
+ status, response, headers = client.put(EPC::Config::CONFIGURATIONS_PATH + "/#{key_id}", params)
50
+
51
+ if status.successful?
52
+ unless response[:id].nil?
53
+ say("#{name} saved.")
54
+ end
55
+ else
56
+ say("Request failed with message [#{response[:message]}]")
57
+ end
58
+ return status
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,54 @@
1
+ module EPC::Command
2
+ class UpdateDeploymentprojectCommand < BaseCommand
3
+
4
+ def execute(deployment_id = nil, project_id = nil)
5
+
6
+ raise FatalError, "All the parameters are mandatory" if deployment_id.blank? || project_id.blank?
7
+
8
+ instances = @options[:instances]
9
+ uris = @options[:uris]
10
+
11
+ raise FatalError, "You need to specify either an instance count or uris" if blank?(instances) && blank?(uris)
12
+
13
+ if numeric?(project_id)
14
+ field = :id
15
+ project_id = project_id.to_i
16
+ else
17
+ field = :name
18
+ end
19
+
20
+ deployed_project_id = get_deployed_project_id(deployment_id, field, project_id)
21
+
22
+ raise FatalError, "Deployed project id not found" if deployed_project_id.nil?
23
+
24
+ params = {}
25
+ params[:instances] = instances.to_i unless blank?(instances)
26
+ params[:uris] = uris.split(",") unless blank?(uris)
27
+
28
+ status, response, headers = client.put(EPC::Config::DEPLOYMENTS_PATH + "/#{deployment_id}/deployed_projects/#{deployed_project_id}", params)
29
+
30
+ if status.successful?
31
+ say("Deployment updated")
32
+ else
33
+ say("Request failed with: [#{response[:message]}]")
34
+ end
35
+ return status
36
+ end
37
+
38
+ private
39
+
40
+ def get_deployed_project_id(deployment_id, project_field, value)
41
+ status, response, headers = client.get(EPC::Config::DEPLOYMENTS_PATH + "/#{deployment_id}")
42
+
43
+ raise FatalError, "Deployed projects retrieval failed: [#{response[:message]}]" if status.failure?
44
+
45
+ return nil if response.blank?
46
+
47
+ projects = response[:solution][:projects] rescue []
48
+ deployed_project_id = projects.detect{|p| p[project_field] == value}[:deployed_project_id] rescue nil
49
+
50
+ deployed_project_id
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,43 @@
1
+ module EPC::Command
2
+ class UpdateGroupCommand < BaseCommand
3
+
4
+ def execute(group = nil)
5
+ if group.nil?
6
+ say("You must specify the group id/name")
7
+ say(EPC::Help::COMMAND_USAGES[:update_group])
8
+ return 1
9
+ end
10
+
11
+ if numeric?(group)
12
+ group_id = group.to_i
13
+ else
14
+ group_id = get_resource_id(EPC::Config::GROUPS_PATH, :name, group)
15
+ end
16
+
17
+ if group_id.nil?
18
+ say("Group could not be found")
19
+ return 1
20
+ end
21
+
22
+ if @options[:add_user].nil? && @options[:remove_user].nil?
23
+ say("You must specify a user to be added or removed")
24
+ return 1
25
+ end
26
+
27
+ failures = []
28
+ if @options[:add_user].present?
29
+ status, response, headers = client.put(EPC::Config::GROUPS_PATH + "/#{group_id}/add_user", {:user_id => @options[:add_user]})
30
+ say("User added to group") if status.successful?
31
+ end
32
+
33
+ if @options[:remove_user].present?
34
+ status, response, headers = client.put(EPC::Config::GROUPS_PATH + "/#{group_id}/remove_user", {:user_id => @options[:remove_user]})
35
+ say("User removed from group") if status.successful?
36
+ end
37
+
38
+ say("Request failed: [#{response[:message]}]") if status.failure?
39
+ return status
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ module EPC::Command
2
+ class UpdateLibrarylanguageCommand < BaseCommand
3
+
4
+ def execute(language, new_name)
5
+ if numeric?(language)
6
+ language_id = language.to_i
7
+ else
8
+ language_id = get_resource_id(EPC::Config::LIBRARY_LANGUAGES_PATH, :name, language)
9
+ end
10
+
11
+ if language_id.nil?
12
+ say("Language could not be determined")
13
+ return 1
14
+ end
15
+
16
+ status, response, headers = client.put(EPC::Config::LIBRARY_LANGUAGES_PATH + "/#{language_id}", :name => new_name )
17
+
18
+ if status.successful?
19
+ say("Language updated")
20
+ else
21
+ say("Request failed: [#{response[:message]}]")
22
+ end
23
+
24
+ return status
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,80 @@
1
+ module EPC::Command
2
+ class UpdateLibrarysetCommand < BaseCommand
3
+
4
+ def execute(set = nil)
5
+ if set.nil?
6
+ say("You must specify the library-set")
7
+ say(EPC::Help::COMMAND_USAGES[:update_libraryset])
8
+ return 1
9
+ end
10
+
11
+ if numeric?(set)
12
+ set_id = set.to_i
13
+ else
14
+ set_id = get_resource_id(EPC::Config::LIBRARY_SETS_PATH, :name, set, :case_sensitivity => false)
15
+ end
16
+
17
+ if set_id.nil?
18
+ say("Set could not be determined")
19
+ return 1
20
+ end
21
+
22
+ if @options[:add_library].present?
23
+ lib = @options[:add_library]
24
+ lib_id = extract_library_id(lib)
25
+
26
+ status, response, headers = client.post(EPC::Config::LIBRARY_SETS_PATH + "/#{set_id}/attach_library/#{lib_id}")
27
+ if status.successful?
28
+ say("Library [#{lib}] added to set")
29
+ else
30
+ say("Request failed: [#{response[:message]}]")
31
+ end
32
+ return status
33
+ end
34
+
35
+ if @options[:remove_library].present?
36
+ lib = @options[:remove_library]
37
+ lib_id = extract_library_id(lib)
38
+
39
+ status, response, headers = client.post(EPC::Config::LIBRARY_SETS_PATH + "/#{set_id}/detach_library/#{lib_id}")
40
+ if status.successful?
41
+ say("Library [#{lib}] removed from set")
42
+ else
43
+ say("Request failed: [#{response[:message]}]")
44
+ end
45
+ return status
46
+ end
47
+
48
+ if @options[:file].present?
49
+ libraries = EPC::Config.read_content_as_json(@options[:file])
50
+ libraries = libraries.map{|h| {:name => h["name"], :version => h["library_version"], :group => h["group"]}}
51
+ lib_ids = retrieve_libraries(libraries)
52
+
53
+ failures = []
54
+ lib_ids.each do |lib_id|
55
+ status, response, headers = client.post(EPC::Config::LIBRARY_SETS_PATH + "/#{set_id}/attach_library/#{lib_id}")
56
+ if status.successful?
57
+ say("Library [#{lib_id}] added to set")
58
+ failures << false
59
+ else
60
+ say("Failed to add [#{lib_id}]: [#{response[:message]}]")
61
+ failures << true
62
+ end
63
+ end
64
+ return failures.all? ? 1 : 0
65
+ end
66
+
67
+ end
68
+
69
+ private
70
+
71
+ def extract_library_id(lib)
72
+ return lib.to_i if numeric?(lib)
73
+
74
+ lib_attrs = lib.split(":").delete_if{|a| a.blank?}
75
+ raise FatalError, "Library incorrectly specified - one of name/version/group attributes are missing" if lib_attrs.size < 3
76
+ retrieve_libraries([{:name => lib_attrs[0], :library_version => lib_attrs[1], :group => lib_attrs[2]}]).first rescue nil
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,49 @@
1
+ module EPC::Command
2
+ class UpdateProjectCommand < BaseCommand
3
+ UPDATABLE_ATTRIBUTES = ["project_name", "project_type"]
4
+
5
+ def execute(*args)
6
+ path = "."
7
+ path = File.expand_path(path)
8
+
9
+ solution_name = @options[:solution_name]
10
+ project_name = @options[:project_name]
11
+
12
+ solution_id, solution_name = infer_solution_context(solution_name, path, :get_solution_name => true)
13
+ project_id, project_name = infer_project_context(project_name, path, solution_id, {:get_project_name => true})
14
+
15
+
16
+ raise FatalError, "Project could not be inferred" if project_id.nil? || project_id == 0
17
+
18
+ args_hash = {}
19
+ args.each do |arg|
20
+ key, val = arg.split("=")
21
+ args_hash[key] = val
22
+ end
23
+
24
+ unless @options[:file].nil?
25
+ args_hash = EPC::Config.read_content_as_json(@options[:file]).merge(args_hash)
26
+ end
27
+
28
+ args_hash.each do |attr, val|
29
+ if !UPDATABLE_ATTRIBUTES.include?(attr)
30
+ args_hash.delete(attr)
31
+ say("Cannot update #{attr}. Updatable attributes are: [#{UPDATABLE_ATTRIBUTES.join(', ')}]")
32
+ next
33
+ end
34
+ end
35
+ unless args_hash.empty?
36
+ status, response, message = client.put(EPC::Config::PROJECTS_PATH + "/#{project_id}", args_hash)
37
+ if status.failure?
38
+ say("Update failed with: [#{response[:message]}]")
39
+ else
40
+ say("Update succesful")
41
+ end
42
+ return status
43
+ else
44
+ say(EPC::Help::COMMAND_USAGES[:update_project])
45
+ return 1
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,47 @@
1
+ module EPC::Command
2
+ class UpdateRoleCommand < BaseCommand
3
+
4
+ required_arguments_count 1, :message => "You must specify the role id/name"
5
+ required_options :add_user, :remove_user, :add_group, :remove_group, :mode => :any?, :message => "You must specify a user to added or removed"
6
+
7
+ def execute(role = nil)
8
+ role_id = retrieve_system_role_identifier(role)
9
+
10
+
11
+ if @options[:add_user].present?
12
+ user_id = retrieve_user_identifier(@options[:add_user])
13
+ params = []
14
+ params << {:member_id => user_id.to_i, :member_type => "User"}
15
+
16
+ status, response, headers = client.put(EPC::Config::ROLES_PATH + "/#{role_id}/assign_members", {:role_memberships => params})
17
+ say("User added to role") if status.successful?
18
+ end
19
+
20
+
21
+ if @options[:remove_user].present?
22
+ user_id = retrieve_user_identifier(@options[:remove_user])
23
+ status, response, headers = client.delete(EPC::Config::ROLES_PATH + "/#{role_id}/remove_member", {:member_id => @options[:remove_user], :member_type => "User"})
24
+ say("User removed from role") if status.successful?
25
+ end
26
+
27
+ if @options[:add_group].present?
28
+ group_id = retrieve_user_group_identifier(@options[:add_group])
29
+ params = []
30
+ params << {:member_id => group_id.to_i, :member_type => "UserGroup"}
31
+
32
+ status, response, headers = client.put(EPC::Config::ROLES_PATH + "/#{role_id}/assign_members", {:role_memberships => params})
33
+ say("UserGroup added to role") if status.successful?
34
+ end
35
+
36
+
37
+ if @options[:remove_group].present?
38
+ group_id = retrieve_user_group_identifier(@options[:remove_group])
39
+ status, response, headers = client.delete(EPC::Config::ROLES_PATH + "/#{role_id}/remove_member", {:member_id => group_id, :member_type => "UserGroup"})
40
+ say("UserGroup removed from role") if status.successful?
41
+ end
42
+
43
+ say("Request failed: [#{response[:message]}]") unless status.successful?
44
+ return status
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,83 @@
1
+ module EPC::Command
2
+ class UpdateRolepermissionsCommand < BaseCommand
3
+ def execute(role = nil)
4
+ raise FatalError, "You have to specify a role" if role.blank?
5
+
6
+
7
+ if @options[:add_grant].present?
8
+ secured_type, action, secured_id = @options[:add_grant].split(":")
9
+ raise FatalError, "Grant incorrectly specified" if secured_type.blank? || action.blank?
10
+
11
+ params = {}
12
+ params[:grant_action] = action
13
+ params[:permitted_type] = "Role"
14
+ params[:permitted_id] = role.to_i
15
+ params[:secured_type] = secured_type
16
+ params[:secured_id] = secured_id if secured_id.present?
17
+
18
+
19
+ status, response, headers = client.post(EPC::Config::GRANTS_PATH, params)
20
+
21
+ if status.successful?
22
+ say("Role permission updated")
23
+ else
24
+ say("Request failed: [#{response[:message]}]")
25
+ end
26
+
27
+ return status
28
+ end
29
+
30
+ if @options[:remove_grant].present?
31
+ secured_type, action, secured_id = @options[:remove_grant].split(":")
32
+ status, response, headers = client.get(EPC::Config::ROLES_PATH + "/#{role}/grants")
33
+
34
+ if status.successful?
35
+ grant_id = response.detect do |g|
36
+ found = (g[:action] == action)
37
+ found = found && (g[:secured_type].to_s == secured_type)
38
+ if secured_id.blank?
39
+ found = found && g[:secured_id].blank?
40
+ else
41
+ found = found && (g[:secured_id].to_s == secured_id)
42
+ end
43
+ found
44
+ end[:id] rescue nil
45
+
46
+ raise FatalError, "Permission couldn't be determined" if grant_id.blank?
47
+
48
+ status, response, headers = client.delete(EPC::Config::GRANTS_PATH + "/#{grant_id}")
49
+
50
+ if status.successful?
51
+ say("Role permission deleted")
52
+ return 1
53
+ else
54
+ say("Request failed: [#{response[:message]}]")
55
+ return 0
56
+ end
57
+ else
58
+ say("Request failed: [#{response[:message]}]")
59
+ end
60
+
61
+ return status
62
+ end
63
+
64
+ if @options[:file].present?
65
+ grants = EPC::Config.read_content_as_json(@options[:file])
66
+ grants.each do |grant|
67
+ raise FatalError, "Incorrectly specified grant.Grants should have at least secured_type and grant_action specified" if grant["secured_type"].blank? || grant["grant_action"].blank?
68
+ grant["permitted_type"] = "Role"
69
+ grant["permitted_id"] = role.to_i
70
+ status, response, headers = client.post(EPC::Config::GRANTS_PATH, grant)
71
+ if status.successful?
72
+ say("Added grant [#{grant["secured_type"]}:#{grant["grant_action"]}:#{grant["secured_id"]}]")
73
+ else
74
+ say("Request failed: [#{response[:message]}]")
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+ end