brpm_content 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +38 -0
  3. data/.travis.yml +14 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +21 -0
  6. data/README.md +308 -0
  7. data/Rakefile +24 -0
  8. data/TO_BE_MIGRATED.txt +8 -0
  9. data/architecture.png +0 -0
  10. data/brpm_content.gemspec +31 -0
  11. data/customers/demo/integrations/brpm/process_event_handler_event.rb +183 -0
  12. data/customers/demo/integrations/jenkins/spec/api/applications_spec.rb +89 -0
  13. data/customers/demo/integrations/jenkins/spec/api/plans_spec.rb +69 -0
  14. data/customers/demo/integrations/jenkins/spec/api/requests_spec.rb +57 -0
  15. data/customers/demo/integrations/jenkins/spec/spec_helper.rb +33 -0
  16. data/customers/demo/integrations/jira/process_webhook_event.rb +33 -0
  17. data/customers/demo/jira_mappings.rb +29 -0
  18. data/infrastructure/integrations/event_handler.rb +62 -0
  19. data/infrastructure/integrations/webhook_receiver.rb +49 -0
  20. data/infrastructure/shell_scripts/backup_database.sh +19 -0
  21. data/infrastructure/shell_scripts/create_bl_package.sh +34 -0
  22. data/infrastructure/shell_scripts/create_release_request.sh +34 -0
  23. data/infrastructure/shell_scripts/ddns.sh +10 -0
  24. data/infrastructure/shell_scripts/install_brpm.sh +63 -0
  25. data/infrastructure/shell_scripts/install_content_module.sh +66 -0
  26. data/infrastructure/shell_scripts/install_content_repo.sh +60 -0
  27. data/infrastructure/shell_scripts/install_module_from_gem.sh +80 -0
  28. data/infrastructure/shell_scripts/maintenance.sh +4 -0
  29. data/infrastructure/shell_scripts/patch_brpm.sh +90 -0
  30. data/infrastructure/shell_scripts/restore_database.sh +33 -0
  31. data/infrastructure/shell_scripts/run_event_handler.cmd +16 -0
  32. data/infrastructure/shell_scripts/run_event_handler.sh +20 -0
  33. data/infrastructure/shell_scripts/run_webhook_receiver.cmd +14 -0
  34. data/infrastructure/shell_scripts/run_webhook_receiver.sh +15 -0
  35. data/infrastructure/shell_scripts/update_content_repo.sh +21 -0
  36. data/infrastructure/silent_install_options_4.6.txt +93 -0
  37. data/infrastructure/silent_install_options_upgrade_4.6.txt +92 -0
  38. data/infrastructure/smtp_settings.rb +42 -0
  39. data/infrastructure/ssh_script_header_additions.rb +21 -0
  40. data/modules/ansible/automations/execute_role.rb +3 -0
  41. data/modules/ansible/automations/execute_role.txt +12 -0
  42. data/modules/ansible/config.yml +5 -0
  43. data/modules/ansible/lib/ansible.rb +41 -0
  44. data/modules/atrium_orchestrator/automations/execute_workflow.rb +12 -0
  45. data/modules/atrium_orchestrator/automations/execute_workflow.txt +25 -0
  46. data/modules/atrium_orchestrator/automations/reserve_ip_address.rb +22 -0
  47. data/modules/atrium_orchestrator/automations/reserve_ip_address.txt +21 -0
  48. data/modules/atrium_orchestrator/config.yml +7 -0
  49. data/modules/atrium_orchestrator/lib/ao_soap_client.rb +94 -0
  50. data/modules/bladelogic/automations/create_package.rb +29 -0
  51. data/modules/bladelogic/automations/create_package.txt +26 -0
  52. data/modules/bladelogic/automations/deploy_package.rb +137 -0
  53. data/modules/bladelogic/automations/deploy_package.txt +53 -0
  54. data/modules/bladelogic/config.yml +7 -0
  55. data/modules/bladelogic/lib/bl_rest/bsa_rest_client.rb +65 -0
  56. data/modules/bladelogic/lib/bl_soap/blpackage.rb +43 -0
  57. data/modules/bladelogic/lib/bl_soap/bsa_soap_base.rb +118 -0
  58. data/modules/bladelogic/lib/bl_soap/bsa_soap_client.rb +34 -0
  59. data/modules/bladelogic/lib/bl_soap/compliance_job.rb +155 -0
  60. data/modules/bladelogic/lib/bl_soap/deploy_job.rb +48 -0
  61. data/modules/bladelogic/lib/bl_soap/depot_group.rb +47 -0
  62. data/modules/bladelogic/lib/bl_soap/job.rb +376 -0
  63. data/modules/bladelogic/lib/bl_soap/job_group.rb +72 -0
  64. data/modules/bladelogic/lib/bl_soap/job_management.rb +22 -0
  65. data/modules/bladelogic/lib/bl_soap/job_result.rb +12 -0
  66. data/modules/bladelogic/lib/bl_soap/job_run.rb +271 -0
  67. data/modules/bladelogic/lib/bl_soap/login.rb +47 -0
  68. data/modules/bladelogic/lib/bl_soap/nsh_script_job.rb +14 -0
  69. data/modules/bladelogic/lib/bl_soap/patch_catalog.rb +178 -0
  70. data/modules/bladelogic/lib/bl_soap/patch_remediation_job.rb +137 -0
  71. data/modules/bladelogic/lib/bl_soap/patching_job.rb +250 -0
  72. data/modules/bladelogic/lib/bl_soap/server.rb +12 -0
  73. data/modules/bladelogic/lib/bl_soap/template.rb +13 -0
  74. data/modules/bladelogic/lib/bl_soap/utility.rb +99 -0
  75. data/modules/bladelogic/resource_automations/select_job.rb +33 -0
  76. data/modules/bladelogic/resource_automations/select_job.txt +15 -0
  77. data/modules/bladelogic/tests/create_package_spec.rb +28 -0
  78. data/modules/bladelogic/tests/deploy_package_spec.rb +23 -0
  79. data/modules/bladelogic/tests/spec_helper.rb +82 -0
  80. data/modules/brpm/automations/create_release_from_excel.rb +34 -0
  81. data/modules/brpm/automations/create_release_from_excel.txt +5 -0
  82. data/modules/brpm/automations/create_release_request.rb +100 -0
  83. data/modules/brpm/automations/create_release_request.txt +5 -0
  84. data/modules/brpm/automations/create_request.rb +73 -0
  85. data/modules/brpm/automations/create_request.txt +23 -0
  86. data/modules/brpm/automations/promote_request.rb +197 -0
  87. data/modules/brpm/automations/promote_request.txt +24 -0
  88. data/modules/brpm/automations/select_application_version.rb +22 -0
  89. data/modules/brpm/automations/select_application_version.txt +17 -0
  90. data/modules/brpm/automations/select_component_version.rb +12 -0
  91. data/modules/brpm/automations/select_component_version.txt +5 -0
  92. data/modules/brpm/automations/select_request_template.rb +6 -0
  93. data/modules/brpm/automations/select_request_template.txt +13 -0
  94. data/modules/brpm/automations/wait_for_step_in_other_request.rb +11 -0
  95. data/modules/brpm/automations/wait_for_step_in_other_request.txt +13 -0
  96. data/modules/brpm/automations/wait_till_promoted_request_is_completed.rb +9 -0
  97. data/modules/brpm/automations/wait_till_promoted_request_is_completed.txt +5 -0
  98. data/modules/brpm/config.yml +6 -0
  99. data/modules/brpm/lib/brpm_request.rb +207 -0
  100. data/modules/brpm/lib/brpm_rest.rb +312 -0
  101. data/modules/brpm/lib/brpm_rest_client.rb +1501 -0
  102. data/modules/brpm/resource_automations/select_application.rb +16 -0
  103. data/modules/brpm/resource_automations/select_application.txt +5 -0
  104. data/modules/brpm/resource_automations/select_environment.rb +14 -0
  105. data/modules/brpm/resource_automations/select_environment.txt +5 -0
  106. data/modules/brpm/resource_automations/select_request_template.rb +16 -0
  107. data/modules/brpm/resource_automations/select_request_template.txt +5 -0
  108. data/modules/brpm/resource_automations/select_step_in_request.rb +33 -0
  109. data/modules/brpm/resource_automations/select_step_in_request.txt +5 -0
  110. data/modules/brpm/sample_applications/e-finance.json +0 -0
  111. data/modules/brpm/tests/create_release_request_spec.rb +66 -0
  112. data/modules/brpm/tests/create_request_spec.rb +84 -0
  113. data/modules/brpm/tests/select_application_version_spec.rb +47 -0
  114. data/modules/brpm/tests/spec_helper.rb +63 -0
  115. data/modules/docker_brpm/automations/create_brpm_instance_input_params.rb +10 -0
  116. data/modules/docker_brpm/automations/create_brpm_instance_input_params.txt +17 -0
  117. data/modules/docker_brpm/automations/create_brpm_instance_one_shot.rb +60 -0
  118. data/modules/docker_brpm/automations/create_brpm_instance_one_shot.txt +14 -0
  119. data/modules/docker_brpm/automations/create_brpm_instance_show_results.rb +23 -0
  120. data/modules/docker_brpm/automations/create_brpm_instance_show_results.txt +13 -0
  121. data/modules/docker_brpm/automations/create_database.rb +24 -0
  122. data/modules/docker_brpm/automations/create_database.txt +3 -0
  123. data/modules/docker_brpm/automations/create_environment.rb +14 -0
  124. data/modules/docker_brpm/automations/create_environment.txt +3 -0
  125. data/modules/docker_brpm/automations/create_image_for_application.rb +23 -0
  126. data/modules/docker_brpm/automations/create_image_for_application.txt +6 -0
  127. data/modules/docker_brpm/automations/create_image_for_brpm_application_input_params.rb +7 -0
  128. data/modules/docker_brpm/automations/create_image_for_brpm_application_input_params.txt +8 -0
  129. data/modules/docker_brpm/automations/create_image_for_brpm_database_creator_input_params.rb +7 -0
  130. data/modules/docker_brpm/automations/create_image_for_brpm_database_creator_input_params.txt +8 -0
  131. data/modules/docker_brpm/automations/create_image_for_database_creator.rb +21 -0
  132. data/modules/docker_brpm/automations/create_image_for_database_creator.txt +6 -0
  133. data/modules/docker_brpm/automations/create_installed_component_for_application.rb +11 -0
  134. data/modules/docker_brpm/automations/create_installed_component_for_application.txt +3 -0
  135. data/modules/docker_brpm/automations/create_installed_component_for_database.rb +7 -0
  136. data/modules/docker_brpm/automations/create_installed_component_for_database.txt +3 -0
  137. data/modules/docker_brpm/automations/create_installed_component_for_database_creator.rb +8 -0
  138. data/modules/docker_brpm/automations/create_installed_component_for_database_creator.txt +3 -0
  139. data/modules/docker_brpm/automations/create_installed_component_for_utilities.rb +7 -0
  140. data/modules/docker_brpm/automations/create_installed_component_for_utilities.txt +3 -0
  141. data/modules/docker_brpm/automations/create_version_tags_for_component_in_all_envs.rb +13 -0
  142. data/modules/docker_brpm/automations/create_version_tags_for_component_in_all_envs.txt +6 -0
  143. data/modules/docker_brpm/automations/delete_brpm_instance.rb +38 -0
  144. data/modules/docker_brpm/automations/delete_brpm_instance.txt +8 -0
  145. data/modules/docker_brpm/automations/execute_test_run_in_jenkins.rb +43 -0
  146. data/modules/docker_brpm/automations/execute_test_run_in_jenkins.txt +13 -0
  147. data/modules/docker_brpm/automations/execute_test_run_in_jenkins_show_results.rb +5 -0
  148. data/modules/docker_brpm/automations/execute_test_run_in_jenkins_show_results.txt +9 -0
  149. data/modules/docker_brpm/automations/launch_create_image_for_brpm_application_request.rb +27 -0
  150. data/modules/docker_brpm/automations/launch_create_image_for_brpm_application_request.txt +3 -0
  151. data/modules/docker_brpm/automations/launch_test_run_request.rb +30 -0
  152. data/modules/docker_brpm/automations/launch_test_run_request.txt +14 -0
  153. data/modules/docker_brpm/automations/release_brpm_input_params.rb +7 -0
  154. data/modules/docker_brpm/automations/release_brpm_input_params.txt +8 -0
  155. data/modules/docker_brpm/automations/run_application_container.rb +27 -0
  156. data/modules/docker_brpm/automations/run_application_container.txt +3 -0
  157. data/modules/docker_brpm/automations/run_database_container.rb +14 -0
  158. data/modules/docker_brpm/automations/run_database_container.txt +3 -0
  159. data/modules/docker_brpm/automations/stop_application_container.rb +11 -0
  160. data/modules/docker_brpm/automations/stop_application_container.txt +3 -0
  161. data/modules/docker_brpm/automations/stop_database_container.rb +11 -0
  162. data/modules/docker_brpm/automations/stop_database_container.txt +3 -0
  163. data/modules/docker_brpm/automations/test_rest_api.rb +18 -0
  164. data/modules/docker_brpm/automations/test_rest_api.txt +3 -0
  165. data/modules/docker_brpm/automations/upgrade_database.rb +19 -0
  166. data/modules/docker_brpm/automations/upgrade_database.txt +8 -0
  167. data/modules/docker_brpm/config.yml +8 -0
  168. data/modules/docker_brpm/lib/docker.rb +39 -0
  169. data/modules/docker_brpm/lib/git.rb +16 -0
  170. data/modules/docker_brpm/sample_applications/dockerizedbrpm.json +0 -0
  171. data/modules/email/automations/send_notification.rb +48 -0
  172. data/modules/email/automations/send_notification.txt +27 -0
  173. data/modules/email/config.yml +6 -0
  174. data/modules/framework/automations/direct_execute.rb +10 -0
  175. data/modules/framework/automations/direct_execute.txt +16 -0
  176. data/modules/framework/automations/install_module.rb +13 -0
  177. data/modules/framework/automations/install_module.txt +16 -0
  178. data/modules/framework/bin/brpm_install +106 -0
  179. data/modules/framework/bin/event_handler +63 -0
  180. data/modules/framework/bin/webhook_receiver +49 -0
  181. data/modules/framework/brpm_auto.rb +307 -0
  182. data/modules/framework/brpm_framework.rb +88 -0
  183. data/modules/framework/brpm_script_executor.rb +146 -0
  184. data/modules/framework/config.yml +7 -0
  185. data/modules/framework/config/customer_include.rb +26 -0
  186. data/modules/framework/config/server.yml +3 -0
  187. data/modules/framework/customer_include_default.rb +25 -0
  188. data/modules/framework/lib/logging/brpm_logger.rb +39 -0
  189. data/modules/framework/lib/logging/logger_base.rb +36 -0
  190. data/modules/framework/lib/logging/simple_logger.rb +27 -0
  191. data/modules/framework/lib/params/all_params.rb +80 -0
  192. data/modules/framework/lib/params/integration_settings.rb +27 -0
  193. data/modules/framework/lib/params/params.rb +172 -0
  194. data/modules/framework/lib/params/params_base.rb +81 -0
  195. data/modules/framework/lib/params/request_params.rb +38 -0
  196. data/modules/framework/lib/resource_framework.rb +211 -0
  197. data/modules/framework/lib/rest_api.rb +155 -0
  198. data/modules/framework/lib/semaphore.rb +79 -0
  199. data/modules/framework/lib/utilities.rb +317 -0
  200. data/modules/framework/lib/version_control/git.rb +192 -0
  201. data/modules/framework/lib/version_control/svn.rb +221 -0
  202. data/modules/framework/log.html +39 -0
  203. data/modules/framework/tests/all_params_spec.rb +116 -0
  204. data/modules/framework/tests/brpm_auto_spec.rb +84 -0
  205. data/modules/framework/tests/customer_include/config/customer_include.rb +10 -0
  206. data/modules/framework/tests/customer_include/config/server.yml +3 -0
  207. data/modules/framework/tests/customer_include_spec.rb +29 -0
  208. data/modules/framework/tests/local_jirb.rb +15 -0
  209. data/modules/framework/tests/params_spec.rb +172 -0
  210. data/modules/framework/tests/request_params_spec.rb +86 -0
  211. data/modules/framework/tests/server_yaml_spec.rb +19 -0
  212. data/modules/framework/tests/spec_helper.rb +42 -0
  213. data/modules/framework/transport/dispatch_baa.rb +355 -0
  214. data/modules/framework/transport/dispatch_base.rb +345 -0
  215. data/modules/framework/transport/dispatch_nsh.rb +248 -0
  216. data/modules/framework/transport/dispatch_ssh.rb +154 -0
  217. data/modules/framework/transport/transport_baa.rb +1095 -0
  218. data/modules/framework/transport/transport_nsh.rb +359 -0
  219. data/modules/framework/transport/transport_ssh.rb +220 -0
  220. data/modules/framework/write_to.rb +1 -0
  221. data/modules/jenkins/automations/create_release.rb +4 -0
  222. data/modules/jenkins/automations/create_release.txt +23 -0
  223. data/modules/jenkins/automations/f2_downloadJenkinsArtifact.rb +126 -0
  224. data/modules/jenkins/config.yml +7 -0
  225. data/modules/jenkins/lib/jenkins.rb +300 -0
  226. data/modules/jenkins/resource_automations/f2_rsc_jenkinsJobs.rb +58 -0
  227. data/modules/jira/automations/add_comment.rb +4 -0
  228. data/modules/jira/automations/add_comment.txt +23 -0
  229. data/modules/jira/automations/create_release.rb +4 -0
  230. data/modules/jira/automations/create_release.txt +23 -0
  231. data/modules/jira/automations/delete_release.rb +4 -0
  232. data/modules/jira/automations/delete_release.txt +23 -0
  233. data/modules/jira/automations/transition_issue.rb +4 -0
  234. data/modules/jira/automations/transition_issue.txt +23 -0
  235. data/modules/jira/automations/transition_issues_for_request.rb +29 -0
  236. data/modules/jira/automations/transition_issues_for_request.txt +20 -0
  237. data/modules/jira/automations/transition_issues_for_run.rb +26 -0
  238. data/modules/jira/automations/transition_issues_for_run.txt +20 -0
  239. data/modules/jira/automations/update_release.rb +4 -0
  240. data/modules/jira/automations/update_release.txt +26 -0
  241. data/modules/jira/config.yml +7 -0
  242. data/modules/jira/lib/jira_rest_client.rb +185 -0
  243. data/modules/jira/tests/create_read_update_delete_release_spec.rb +39 -0
  244. data/modules/jira/tests/spec_helper.rb +39 -0
  245. data/modules/jira/tests/transition_issue_spec.rb +32 -0
  246. data/modules/patch_process_management/automations/execute_job/script.rb +105 -0
  247. data/modules/patch_process_management/automations/execute_job/wrapper.txt +39 -0
  248. data/modules/patch_process_management/automations/patch_analysis/script.rb +107 -0
  249. data/modules/patch_process_management/automations/patch_analysis/wrapper.txt +33 -0
  250. data/modules/patch_process_management/automations/patch_readiness/script.rb +89 -0
  251. data/modules/patch_process_management/automations/patch_readiness/wrapper.txt +33 -0
  252. data/modules/patch_process_management/automations/patch_remediation/script.rb +217 -0
  253. data/modules/patch_process_management/automations/patch_remediation/wrapper.txt +40 -0
  254. data/modules/patch_process_management/config.yml +10 -0
  255. data/modules/teamcity/automations/trigger_build.rb +4 -0
  256. data/modules/teamcity/automations/trigger_build.txt +14 -0
  257. data/modules/teamcity/config.yml +7 -0
  258. data/modules/teamcity/lib/teamcity_rest_client.rb +17 -0
  259. data/modules/teamcity/tests/spec_helper.rb +34 -0
  260. data/modules/teamcity/tests/trigger_build_spec.rb +27 -0
  261. data/modules/windows/automations/deploy_directory_over_windows_shares/script.rb +87 -0
  262. data/modules/windows/automations/deploy_directory_over_windows_shares/wrapper.txt +29 -0
  263. data/modules/windows/automations/deploy_file_over_windows_shares/script.rb +31 -0
  264. data/modules/windows/automations/deploy_file_over_windows_shares/wrapper.txt +24 -0
  265. data/modules/windows/config.yml +6 -0
  266. data/modules/windows/lib/samba.rb +29 -0
  267. metadata +397 -0
@@ -0,0 +1,81 @@
1
+ class ParamsBase < Hash
2
+ def [] key
3
+ BrpmAuto.substitute_tokens(super(key))
4
+ end
5
+
6
+ # Gets a params
7
+ #
8
+ # ==== Attributes
9
+ #
10
+ # * +key+ - key to find
11
+ def get(key, default_value = "")
12
+ self[key] || default_value
13
+ end
14
+
15
+ # Adds a key/value to the params
16
+ #
17
+ # ==== Attributes
18
+ #
19
+ # * +key_name+ - key name
20
+ # * +value+ - value to assign
21
+ #
22
+ # ==== Returns
23
+ #
24
+ # * value added
25
+ def add(key, value)
26
+ self[key] = value
27
+ end
28
+
29
+ # Adds a key/value to the params if not found
30
+ #
31
+ # ==== Attributes
32
+ #
33
+ # * +key_name+ - key name
34
+ # * +value+ - value to assign
35
+ #
36
+ # ==== Returns
37
+ #
38
+ # * value of key
39
+ def find_or_add(key, value)
40
+ ans = get(key)
41
+ add(key, value) if ans == ""
42
+ ans == "" ? value : ans
43
+ end
44
+
45
+ # Allows you to specify a key like a method call
46
+ #
47
+ # ==== Attributes
48
+ #
49
+ # * +key_name+ - key name note: you must use get if keyname has spaces
50
+ # * +*args+ - allows you to send a default value
51
+ #
52
+ # ==== Returns
53
+ #
54
+ # * value of key - including resolved properties that may be embedded
55
+ #
56
+ # ==== Examples
57
+ #
58
+ # @p = Params.new(params)
59
+ # @p.SS_application
60
+ # => "Sales"
61
+ def method_missing(key, *args)
62
+ ans = get(key.to_s)
63
+ ans = args[0] if ans == "" && args[0]
64
+ ans
65
+ end
66
+
67
+ # Raises an error if a key is not found
68
+ #
69
+ # ==== Attributes
70
+ #
71
+ # * +key_name+ - key name
72
+ #
73
+ # ==== Returns
74
+ #
75
+ # * value of key
76
+ def required(key)
77
+ raise "ParamsError: param #{key} must be present" unless self.has_key?(key)
78
+ get(key)
79
+ end
80
+
81
+ end
@@ -0,0 +1,38 @@
1
+ class RequestParams < ParamsBase
2
+ attr_reader :file_path
3
+
4
+ def initialize(path)
5
+ @file_path = "#{path}/request_data.json"
6
+
7
+ self.merge!(get_request_params)
8
+ end
9
+
10
+ def self.new_for_request(automation_results_dir, app_name, request_id)
11
+ self.new("#{automation_results_dir}/request/#{app_name}/#{request_id}")
12
+ end
13
+
14
+ def []=(key,val)
15
+ super(key, val)
16
+
17
+ set_request_params
18
+ end
19
+
20
+ #TODO: support parallel steps modifying the same request params file
21
+
22
+ private
23
+
24
+ def set_request_params
25
+ File.open(@file_path, "w") do |file|
26
+ file.puts(self.to_json)
27
+ end
28
+ end
29
+
30
+ def get_request_params
31
+ if File.exist?(@file_path)
32
+ json = File.read(@file_path)
33
+ JSON.parse(json)
34
+ else
35
+ {}
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,211 @@
1
+
2
+ module ResourceFramework
3
+ #DEPRECATED: this functionality already exists, see modules/framework/lib/request_params.rb
4
+ def create_request_params_file
5
+ request_data_file_dir = File.dirname(@params["SS_output_dir"])
6
+ request_data_file = "#{request_data_file_dir}/request_data.json"
7
+ fil = File.open(request_data_file,"w")
8
+ fil.puts "{\"request_data_file\":\"Created #{Time.now.strftime("%m/%d/%Y %H:%M:%S")}\"}"
9
+ fil.close
10
+ file_part = request_data_file[request_data_file.index("/automation_results")..255]
11
+ data_file_url = "#{@params["SS_base_url"]}#{file_part}"
12
+ write_to "Request Run Data: #{data_file_url}"
13
+ request_data_file
14
+ end
15
+
16
+ #DEPRECATED: this functionality already exists, see modules/framework/lib/request_params.rb
17
+ def init_request_params
18
+ request_data_file_dir = File.dirname(@params["SS_output_dir"])
19
+ request_data_file = "#{request_data_file_dir}/request_data.json"
20
+ sleep(2) unless File.exist?(request_data_file)
21
+ unless File.exist?(request_data_file)
22
+ create_request_params_file
23
+ end
24
+ file_part = request_data_file[request_data_file.index("/automation_results")..255]
25
+ data_file_url = "#{@params["SS_base_url"]}#{file_part}"
26
+ write_to "Request Run Data: #{data_file_url}"
27
+ request_data_file
28
+ end
29
+
30
+ #DEPRECATED: this functionality already exists, see modules/framework/lib/request_params.rb
31
+ def get_request_params
32
+ # Uses a json document in automation_results to store free-form information
33
+ cur = init_request_params
34
+ #message_box("Current Request Data","sep")
35
+ @request_params = JSON.parse(File.open(cur).read)
36
+ @request_params.each{ |k,v| write_to("#{k} => #{v.is_a?(String) ? v : v.inspect}") }
37
+ @orig_request_params = @request_params.dup
38
+ @request_params
39
+ end
40
+
41
+ #DEPRECATED: this functionality already exists, see modules/framework/lib/request_params.rb
42
+ def save_request_params
43
+ # Uses a json document in automation_results to store free-form information
44
+ cur = init_request_params
45
+ unless @orig_request_params == @request_params
46
+ sleep(2) unless File.exist?(cur)
47
+ fil = File.open(cur,"w+")
48
+ fil.write @request_params.to_json
49
+ fil.flush
50
+ fil.close
51
+ end
52
+ end
53
+
54
+ #DEPRECATED: is this specific to a particular use case?
55
+ def default_table(other_rows = nil)
56
+ totalItems = 1
57
+ table_entries = [["#","Status","Information"]]
58
+ table_entries << ["1","Error", "Insufficient Data"] if other_rows.nil?
59
+ other_rows.each{|row| table_entries << row } unless other_rows.nil?
60
+ per_page=10
61
+ {:totalItems => totalItems, :perPage => per_page, :data => table_entries }
62
+ end
63
+
64
+ #DEPRECATED: what does this method do?
65
+ def default_list(msg)
66
+ result = [{msg => 0}]
67
+ select_hash = {}
68
+ result.unshift(select_hash)
69
+ end
70
+
71
+ #DEPRECATED: this functionality already exists, see modules/framework/lib/logger.rb
72
+ def log_it(it)
73
+ log_path = File.join(@params["SS_automation_results_dir"], "resource_logs")
74
+ txt = it.is_a?(String) ? it : it.inspect
75
+ write_to txt
76
+ Dir.mkdir(log_path) unless File.exist?(log_path)
77
+ s_handle = defined?(@script_name_handle) ? @script_name_handle : "rsc_output"
78
+ fil = File.open("#{log_path}/#{s_handle}_#{@params["SS_run_key"]}", "a")
79
+ fil.puts txt
80
+ fil.flush
81
+ fil.close
82
+ end
83
+
84
+ #DEPRECATED: OK - implemented it with a server.yml file instead (located in BRPM_HOME/config)
85
+ def load_customer_include(framework_dir)
86
+ customer_include_file = File.join(framework_dir, "customer_include.rb")
87
+ begin
88
+ if File.exist?(customer_include_file)
89
+ log_it "Loading customer include file: #{customer_include_file}"
90
+ eval(File.open(customer_include_file).read)
91
+ elsif File.exist customer_include_file = File.join(framework_dir,"customer_include_default.rb")
92
+ log_it "Loading default customer include file: #{customer_include_file}"
93
+ eval(File.open(customer_include_file).read)
94
+ end
95
+ rescue Exception => e
96
+ log_it "Error loading customer include: #{e.message}\n#{e.backtrace}"
97
+ end
98
+ end
99
+
100
+ #DEPRECATED: what does this method do?
101
+ def hashify_list(list)
102
+ response = {}
103
+ list.each do |item,val|
104
+ response[val] = item
105
+ end
106
+ return [response]
107
+ end
108
+
109
+ #DEPRECATED: already implemented differently
110
+ def action_library_path
111
+ raise "Command_Failed: no library path defined, set property: ACTION_LIBRARY_PATH" if !defined?(ACTION_LIBRARY_PATH)
112
+ ACTION_LIBRARY_PATH
113
+ end
114
+
115
+
116
+ #DEPRECATED: what's the difference with the method with the same name from brpm_automation?
117
+
118
+ # Makes an http method call and returns data in JSON
119
+ #
120
+ # ==== Attributes
121
+ #
122
+ # * +url+ - the url for the request
123
+ # * +method+ - the http method [get, put, post]
124
+ # * +options+ - a hash of options
125
+ # +verbose+: gives verbose output (yes/no)
126
+ # +data+: required for put and post methods a hash of post data
127
+ # +username+: username for basic http authentication
128
+ # +password+: password for basic http authentication
129
+ # +suppress_errors+: continues after errors if true
130
+ #
131
+ # ==== Returns
132
+ #
133
+ # * returns a hash of the http response with these keys
134
+ # * +status+ - success or ERROR
135
+ # * +message+ - if status is ERROR this will hold an error message
136
+ # * +code+ - the http status code 200=ok, 404=not found, 500=error, 504=not authorized
137
+ # * +data+ - the body of the http response
138
+ def rest_call(url, method, options = {})
139
+ methods = %w{get post put}
140
+ result = {"status" => "ERROR", "response" => "", "message" => ""}
141
+ method = method.downcase
142
+ verbose = get_option(options, "verbose") == "yes" || get_option(options, "verbose")
143
+ headers = get_option(options, "headers", {:accept => :json, :content_type => :json})
144
+ return result["message"] = "ERROR - #{method} not recognized" unless methods.include?(method)
145
+ log "Rest URL: #{url}" if verbose
146
+ begin
147
+ data = get_option(options, "data")
148
+ rest_params = {}
149
+ rest_params[:url] = url
150
+ rest_params[:method] = method.to_sym
151
+ rest_params[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE if url.start_with?("https")
152
+ rest_params[:payload] = data.to_json unless data == ""
153
+ if options.has_key?("username") && options.has_key?("password")
154
+ rest_params[:user] = options["username"]
155
+ rest_params[:password] = options["password"]
156
+ end
157
+ rest_params[:headers] = headers
158
+ log "RestParams: #{rest_params.inspect}" if verbose
159
+ if %{put post}.include?(method)
160
+ return result["message"] = "ERROR - no data param for post" if data == ""
161
+ response = RestClient::Request.new(rest_params).execute
162
+ else
163
+ response = RestClient::Request.new(rest_params).execute
164
+ end
165
+ rescue Exception => e
166
+ result["message"] = e.message
167
+ raise "RestError: #{result["message"]}" unless get_option(options, "suppress_errors") == true
168
+ return result
169
+ end
170
+ log "Rest Response:\n#{response.inspect}" if verbose
171
+ if headers[:accept] == :json
172
+ parsed_response = JSON.parse(response) rescue nil
173
+ else
174
+ parsed_response = response
175
+ end
176
+ parsed_response = {"info" => "no data returned"} if parsed_response.nil?
177
+ result["code"] = response.code
178
+ if response.code < 300
179
+ result["status"] = "success"
180
+ result["data"] = parsed_response
181
+ elsif response.code == 422
182
+ result["message"] = "REST call returned code 422 usually a bad token"
183
+ else
184
+ result["message"] = "REST call returned HTTP code #{response.code}"
185
+ end
186
+ if result["status"] == "ERROR"
187
+ raise "RestError: #{result["message"]}" unless get_option(options, "suppress_errors") == true
188
+ end
189
+ result
190
+ end
191
+
192
+
193
+ #DEPRECATED: what's the difference with the method with the same name from brpm_automation?
194
+
195
+ # Provides a simple failsafe for working with hash options
196
+ # returns "" if the option doesn't exist or is blank
197
+ # ==== Attributes
198
+ #
199
+ # * +options+ - the hash
200
+ # * +key+ - key to find in options
201
+ # * +default_value+ - if entered will be returned if the option doesn't exist or is blank
202
+ def get_option(options, key, default_value = "")
203
+ result = options.has_key?(key) ? options[key] : nil
204
+ result = default_value if result.nil? || result == ""
205
+ result
206
+ end
207
+
208
+ end
209
+
210
+ extend ResourceFramework
211
+
@@ -0,0 +1,155 @@
1
+ require 'rest-client'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'cgi'
5
+
6
+ class Rest
7
+ class << self
8
+ def get(url, options = {})
9
+ rest_call(url, "get", options)
10
+ end
11
+
12
+ def post(url, data, options = {})
13
+ options[:data] = data
14
+ rest_call(url, "post", options)
15
+ end
16
+
17
+ def put(url, data, options = {})
18
+ options[:data] = data
19
+ rest_call(url, "put", options)
20
+ end
21
+
22
+ def delete(url, options = {})
23
+ rest_call(url, "delete", options)
24
+ end
25
+
26
+ # Makes an http method call and returns data in JSON
27
+ #
28
+ # ==== Attributes
29
+ #
30
+ # * +url+ - the url for the request
31
+ # * +method+ - the http method [get, put, post]
32
+ # * +options+ - a hash of options
33
+ # +verbose+: gives verbose output (yes/no)
34
+ # +data+: required for put and post methods a hash of post data
35
+ # +username+: username for basic http authentication
36
+ # +password+: password for basic http authentication
37
+ # +suppress_errors+: continues after errors if true
38
+ #
39
+ # ==== Returns
40
+ #
41
+ # * returns a hash of the http response with these keys
42
+ # * +status+ - success or ERROR
43
+ # * +message+ - if status is ERROR this will hold an error message
44
+ # * +code+ - the http status code 200=ok, 404=not found, 500=error, 504=not authorized
45
+ # * +data+ - the body of the http response
46
+ def rest_call(url, method, options = {})
47
+ methods = %w{get post put delete}
48
+ result = rest_params = {}
49
+ rest_params[:url] = URI.escape(url)
50
+
51
+ unless methods.include?(method.downcase)
52
+ BrpmAuto.log "No method named: #{method}"
53
+ result["code"] = -1
54
+ result["status"] = "failure"
55
+ result["message"] = "No method named: #{method}"
56
+ return result
57
+ end
58
+
59
+ rest_params[:method] = method.downcase
60
+
61
+ begin
62
+ BrpmAuto.log("REST #{method.upcase} #{BrpmAuto.privatize(url, get_token(url))}") unless options.has_key?("quiet")
63
+
64
+ if options.has_key?(:username) && options.has_key?(:password)
65
+ rest_params[:user] = options[:username]
66
+ rest_params[:password] = options[:password]
67
+ end
68
+
69
+ if %{put post}.include?(method.downcase)
70
+ options[:data] = options["data"] if options.has_key?("data")
71
+ rest_params[:payload] = options[:data].to_json if options.has_key?(:data)
72
+ if !options.has_key?(:data) || rest_params[:payload].length < 4
73
+ result["code"] = -1
74
+ result["status"] = "failure"
75
+ result["message"] = "No Post data"
76
+ return result
77
+ end
78
+ BrpmAuto.log "\tPost Data: #{rest_params[:payload].inspect}" unless options.has_key?("quiet")
79
+ end
80
+
81
+ rest_params.merge!({:headers => { :accept => :json, :content_type => :json }})
82
+ rest_params.merge!({:verify_ssl => OpenSSL::SSL::VERIFY_NONE})
83
+ rest_params.merge!({:cookies => options["cookies"] }) if options.has_key?("cookies")
84
+
85
+ BrpmAuto.log rest_params.inspect if options.has_key?("verbose")
86
+
87
+ response = RestClient::Request.new(rest_params).execute
88
+
89
+ BrpmAuto.log "\tParsing response to JSON format ..." if options.has_key?("verbose")
90
+ begin
91
+ parsed_response = JSON.parse(response)
92
+ rescue
93
+ parsed_response = response
94
+ end
95
+ BrpmAuto.log "Parsed response: #{parsed_response.inspect}" if options.has_key?("verbose")
96
+
97
+ if response.code < 300
98
+ BrpmAuto.log "\treturn code: #{response.code}" unless options.has_key?("quiet")
99
+ result["status"] = "success"
100
+ result["code"] = response.code
101
+ result["response"] = parsed_response
102
+ result["cookies"] = response.cookies if options.has_key?("cookies")
103
+ else
104
+ result["status"] = "error"
105
+ result["code"] = response.code
106
+ result["response"] = parsed_response
107
+ result["error_message"] = "REST call returned HTTP code:\n#{response.code}\n#{response}"
108
+ BrpmAuto.log "\tREST call returned HTTP code #{response.code}" unless options.has_key?("quiet")
109
+ end
110
+
111
+ rescue RestClient::Exception => e
112
+ BrpmAuto.log "\tREST call generated an error: #{e.message}" unless options.has_key?("quiet")
113
+
114
+ if e.response.nil?
115
+ result["status"] = "error"
116
+ result["code"] = 1000
117
+ result["response"] = "No response received."
118
+ result["error_message"] = "REST call generated a RestClient error:\n#{e.message}\n#{e.backtrace}"
119
+ return
120
+ end
121
+
122
+ BrpmAuto.log "\tParsing response to JSON format ..." unless options.has_key?("quiet")
123
+ begin
124
+ parsed_response = JSON.parse(e.response)
125
+ rescue
126
+ parsed_response = e.response
127
+ end
128
+ BrpmAuto.log "\tParsed response: #{parsed_response.inspect}"
129
+
130
+ result["status"] = "error"
131
+ result["code"] = e.response.code
132
+ result["response"] = parsed_response
133
+ result["error_message"] = "REST call generated a RestClient error:\n#{e.response.code}\n#{e.response}\n#{e.message}\n#{e.backtrace}"
134
+
135
+ BrpmAuto.log "Back trace:\n#{e.backtrace}" unless already_exists_error(result) or not_found_error(result)
136
+ end
137
+ result
138
+ end
139
+
140
+ def already_exists_error(result)
141
+ result["code"] == 422 && result["response"].keys.count >= 1 && (result["response"][result["response"].keys[0]][0] == "has already been taken" || result["response"][result["response"].keys[0]][0] =~ /Version Tag is not unique/)
142
+ end
143
+
144
+ def not_found_error(result)
145
+ result["code"] == 404
146
+ end
147
+
148
+ private
149
+
150
+ def get_token(url)
151
+ params = CGI::parse(url.split("?").last)
152
+ params.has_key?("token") ? params["token"] : ""
153
+ end
154
+ end
155
+ end