hammer_cli_foreman 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (325) hide show
  1. checksums.yaml +4 -4
  2. data/doc/configuration.md +2 -2
  3. data/doc/name_id_resolution.md +26 -1
  4. data/doc/release_notes.md +24 -0
  5. data/lib/hammer_cli_foreman.rb +30 -29
  6. data/lib/hammer_cli_foreman/api/connection.rb +1 -1
  7. data/lib/hammer_cli_foreman/api/interactive_basic_auth.rb +3 -3
  8. data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +9 -8
  9. data/lib/hammer_cli_foreman/api/void_auth.rb +7 -0
  10. data/lib/hammer_cli_foreman/architecture.rb +3 -5
  11. data/lib/hammer_cli_foreman/associating_commands.rb +32 -32
  12. data/lib/hammer_cli_foreman/auth.rb +2 -2
  13. data/lib/hammer_cli_foreman/auth_source_ldap.rb +4 -4
  14. data/lib/hammer_cli_foreman/commands.rb +23 -55
  15. data/lib/hammer_cli_foreman/common_parameter.rb +5 -5
  16. data/lib/hammer_cli_foreman/compute_resource.rb +17 -7
  17. data/lib/hammer_cli_foreman/config_group.rb +3 -3
  18. data/lib/hammer_cli_foreman/domain.rb +6 -8
  19. data/lib/hammer_cli_foreman/environment.rb +3 -3
  20. data/lib/hammer_cli_foreman/exception_handler.rb +27 -4
  21. data/lib/hammer_cli_foreman/external_usergroup.rb +3 -4
  22. data/lib/hammer_cli_foreman/filter.rb +20 -21
  23. data/lib/hammer_cli_foreman/host.rb +43 -18
  24. data/lib/hammer_cli_foreman/hostgroup.rb +24 -19
  25. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +4 -6
  26. data/lib/hammer_cli_foreman/id_resolver.rb +86 -50
  27. data/lib/hammer_cli_foreman/image.rb +3 -4
  28. data/lib/hammer_cli_foreman/interface.rb +7 -9
  29. data/lib/hammer_cli_foreman/location.rb +6 -9
  30. data/lib/hammer_cli_foreman/media.rb +3 -6
  31. data/lib/hammer_cli_foreman/model.rb +3 -6
  32. data/lib/hammer_cli_foreman/operating_system.rb +11 -12
  33. data/lib/hammer_cli_foreman/option_sources.rb +4 -0
  34. data/lib/hammer_cli_foreman/option_sources/id_params.rb +51 -0
  35. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +30 -0
  36. data/lib/hammer_cli_foreman/option_sources/self_param.rb +16 -0
  37. data/lib/hammer_cli_foreman/option_sources/user_params.rb +59 -0
  38. data/lib/hammer_cli_foreman/organization.rb +6 -9
  39. data/lib/hammer_cli_foreman/output/formatters.rb +1 -1
  40. data/lib/hammer_cli_foreman/parameter.rb +3 -5
  41. data/lib/hammer_cli_foreman/partition_table.rb +5 -6
  42. data/lib/hammer_cli_foreman/realm.rb +3 -3
  43. data/lib/hammer_cli_foreman/report.rb +1 -4
  44. data/lib/hammer_cli_foreman/role.rb +4 -7
  45. data/lib/hammer_cli_foreman/settings.rb +1 -1
  46. data/lib/hammer_cli_foreman/smart_class_parameter.rb +24 -14
  47. data/lib/hammer_cli_foreman/smart_proxy.rb +5 -7
  48. data/lib/hammer_cli_foreman/smart_variable.rb +24 -12
  49. data/lib/hammer_cli_foreman/ssh_keys.rb +56 -0
  50. data/lib/hammer_cli_foreman/subnet.rb +6 -9
  51. data/lib/hammer_cli_foreman/template.rb +16 -9
  52. data/lib/hammer_cli_foreman/user.rb +10 -52
  53. data/lib/hammer_cli_foreman/usergroup.rb +3 -3
  54. data/lib/hammer_cli_foreman/version.rb +1 -1
  55. data/test/data/1.15/foreman_api.json +1 -1
  56. data/test/data/1.16/foreman_api.json +1 -0
  57. data/test/functional/compute_resource_test.rb +117 -0
  58. data/test/functional/filter_test.rb +2 -2
  59. data/test/functional/host_test.rb +61 -10
  60. data/test/functional/location_test.rb +5 -5
  61. data/test/functional/organization_test.rb +7 -7
  62. data/test/functional/role_test.rb +3 -3
  63. data/test/functional/smart_class_parameter_test.rb +5 -5
  64. data/test/functional/smart_variable_test.rb +1 -1
  65. data/test/functional/ssh_keys_test.rb +105 -0
  66. data/test/functional/template_test.rb +30 -4
  67. data/test/functional/user_test.rb +5 -5
  68. data/test/reports/TEST-HammerCLIForeman-Architecture-CreateCommand-parameters.xml +11 -0
  69. data/test/reports/TEST-HammerCLIForeman-Architecture-CreateCommand.xml +7 -0
  70. data/test/reports/TEST-HammerCLIForeman-Architecture-DeleteCommand-parameters.xml +13 -0
  71. data/test/reports/TEST-HammerCLIForeman-Architecture-DeleteCommand.xml +7 -0
  72. data/test/reports/TEST-HammerCLIForeman-Architecture-InfoCommand-output.xml +13 -0
  73. data/test/reports/TEST-HammerCLIForeman-Architecture-InfoCommand-parameters.xml +13 -0
  74. data/test/reports/TEST-HammerCLIForeman-Architecture-InfoCommand.xml +7 -0
  75. data/test/reports/TEST-HammerCLIForeman-Architecture-ListCommand-output.xml +13 -0
  76. data/test/reports/TEST-HammerCLIForeman-Architecture-ListCommand-parameters.xml +17 -0
  77. data/test/reports/TEST-HammerCLIForeman-Architecture-ListCommand.xml +7 -0
  78. data/test/reports/TEST-HammerCLIForeman-Architecture-UpdateCommand-parameters.xml +15 -0
  79. data/test/reports/TEST-HammerCLIForeman-Architecture-UpdateCommand.xml +7 -0
  80. data/test/reports/TEST-HammerCLIForeman-Architecture.xml +7 -0
  81. data/test/reports/TEST-HammerCLIForeman-CommonParameter-DeleteCommand-parameters.xml +11 -0
  82. data/test/reports/TEST-HammerCLIForeman-CommonParameter-DeleteCommand.xml +7 -0
  83. data/test/reports/TEST-HammerCLIForeman-CommonParameter-ListCommand-output.xml +13 -0
  84. data/test/reports/TEST-HammerCLIForeman-CommonParameter-ListCommand-parameters.xml +17 -0
  85. data/test/reports/TEST-HammerCLIForeman-CommonParameter-ListCommand.xml +7 -0
  86. data/test/reports/TEST-HammerCLIForeman-CommonParameter-SetCommand-parameters.xml +13 -0
  87. data/test/reports/TEST-HammerCLIForeman-CommonParameter-SetCommand.xml +7 -0
  88. data/test/reports/TEST-HammerCLIForeman-CommonParameter.xml +7 -0
  89. data/test/reports/TEST-HammerCLIForeman-ComputeResource-CreateCommand-parameters.xml +15 -0
  90. data/test/reports/TEST-HammerCLIForeman-ComputeResource-CreateCommand.xml +7 -0
  91. data/test/reports/TEST-HammerCLIForeman-ComputeResource-DeleteCommand-parameters.xml +13 -0
  92. data/test/reports/TEST-HammerCLIForeman-ComputeResource-DeleteCommand.xml +7 -0
  93. data/test/reports/TEST-HammerCLIForeman-ComputeResource-InfoCommand-output.xml +17 -0
  94. data/test/reports/TEST-HammerCLIForeman-ComputeResource-InfoCommand-parameters.xml +13 -0
  95. data/test/reports/TEST-HammerCLIForeman-ComputeResource-InfoCommand.xml +7 -0
  96. data/test/reports/TEST-HammerCLIForeman-ComputeResource-ListCommand-output.xml +15 -0
  97. data/test/reports/TEST-HammerCLIForeman-ComputeResource-ListCommand-parameters.xml +17 -0
  98. data/test/reports/TEST-HammerCLIForeman-ComputeResource-ListCommand.xml +7 -0
  99. data/test/reports/TEST-HammerCLIForeman-ComputeResource-UpdateCommand-parameters.xml +15 -0
  100. data/test/reports/TEST-HammerCLIForeman-ComputeResource-UpdateCommand.xml +7 -0
  101. data/test/reports/TEST-HammerCLIForeman-ComputeResource.xml +7 -0
  102. data/test/reports/TEST-HammerCLIForeman-Domain-CreateCommand-parameters.xml +11 -0
  103. data/test/reports/TEST-HammerCLIForeman-Domain-CreateCommand.xml +7 -0
  104. data/test/reports/TEST-HammerCLIForeman-Domain-DeleteCommand-parameters.xml +13 -0
  105. data/test/reports/TEST-HammerCLIForeman-Domain-DeleteCommand.xml +7 -0
  106. data/test/reports/TEST-HammerCLIForeman-Domain-DeleteParameterCommand-parameters.xml +15 -0
  107. data/test/reports/TEST-HammerCLIForeman-Domain-DeleteParameterCommand.xml +7 -0
  108. data/test/reports/TEST-HammerCLIForeman-Domain-InfoCommand-output.xml +21 -0
  109. data/test/reports/TEST-HammerCLIForeman-Domain-InfoCommand-parameters.xml +13 -0
  110. data/test/reports/TEST-HammerCLIForeman-Domain-InfoCommand.xml +7 -0
  111. data/test/reports/TEST-HammerCLIForeman-Domain-ListCommand-output.xml +13 -0
  112. data/test/reports/TEST-HammerCLIForeman-Domain-ListCommand-parameters.xml +17 -0
  113. data/test/reports/TEST-HammerCLIForeman-Domain-ListCommand.xml +7 -0
  114. data/test/reports/TEST-HammerCLIForeman-Domain-SetParameterCommand-parameters.xml +17 -0
  115. data/test/reports/TEST-HammerCLIForeman-Domain-SetParameterCommand.xml +7 -0
  116. data/test/reports/TEST-HammerCLIForeman-Domain-UpdateCommand-parameters.xml +15 -0
  117. data/test/reports/TEST-HammerCLIForeman-Domain-UpdateCommand.xml +7 -0
  118. data/test/reports/TEST-HammerCLIForeman-Domain.xml +7 -0
  119. data/test/reports/TEST-HammerCLIForeman-Environment-CreateCommand-parameters.xml +11 -0
  120. data/test/reports/TEST-HammerCLIForeman-Environment-CreateCommand.xml +7 -0
  121. data/test/reports/TEST-HammerCLIForeman-Environment-DeleteCommand-parameters.xml +13 -0
  122. data/test/reports/TEST-HammerCLIForeman-Environment-DeleteCommand.xml +7 -0
  123. data/test/reports/TEST-HammerCLIForeman-Environment-InfoCommand-output.xml +17 -0
  124. data/test/reports/TEST-HammerCLIForeman-Environment-InfoCommand-parameters.xml +13 -0
  125. data/test/reports/TEST-HammerCLIForeman-Environment-InfoCommand.xml +7 -0
  126. data/test/reports/TEST-HammerCLIForeman-Environment-ListCommand-output.xml +13 -0
  127. data/test/reports/TEST-HammerCLIForeman-Environment-ListCommand-parameters.xml +17 -0
  128. data/test/reports/TEST-HammerCLIForeman-Environment-ListCommand.xml +7 -0
  129. data/test/reports/TEST-HammerCLIForeman-Environment-UpdateCommand-parameters.xml +15 -0
  130. data/test/reports/TEST-HammerCLIForeman-Environment-UpdateCommand.xml +7 -0
  131. data/test/reports/TEST-HammerCLIForeman-Environment.xml +7 -0
  132. data/test/reports/TEST-HammerCLIForeman-ExceptionHandler.xml +13 -0
  133. data/test/reports/TEST-HammerCLIForeman-Host-CreateCommand-parameters.xml +46 -0
  134. data/test/reports/TEST-HammerCLIForeman-Host-CreateCommand.xml +7 -0
  135. data/test/reports/TEST-HammerCLIForeman-Host-DeleteCommand-parameters.xml +13 -0
  136. data/test/reports/TEST-HammerCLIForeman-Host-DeleteCommand.xml +7 -0
  137. data/test/reports/TEST-HammerCLIForeman-Host-DeleteParameterCommand-parameters.xml +15 -0
  138. data/test/reports/TEST-HammerCLIForeman-Host-DeleteParameterCommand.xml +7 -0
  139. data/test/reports/TEST-HammerCLIForeman-Host-InfoCommand-output.xml +85 -0
  140. data/test/reports/TEST-HammerCLIForeman-Host-InfoCommand-parameters.xml +13 -0
  141. data/test/reports/TEST-HammerCLIForeman-Host-InfoCommand.xml +7 -0
  142. data/test/reports/TEST-HammerCLIForeman-Host-ListCommand-output.xml +21 -0
  143. data/test/reports/TEST-HammerCLIForeman-Host-ListCommand-parameters.xml +17 -0
  144. data/test/reports/TEST-HammerCLIForeman-Host-ListCommand.xml +7 -0
  145. data/test/reports/TEST-HammerCLIForeman-Host-PuppetRunCommand-output.xml +9 -0
  146. data/test/reports/TEST-HammerCLIForeman-Host-PuppetRunCommand.xml +7 -0
  147. data/test/reports/TEST-HammerCLIForeman-Host-SetParameterCommand-parameters.xml +17 -0
  148. data/test/reports/TEST-HammerCLIForeman-Host-SetParameterCommand.xml +7 -0
  149. data/test/reports/TEST-HammerCLIForeman-Host-StatusCommand-output.xml +9 -0
  150. data/test/reports/TEST-HammerCLIForeman-Host-StatusCommand.xml +7 -0
  151. data/test/reports/TEST-HammerCLIForeman-Host-UpdateCommand-parameters.xml +40 -0
  152. data/test/reports/TEST-HammerCLIForeman-Host-UpdateCommand.xml +7 -0
  153. data/test/reports/TEST-HammerCLIForeman-Host.xml +7 -0
  154. data/test/reports/TEST-HammerCLIForeman-Hostgroup-CreateCommand-parameters.xml +11 -0
  155. data/test/reports/TEST-HammerCLIForeman-Hostgroup-CreateCommand.xml +7 -0
  156. data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteCommand-parameters.xml +11 -0
  157. data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteCommand.xml +7 -0
  158. data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteParameterCommand-parameters.xml +13 -0
  159. data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteParameterCommand.xml +7 -0
  160. data/test/reports/TEST-HammerCLIForeman-Hostgroup-InfoCommand-output.xml +29 -0
  161. data/test/reports/TEST-HammerCLIForeman-Hostgroup-InfoCommand-parameters.xml +11 -0
  162. data/test/reports/TEST-HammerCLIForeman-Hostgroup-InfoCommand.xml +7 -0
  163. data/test/reports/TEST-HammerCLIForeman-Hostgroup-ListCommand-output.xml +27 -0
  164. data/test/reports/TEST-HammerCLIForeman-Hostgroup-ListCommand-parameters.xml +17 -0
  165. data/test/reports/TEST-HammerCLIForeman-Hostgroup-ListCommand.xml +7 -0
  166. data/test/reports/TEST-HammerCLIForeman-Hostgroup-SetParameterCommand-parameters.xml +15 -0
  167. data/test/reports/TEST-HammerCLIForeman-Hostgroup-SetParameterCommand.xml +7 -0
  168. data/test/reports/TEST-HammerCLIForeman-Hostgroup-UpdateCommand-parameters.xml +13 -0
  169. data/test/reports/TEST-HammerCLIForeman-Hostgroup-UpdateCommand.xml +7 -0
  170. data/test/reports/TEST-HammerCLIForeman-Hostgroup.xml +7 -0
  171. data/test/reports/TEST-HammerCLIForeman-Location-CreateCommand-parameters.xml +11 -0
  172. data/test/reports/TEST-HammerCLIForeman-Location-CreateCommand-resource-disabled.xml +11 -0
  173. data/test/reports/TEST-HammerCLIForeman-Location-CreateCommand.xml +7 -0
  174. data/test/reports/TEST-HammerCLIForeman-Location-DeleteCommand-parameters.xml +13 -0
  175. data/test/reports/TEST-HammerCLIForeman-Location-DeleteCommand-resource-disabled.xml +11 -0
  176. data/test/reports/TEST-HammerCLIForeman-Location-DeleteCommand.xml +7 -0
  177. data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand-output.xml +17 -0
  178. data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand-parameters.xml +13 -0
  179. data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand-resource-disabled.xml +11 -0
  180. data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand.xml +7 -0
  181. data/test/reports/TEST-HammerCLIForeman-Location-ListCommand-output.xml +13 -0
  182. data/test/reports/TEST-HammerCLIForeman-Location-ListCommand-parameters.xml +17 -0
  183. data/test/reports/TEST-HammerCLIForeman-Location-ListCommand-resource-disabled.xml +11 -0
  184. data/test/reports/TEST-HammerCLIForeman-Location-ListCommand.xml +7 -0
  185. data/test/reports/TEST-HammerCLIForeman-Location-UpdateCommand-parameters.xml +15 -0
  186. data/test/reports/TEST-HammerCLIForeman-Location-UpdateCommand-resource-disabled.xml +11 -0
  187. data/test/reports/TEST-HammerCLIForeman-Location-UpdateCommand.xml +7 -0
  188. data/test/reports/TEST-HammerCLIForeman-Location.xml +7 -0
  189. data/test/reports/TEST-HammerCLIForeman-Medium-CreateCommand-parameters.xml +13 -0
  190. data/test/reports/TEST-HammerCLIForeman-Medium-CreateCommand.xml +7 -0
  191. data/test/reports/TEST-HammerCLIForeman-Medium-DeleteCommand-parameters.xml +13 -0
  192. data/test/reports/TEST-HammerCLIForeman-Medium-DeleteCommand.xml +7 -0
  193. data/test/reports/TEST-HammerCLIForeman-Medium-InfoCommand-output.xml +23 -0
  194. data/test/reports/TEST-HammerCLIForeman-Medium-InfoCommand-parameters.xml +13 -0
  195. data/test/reports/TEST-HammerCLIForeman-Medium-InfoCommand.xml +7 -0
  196. data/test/reports/TEST-HammerCLIForeman-Medium-ListCommand-output.xml +15 -0
  197. data/test/reports/TEST-HammerCLIForeman-Medium-ListCommand-parameters.xml +17 -0
  198. data/test/reports/TEST-HammerCLIForeman-Medium-ListCommand.xml +7 -0
  199. data/test/reports/TEST-HammerCLIForeman-Medium-UpdateCommand-parameters.xml +17 -0
  200. data/test/reports/TEST-HammerCLIForeman-Medium-UpdateCommand.xml +7 -0
  201. data/test/reports/TEST-HammerCLIForeman-Medium.xml +7 -0
  202. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-CreateCommand-parameters.xml +11 -0
  203. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-CreateCommand.xml +7 -0
  204. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteCommand-parameters.xml +13 -0
  205. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteCommand.xml +7 -0
  206. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteParameterCommand-parameters.xml +13 -0
  207. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteParameterCommand.xml +7 -0
  208. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-InfoCommand-output.xml +27 -0
  209. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-InfoCommand-parameters.xml +13 -0
  210. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-InfoCommand.xml +7 -0
  211. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-ListCommand-output.xml +17 -0
  212. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-ListCommand-parameters.xml +17 -0
  213. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-ListCommand.xml +7 -0
  214. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-SetParameterCommand-parameters.xml +15 -0
  215. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-SetParameterCommand.xml +7 -0
  216. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-UpdateCommand-parameters.xml +17 -0
  217. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-UpdateCommand.xml +7 -0
  218. data/test/reports/TEST-HammerCLIForeman-OperatingSystem.xml +7 -0
  219. data/test/reports/TEST-HammerCLIForeman-Organization-CreateCommand-parameters.xml +11 -0
  220. data/test/reports/TEST-HammerCLIForeman-Organization-CreateCommand-resource-disabled.xml +11 -0
  221. data/test/reports/TEST-HammerCLIForeman-Organization-CreateCommand.xml +7 -0
  222. data/test/reports/TEST-HammerCLIForeman-Organization-DeleteCommand-parameters.xml +13 -0
  223. data/test/reports/TEST-HammerCLIForeman-Organization-DeleteCommand-resource-disabled.xml +11 -0
  224. data/test/reports/TEST-HammerCLIForeman-Organization-DeleteCommand.xml +7 -0
  225. data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand-output.xml +17 -0
  226. data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand-parameters.xml +13 -0
  227. data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand-resource-disabled.xml +11 -0
  228. data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand.xml +7 -0
  229. data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand-output.xml +13 -0
  230. data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand-parameters.xml +17 -0
  231. data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand-resource-disabled.xml +11 -0
  232. data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand.xml +7 -0
  233. data/test/reports/TEST-HammerCLIForeman-Organization-UpdateCommand-parameters.xml +15 -0
  234. data/test/reports/TEST-HammerCLIForeman-Organization-UpdateCommand-resource-disabled.xml +11 -0
  235. data/test/reports/TEST-HammerCLIForeman-Organization-UpdateCommand.xml +7 -0
  236. data/test/reports/TEST-HammerCLIForeman-Organization.xml +7 -0
  237. data/test/reports/TEST-HammerCLIForeman-PartitionTable-CreateCommand-parameters.xml +13 -0
  238. data/test/reports/TEST-HammerCLIForeman-PartitionTable-CreateCommand.xml +7 -0
  239. data/test/reports/TEST-HammerCLIForeman-PartitionTable-DeleteCommand-parameters.xml +13 -0
  240. data/test/reports/TEST-HammerCLIForeman-PartitionTable-DeleteCommand.xml +7 -0
  241. data/test/reports/TEST-HammerCLIForeman-PartitionTable-DumpCommand-parameters.xml +15 -0
  242. data/test/reports/TEST-HammerCLIForeman-PartitionTable-DumpCommand.xml +7 -0
  243. data/test/reports/TEST-HammerCLIForeman-PartitionTable-InfoCommand-output.xml +19 -0
  244. data/test/reports/TEST-HammerCLIForeman-PartitionTable-InfoCommand-parameters.xml +13 -0
  245. data/test/reports/TEST-HammerCLIForeman-PartitionTable-InfoCommand.xml +7 -0
  246. data/test/reports/TEST-HammerCLIForeman-PartitionTable-ListCommand-output.xml +15 -0
  247. data/test/reports/TEST-HammerCLIForeman-PartitionTable-ListCommand-parameters.xml +17 -0
  248. data/test/reports/TEST-HammerCLIForeman-PartitionTable-ListCommand.xml +7 -0
  249. data/test/reports/TEST-HammerCLIForeman-PartitionTable-UpdateCommand-parameters.xml +13 -0
  250. data/test/reports/TEST-HammerCLIForeman-PartitionTable-UpdateCommand.xml +7 -0
  251. data/test/reports/TEST-HammerCLIForeman-PartitionTable.xml +7 -0
  252. data/test/reports/TEST-HammerCLIForeman-SmartProxy-CreateCommand-parameters.xml +13 -0
  253. data/test/reports/TEST-HammerCLIForeman-SmartProxy-CreateCommand.xml +7 -0
  254. data/test/reports/TEST-HammerCLIForeman-SmartProxy-DeleteCommand-parameters.xml +13 -0
  255. data/test/reports/TEST-HammerCLIForeman-SmartProxy-DeleteCommand.xml +7 -0
  256. data/test/reports/TEST-HammerCLIForeman-SmartProxy-InfoCommand-output.xml +21 -0
  257. data/test/reports/TEST-HammerCLIForeman-SmartProxy-InfoCommand-parameters.xml +13 -0
  258. data/test/reports/TEST-HammerCLIForeman-SmartProxy-InfoCommand.xml +7 -0
  259. data/test/reports/TEST-HammerCLIForeman-SmartProxy-ListCommand-output.xml +15 -0
  260. data/test/reports/TEST-HammerCLIForeman-SmartProxy-ListCommand-parameters.xml +11 -0
  261. data/test/reports/TEST-HammerCLIForeman-SmartProxy-ListCommand.xml +7 -0
  262. data/test/reports/TEST-HammerCLIForeman-SmartProxy-UpdateCommand-parameters.xml +15 -0
  263. data/test/reports/TEST-HammerCLIForeman-SmartProxy-UpdateCommand.xml +7 -0
  264. data/test/reports/TEST-HammerCLIForeman-SmartProxy.xml +7 -0
  265. data/test/reports/TEST-HammerCLIForeman-Subnet-CreateCommand-parameters.xml +15 -0
  266. data/test/reports/TEST-HammerCLIForeman-Subnet-CreateCommand.xml +7 -0
  267. data/test/reports/TEST-HammerCLIForeman-Subnet-DeleteCommand-parameters.xml +13 -0
  268. data/test/reports/TEST-HammerCLIForeman-Subnet-DeleteCommand.xml +7 -0
  269. data/test/reports/TEST-HammerCLIForeman-Subnet-InfoCommand-output.xml +43 -0
  270. data/test/reports/TEST-HammerCLIForeman-Subnet-InfoCommand-parameters.xml +13 -0
  271. data/test/reports/TEST-HammerCLIForeman-Subnet-InfoCommand.xml +7 -0
  272. data/test/reports/TEST-HammerCLIForeman-Subnet-ListCommand-output.xml +17 -0
  273. data/test/reports/TEST-HammerCLIForeman-Subnet-ListCommand-parameters.xml +17 -0
  274. data/test/reports/TEST-HammerCLIForeman-Subnet-ListCommand.xml +7 -0
  275. data/test/reports/TEST-HammerCLIForeman-Subnet-UpdateCommand-parameters.xml +15 -0
  276. data/test/reports/TEST-HammerCLIForeman-Subnet-UpdateCommand.xml +7 -0
  277. data/test/reports/TEST-HammerCLIForeman-Subnet.xml +7 -0
  278. data/test/reports/TEST-HammerCLIForeman-Template-CreateCommand-parameters.xml +15 -0
  279. data/test/reports/TEST-HammerCLIForeman-Template-CreateCommand.xml +7 -0
  280. data/test/reports/TEST-HammerCLIForeman-Template-DeleteCommand-parameters.xml +11 -0
  281. data/test/reports/TEST-HammerCLIForeman-Template-DeleteCommand.xml +7 -0
  282. data/test/reports/TEST-HammerCLIForeman-Template-DumpCommand-parameters.xml +12 -0
  283. data/test/reports/TEST-HammerCLIForeman-Template-DumpCommand.xml +7 -0
  284. data/test/reports/TEST-HammerCLIForeman-Template-InfoCommand-output.xml +17 -0
  285. data/test/reports/TEST-HammerCLIForeman-Template-InfoCommand-parameters.xml +11 -0
  286. data/test/reports/TEST-HammerCLIForeman-Template-InfoCommand.xml +7 -0
  287. data/test/reports/TEST-HammerCLIForeman-Template-ListCommand-output.xml +15 -0
  288. data/test/reports/TEST-HammerCLIForeman-Template-ListCommand-parameters.xml +17 -0
  289. data/test/reports/TEST-HammerCLIForeman-Template-ListCommand.xml +7 -0
  290. data/test/reports/TEST-HammerCLIForeman-Template-ListKindsCommand-parameters.xml +9 -0
  291. data/test/reports/TEST-HammerCLIForeman-Template-ListKindsCommand.xml +7 -0
  292. data/test/reports/TEST-HammerCLIForeman-Template-UpdateCommand-parameters.xml +11 -0
  293. data/test/reports/TEST-HammerCLIForeman-Template-UpdateCommand.xml +7 -0
  294. data/test/reports/TEST-HammerCLIForeman-Template.xml +7 -0
  295. data/test/reports/TEST-HammerCLIForeman-User-CreateCommand-parameters.xml +19 -0
  296. data/test/reports/TEST-HammerCLIForeman-User-CreateCommand.xml +7 -0
  297. data/test/reports/TEST-HammerCLIForeman-User-DeleteCommand-parameters.xml +11 -0
  298. data/test/reports/TEST-HammerCLIForeman-User-DeleteCommand.xml +7 -0
  299. data/test/reports/TEST-HammerCLIForeman-User-InfoCommand-output.xml +23 -0
  300. data/test/reports/TEST-HammerCLIForeman-User-InfoCommand-parameters.xml +11 -0
  301. data/test/reports/TEST-HammerCLIForeman-User-InfoCommand.xml +7 -0
  302. data/test/reports/TEST-HammerCLIForeman-User-ListCommand-output.xml +17 -0
  303. data/test/reports/TEST-HammerCLIForeman-User-ListCommand-parameters.xml +17 -0
  304. data/test/reports/TEST-HammerCLIForeman-User-ListCommand.xml +7 -0
  305. data/test/reports/TEST-HammerCLIForeman-User-UpdateCommand-parameters.xml +11 -0
  306. data/test/reports/TEST-HammerCLIForeman-User-UpdateCommand.xml +7 -0
  307. data/test/reports/TEST-HammerCLIForeman-User.xml +7 -0
  308. data/test/reports/TEST-MiniTest-Spec.xml +7 -0
  309. data/test/unit/api/interactive_basic_auth_test.rb +20 -1
  310. data/test/unit/api/session_authenticator_wrapper_test.rb +23 -8
  311. data/test/unit/api/void_auth_test.rb +11 -0
  312. data/test/unit/commands_test.rb +1 -1
  313. data/test/unit/exception_handler_test.rb +24 -3
  314. data/test/unit/helpers/command.rb +6 -2
  315. data/test/unit/host_test.rb +2 -2
  316. data/test/unit/hostgroup_test.rb +5 -3
  317. data/test/unit/id_resolver_test.rb +53 -5
  318. data/test/unit/media_test.rb +2 -2
  319. data/test/unit/option_sources/id_params_test.rb +30 -0
  320. data/test/unit/option_sources/ids_params_test.rb +30 -0
  321. data/test/unit/output/formatters_test.rb +4 -0
  322. data/test/unit/smart_class_parameter_test.rb +4 -4
  323. data/test/unit/smart_variable_test.rb +2 -2
  324. data/test/unit/user_test.rb +1 -2
  325. metadata +569 -69
@@ -6,8 +6,8 @@ module HammerCLIForeman
6
6
  command_name "login"
7
7
  desc _("Set credentials")
8
8
 
9
- option ["-u", "--username"], "USERNAME", _("username to access the remote system")
10
- option ["-p", "--password"], "PASSWORD", _("password to access the remote system")
9
+ option ["-u", "--username"], "USERNAME", _("Username to access the remote system")
10
+ option ["-p", "--password"], "PASSWORD", _("Password to access the remote system")
11
11
 
12
12
  def execute
13
13
  if !(HammerCLIForeman.foreman_api_connection.authenticator.is_a?(HammerCLIForeman::Api::SessionAuthenticatorWrapper))
@@ -2,7 +2,7 @@ module HammerCLIForeman
2
2
  class AuthSourceLdap < HammerCLIForeman::Command
3
3
  resource :auth_source_ldaps
4
4
  command_name 'ldap'
5
- desc _('Manage LDAP auth sources.')
5
+ desc _('Manage LDAP auth sources')
6
6
 
7
7
  class ListCommand < HammerCLIForeman::ListCommand
8
8
  output do
@@ -49,21 +49,21 @@ module HammerCLIForeman
49
49
  end
50
50
 
51
51
  class CreateCommand < HammerCLIForeman::CreateCommand
52
- success_message _('Auth source [%{name}] created')
52
+ success_message _('Auth source [%{name}] created.')
53
53
  failure_message _('Could not create the Auth Source')
54
54
 
55
55
  build_options
56
56
  end
57
57
 
58
58
  class DeleteCommand < HammerCLIForeman::DeleteCommand
59
- success_message _('Auth source [%{name}] deleted')
59
+ success_message _('Auth source [%{name}] deleted.')
60
60
  failure_message _('Could not delete the Auth Source')
61
61
 
62
62
  build_options
63
63
  end
64
64
 
65
65
  class UpdateCommand < HammerCLIForeman::UpdateCommand
66
- success_message _('Auth source [%{name}] updated')
66
+ success_message _('Auth source [%{name}] updated.')
67
67
  failure_message _('Could not update the Auth Source')
68
68
 
69
69
  build_options
@@ -53,7 +53,7 @@ module HammerCLIForeman
53
53
  # produce [ { 'attr' => 'val' }, ... ]
54
54
  col = HammerCLI::Output::RecordCollection.new(data.map { |r| r.keys.length == 1 ? r[r.keys[0]] : r })
55
55
  else
56
- raise RuntimeError.new(_("Received data of unknown format"))
56
+ raise RuntimeError.new(_("Received data of unknown format."))
57
57
  end
58
58
  col
59
59
  end
@@ -115,16 +115,17 @@ module HammerCLIForeman
115
115
  super(builder_params.to_hash, &nil)
116
116
  end
117
117
 
118
- def get_identifier
119
- @identifier ||= get_resource_id(resource)
118
+ def get_identifier(all_opts=all_options)
119
+ @identifier ||= get_resource_id(resource, :all_options => all_opts)
120
120
  @identifier
121
121
  end
122
122
 
123
123
  def get_resource_id(resource, options={})
124
+ all_opts = options[:all_options] || all_options
124
125
  if options[:scoped]
125
- opts = resolver.scoped_options(resource.singular_name, all_options)
126
+ opts = resolver.scoped_options(resource.singular_name, all_opts, :single)
126
127
  else
127
- opts = all_options
128
+ opts = all_opts
128
129
  end
129
130
  begin
130
131
  resolver.send("#{resource.singular_name}_id", opts)
@@ -137,7 +138,8 @@ module HammerCLIForeman
137
138
  end
138
139
 
139
140
  def get_resource_ids(resource, options={})
140
- opts = resolver.scoped_options(resource.singular_name, all_options)
141
+ all_opts = options[:all_options] || all_options
142
+ opts = resolver.scoped_options(resource.singular_name, all_opts, :multi)
141
143
  begin
142
144
  resolver.send("#{resource.singular_name}_ids", opts)
143
145
  rescue HammerCLIForeman::MissingSearchOptions => e
@@ -164,25 +166,6 @@ module HammerCLIForeman
164
166
 
165
167
  def send_request
166
168
  transform_format(super)
167
- rescue HammerCLIForeman::MissingSearchOptions => e
168
-
169
- switches = self.class.find_options(:referenced_resource => e.resource.singular_name).map(&:long_switch)
170
-
171
- if switches.empty?
172
- error_message = _("Could not find %{resource}. Some search options were missing, please see --help.")
173
- elsif switches.length == 1
174
- error_message = _("Could not find %{resource}, please set option %{switches}.")
175
- else
176
- error_message = _("Could not find %{resource}, please set one of options %{switches}.")
177
- end
178
-
179
- raise MissingSearchOptions.new(
180
- error_message % {
181
- :resource => e.resource.singular_name,
182
- :switches => switches.join(", ")
183
- },
184
- e.resource
185
- )
186
169
  end
187
170
 
188
171
  def transform_format(data)
@@ -190,36 +173,14 @@ module HammerCLIForeman
190
173
  end
191
174
 
192
175
  def customized_options
193
- params = options
194
- # resolve all '<resource_name>_id' parameters if they are defined as options
195
- # (they can be skipped using .without or .expand.except)
196
- IdParamsFilter.new(:only_required => false).for_action(resource.action(action)).each do |api_param|
197
- param_resource = HammerCLIForeman.param_to_resource(api_param.name)
198
- if param_resource && respond_to?(HammerCLI.option_accessor_name("#{param_resource.singular_name}_id"))
199
- resource_id = get_resource_id(param_resource, :scoped => true, :required => api_param.required?)
200
- params[HammerCLI.option_accessor_name(api_param.name)] = resource_id if resource_id
201
- end
202
- end
203
-
204
- # resolve all '<resource_name>_ids' parameters if they are defined as options
205
- IdArrayParamsFilter.new(:only_required => false).for_action(resource.action(action)).each do |api_param|
206
- param_resource = HammerCLIForeman.param_to_resource(api_param.name)
207
- if param_resource && respond_to?(HammerCLI.option_accessor_name("#{param_resource.singular_name}_ids"))
208
- resource_ids = get_resource_ids(param_resource, :scoped => true, :required => api_param.required?)
209
- params[HammerCLI.option_accessor_name(api_param.name)] = resource_ids if resource_ids
210
- end
211
- end
212
-
213
- # resolve 'id' parameter if it's defined as an option
214
- id_option_name = HammerCLI.option_accessor_name('id')
215
- params[id_option_name] ||= get_identifier if respond_to?(id_option_name)
216
- params
176
+ # this method is deprecated and will be removed in future versions.
177
+ # Check option_sources for custom tuning of options
178
+ options
217
179
  end
218
180
 
219
181
  def request_params
220
182
  params = customized_options
221
183
  params_pruned = method_options(params)
222
-
223
184
  # Options defined manualy in commands are removed in method_options.
224
185
  # Manual ids are common so its handling is covered here
225
186
  id_option_name = HammerCLI.option_accessor_name('id')
@@ -227,6 +188,14 @@ module HammerCLIForeman
227
188
  params_pruned
228
189
  end
229
190
 
191
+ def option_sources
192
+ sources = super
193
+ sources << HammerCLIForeman::OptionSources::IdParams.new(self)
194
+ sources << HammerCLIForeman::OptionSources::IdsParams.new(self)
195
+ sources << HammerCLIForeman::OptionSources::SelfParam.new(self)
196
+ sources
197
+ end
198
+
230
199
  private
231
200
 
232
201
  def resource_search_requested(resource, options, plural=false)
@@ -237,7 +206,6 @@ module HammerCLIForeman
237
206
  end
238
207
  !(filed_options & searchable_options).empty?
239
208
  end
240
-
241
209
  end
242
210
 
243
211
 
@@ -506,11 +474,11 @@ module HammerCLIForeman
506
474
  end
507
475
 
508
476
  def self.failure_message(msg = nil)
509
- super(msg) || default_message(_('Could not associate the %{resource_name}'))
477
+ super(msg) || default_message(_('Could not associate the %{resource_name}.'))
510
478
  end
511
479
 
512
480
  def self.success_message(msg = nil)
513
- super(msg) || default_message(_('The %{resource_name} has been associated'))
481
+ super(msg) || default_message(_('The %{resource_name} has been associated.'))
514
482
  end
515
483
 
516
484
  def get_new_ids
@@ -544,11 +512,11 @@ module HammerCLIForeman
544
512
  end
545
513
 
546
514
  def self.failure_message(msg = nil)
547
- super(msg) || default_message(_('Could not disassociate the %{resource_name}'))
515
+ super(msg) || default_message(_('Could not disassociate the %{resource_name}.'))
548
516
  end
549
517
 
550
518
  def self.success_message(msg = nil)
551
- super(msg) || default_message(_('The %{resource_name} has been disassociated'))
519
+ super(msg) || default_message(_('The %{resource_name} has been disassociated.'))
552
520
  end
553
521
  end
554
522
  end
@@ -19,14 +19,14 @@ module HammerCLIForeman
19
19
  class SetCommand < HammerCLIForeman::Command
20
20
 
21
21
  command_name "set"
22
- desc _("Set a global parameter.")
22
+ desc _("Set a global parameter")
23
23
 
24
24
  success_message_for :create, _("Created parameter [%{name}] with value [%{value}].")
25
25
  success_message_for :update, _("Parameter [%{name}] updated to [%{value}].")
26
26
 
27
- option "--name", "NAME", _("parameter name"), :required => true
28
- option "--value", "VALUE", _("parameter value"), :required => true
29
- option "--hidden-value", "HIDDEN_VALUE", _("should the value be hidden"), :format => HammerCLI::Options::Normalizers::Bool.new
27
+ option "--name", "NAME", _("Parameter name"), :required => true
28
+ option "--value", "VALUE", _("Parameter value"), :required => true
29
+ option "--hidden-value", "HIDDEN_VALUE", _("Should the value be hidden"), :format => HammerCLI::Options::Normalizers::Bool.new
30
30
 
31
31
  def action
32
32
  @action ||= parameter_exist? ? :update : :create
@@ -65,4 +65,4 @@ module HammerCLIForeman
65
65
  end
66
66
  end
67
67
 
68
- HammerCLI::MainCommand.subcommand 'global-parameter', _("Manipulate global parameters."), HammerCLIForeman::CommonParameter
68
+ HammerCLI::MainCommand.subcommand 'global-parameter', _("Manipulate global parameters"), HammerCLIForeman::CommonParameter
@@ -70,19 +70,31 @@ module HammerCLIForeman
70
70
 
71
71
  class CreateCommand < HammerCLIForeman::CreateCommand
72
72
 
73
- success_message _("Compute resource created")
73
+ VALIDATION_PER_PROVIDER = {
74
+ 'libvirt' => [:option_url],
75
+ 'ovirt' => [:option_url, :option_user, :option_password, :option_datacenter],
76
+ 'openstack' => [:option_url, :option_user, :option_password],
77
+ 'racksapce' => [:option_url],
78
+ 'ec2' => [:option_region, :option_user, :option_password],
79
+ 'vmware' => [:option_user, :option_password, :option_datacenter, :option_server]
80
+ }
81
+
82
+ success_message _("Compute resource created.")
74
83
  failure_message _("Could not create the compute resource")
75
84
 
76
85
  build_options
77
86
 
78
87
  validate_options do
79
- all(:option_name, :option_url, :option_provider).required
88
+ required_options = (VALIDATION_PER_PROVIDER[
89
+ option(:option_provider).value.to_s.downcase
90
+ ] || []).unshift(:option_name, :option_provider).uniq
91
+
92
+ all(*required_options).required
80
93
  end
81
94
  end
82
95
 
83
-
84
96
  class UpdateCommand < HammerCLIForeman::UpdateCommand
85
- success_message _("Compute resource updated")
97
+ success_message _("Compute resource updated.")
86
98
  failure_message _("Could not update the compute resource")
87
99
 
88
100
  build_options :without => :name
@@ -90,7 +102,7 @@ module HammerCLIForeman
90
102
 
91
103
 
92
104
  class DeleteCommand < HammerCLIForeman::DeleteCommand
93
- success_message _("Compute resource deleted")
105
+ success_message _("Compute resource deleted.")
94
106
  failure_message _("Could not delete the compute resource")
95
107
 
96
108
  build_options
@@ -126,5 +138,3 @@ module HammerCLIForeman
126
138
  end
127
139
 
128
140
  end
129
-
130
-
@@ -20,21 +20,21 @@ module HammerCLIForeman
20
20
  end
21
21
 
22
22
  class CreateCommand < HammerCLIForeman::CreateCommand
23
- success_message _("Config group created")
23
+ success_message _("Config group created.")
24
24
  failure_message _("Could not create the config group")
25
25
 
26
26
  build_options
27
27
  end
28
28
 
29
29
  class UpdateCommand < HammerCLIForeman::UpdateCommand
30
- success_message _("Config group updated")
30
+ success_message _("Config group updated.")
31
31
  failure_message _("Could not update the config group")
32
32
 
33
33
  build_options
34
34
  end
35
35
 
36
36
  class DeleteCommand < HammerCLIForeman::DeleteCommand
37
- success_message _("Config group has been deleted")
37
+ success_message _("Config group has been deleted.")
38
38
  failure_message _("Could not delete the config group")
39
39
 
40
40
  build_options
@@ -54,7 +54,7 @@ module HammerCLIForeman
54
54
  class CreateCommand < HammerCLIForeman::CreateCommand
55
55
  include DomainUpdateCreateCommons
56
56
 
57
- success_message _("Domain [%{name}] created")
57
+ success_message _("Domain [%{name}] created.")
58
58
  failure_message _("Could not create the domain")
59
59
 
60
60
  option "--description", "DESC", _("Full name describing the domain"), :attribute_name => :option_fullname
@@ -65,7 +65,7 @@ module HammerCLIForeman
65
65
  class UpdateCommand < HammerCLIForeman::UpdateCommand
66
66
  include DomainUpdateCreateCommons
67
67
 
68
- success_message _("Domain [%{name}] updated")
68
+ success_message _("Domain [%{name}] updated.")
69
69
  failure_message _("Could not update the domain")
70
70
 
71
71
  option "--description", "DESC", _("Full name describing the domain"), :attribute_name => :option_fullname
@@ -75,7 +75,7 @@ module HammerCLIForeman
75
75
 
76
76
  class DeleteCommand < HammerCLIForeman::DeleteCommand
77
77
 
78
- success_message _("Domain [%{name}] deleted")
78
+ success_message _("Domain [%{name}] deleted.")
79
79
  failure_message _("Could not delete the domain")
80
80
 
81
81
  build_options
@@ -83,7 +83,7 @@ module HammerCLIForeman
83
83
 
84
84
 
85
85
  class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
86
- desc _("Create or update parameter for a domain.")
86
+ desc _("Create or update parameter for a domain")
87
87
 
88
88
  success_message_for :update, _("Domain parameter updated")
89
89
  success_message_for :create, _("New domain parameter created")
@@ -99,9 +99,9 @@ module HammerCLIForeman
99
99
 
100
100
 
101
101
  class DeleteParameterCommand < HammerCLIForeman::Parameter::DeleteCommand
102
- desc _("Delete parameter for a domain.")
102
+ desc _("Delete parameter for a domain")
103
103
 
104
- success_message _("Domain parameter deleted")
104
+ success_message _("Domain parameter deleted.")
105
105
 
106
106
  def validate_options
107
107
  super
@@ -115,5 +115,3 @@ module HammerCLIForeman
115
115
  end
116
116
 
117
117
  end
118
-
119
-
@@ -31,7 +31,7 @@ module HammerCLIForeman
31
31
 
32
32
 
33
33
  class CreateCommand < HammerCLIForeman::CreateCommand
34
- success_message _("Environment created")
34
+ success_message _("Environment created.")
35
35
  failure_message _("Could not create the environment")
36
36
 
37
37
  build_options
@@ -39,7 +39,7 @@ module HammerCLIForeman
39
39
 
40
40
 
41
41
  class UpdateCommand < HammerCLIForeman::UpdateCommand
42
- success_message _("Environment updated")
42
+ success_message _("Environment updated.")
43
43
  failure_message _("Could not update the environment")
44
44
 
45
45
  build_options
@@ -47,7 +47,7 @@ module HammerCLIForeman
47
47
 
48
48
 
49
49
  class DeleteCommand < HammerCLIForeman::DeleteCommand
50
- success_message _("Environment deleted")
50
+ success_message _("Environment deleted.")
51
51
  failure_message _("Could not delete the environment")
52
52
 
53
53
  build_options
@@ -11,6 +11,7 @@ module HammerCLIForeman
11
11
  [RestClient::Forbidden, :handle_forbidden],
12
12
  [RestClient::UnprocessableEntity, :handle_unprocessable_entity],
13
13
  [RestClient::MovedPermanently, :handle_moved_permanently],
14
+ [RestClient::BadRequest, :handle_bad_request],
14
15
  [HammerCLIForeman::Api::UnauthorizedError, :handle_foreman_unauthorized],
15
16
  [HammerCLIForeman::Api::SessionExpired, :handle_sesion_expired],
16
17
  [ArgumentError, :handle_argument_error],
@@ -42,8 +43,8 @@ module HammerCLIForeman
42
43
  error = [_("Redirection of API call detected.")]
43
44
  https_message = _("It seems hammer is configured to use HTTP and the server prefers HTTPS.")
44
45
  error << https_message if strip_protocol(e.response.headers[:location]) == strip_protocol(e.response.request.url)
45
- error << _("Update your server url configuration")
46
- error << _("you can set 'follow_redirects' to one of :default or :always to enable redirects following")
46
+ error << _("Update your server url configuration.")
47
+ error << _("You can set 'follow_redirects' to one of :default or :always to enable redirects following.")
47
48
  print_error error.join("\n")
48
49
  log_full_error e
49
50
  HammerCLI::EX_CONFIG
@@ -64,7 +65,16 @@ module HammerCLIForeman
64
65
 
65
66
 
66
67
  def handle_forbidden(e)
67
- print_error _("Forbidden - server refused to process the request")
68
+ if e.response
69
+ response = JSON.parse(e.response)
70
+ error = response['error']
71
+ if error && error['message'] && error['details']
72
+ message = error['message'] + "\n" + error['details']
73
+ end
74
+ end
75
+ message ||= _("Forbidden - server refused to process the request.")
76
+
77
+ print_error message
68
78
  log_full_error e
69
79
  HammerCLI::EX_NOPERM
70
80
  end
@@ -96,6 +106,12 @@ module HammerCLIForeman
96
106
  log_full_error e
97
107
  end
98
108
 
109
+ def handle_bad_request(e)
110
+ print_error "#{e.message}#{response_message(e.response)}"
111
+ log_full_error e
112
+ HammerCLI::EX_DATAERR
113
+ end
114
+
99
115
  def ssl_cert_instructions
100
116
  host_url = HammerCLI::Settings.get(:_params, :host) || HammerCLI::Settings.get(:foreman, :host)
101
117
  uri = URI.parse(host_url)
@@ -114,7 +130,7 @@ module HammerCLIForeman
114
130
  instructions = _("The following configuration option were used for the SSL connection:" ) + "\n"
115
131
  instructions << " ssl_ca_path = #{ssl_option[:ssl_ca_path]}\n" unless ssl_option[:ssl_ca_path].nil?
116
132
  instructions << " ssl_ca_file = #{ssl_option[:ssl_ca_file]}\n" unless ssl_option[:ssl_ca_file].nil?
117
- instructions << "\n" + _("Make sure the location contains an unexpired and valid CA certificate for #{host_url}")
133
+ instructions << "\n" + _("Make sure the location contains an unexpired and valid CA certificate for %s.") % host_url
118
134
  else
119
135
  instructions = _("You can use hammer to fetch the CA certificate from the server. Be aware that hammer cannot verify whether the certificate is correct and you should verify its authenticity after downloading it.")
120
136
  instructions << "\n\n" + _("Download the certificate as follows:")
@@ -131,6 +147,13 @@ module HammerCLIForeman
131
147
 
132
148
  private
133
149
 
150
+ def response_message(response)
151
+ message = JSON.parse(response)["error"]["message"]
152
+ "\n #{message}"
153
+ rescue JSON::ParserError
154
+ ''
155
+ end
156
+
134
157
  def strip_protocol(url)
135
158
  url.gsub(%r'^http(s)?://','').gsub(%r'//', '/')
136
159
  end