hammer_cli_foreman 0.18.2 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (307) hide show
  1. checksums.yaml +4 -4
  2. data/config/foreman.yml +20 -0
  3. data/doc/host_create.md +19 -10
  4. data/doc/release_notes.md +12 -4
  5. data/lib/hammer_cli_foreman/api/authenticator.rb +81 -0
  6. data/lib/hammer_cli_foreman/api/connection.rb +48 -33
  7. data/lib/hammer_cli_foreman/api/interactive_basic_auth.rb +2 -2
  8. data/lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb +100 -0
  9. data/lib/hammer_cli_foreman/api/oauth/password_grant.rb +81 -0
  10. data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +34 -80
  11. data/lib/hammer_cli_foreman/auth.rb +54 -20
  12. data/lib/hammer_cli_foreman/authenticate/login.rb +21 -0
  13. data/lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb +1 -0
  14. data/lib/hammer_cli_foreman/command_extensions/ping.rb +14 -0
  15. data/lib/hammer_cli_foreman/command_extensions/status.rb +44 -0
  16. data/lib/hammer_cli_foreman/command_extensions.rb +2 -0
  17. data/lib/hammer_cli_foreman/commands.rb +1 -1
  18. data/lib/hammer_cli_foreman/compute_attribute.rb +22 -5
  19. data/lib/hammer_cli_foreman/compute_resource/base.rb +1 -1
  20. data/lib/hammer_cli_foreman/compute_resource/ec2.rb +1 -1
  21. data/lib/hammer_cli_foreman/compute_resource/gce.rb +1 -1
  22. data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +11 -8
  23. data/lib/hammer_cli_foreman/compute_resource/openstack.rb +1 -1
  24. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +7 -4
  25. data/lib/hammer_cli_foreman/compute_resource/rackspace.rb +1 -1
  26. data/lib/hammer_cli_foreman/compute_resource/vmware.rb +6 -6
  27. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +1 -1
  28. data/lib/hammer_cli_foreman/location.rb +1 -1
  29. data/lib/hammer_cli_foreman/openid_connect.rb +68 -0
  30. data/lib/hammer_cli_foreman/organization.rb +1 -1
  31. data/lib/hammer_cli_foreman/output/formatters.rb +4 -5
  32. data/lib/hammer_cli_foreman/partition_table.rb +1 -0
  33. data/lib/hammer_cli_foreman/ping.rb +24 -0
  34. data/lib/hammer_cli_foreman/report_template.rb +3 -2
  35. data/lib/hammer_cli_foreman/sessions.rb +92 -0
  36. data/lib/hammer_cli_foreman/status.rb +53 -0
  37. data/lib/hammer_cli_foreman/subnet.rb +1 -0
  38. data/lib/hammer_cli_foreman/template.rb +1 -0
  39. data/lib/hammer_cli_foreman/version.rb +1 -1
  40. data/lib/hammer_cli_foreman.rb +8 -0
  41. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  42. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  43. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  47. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  48. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  49. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  50. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  51. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  52. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  53. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  54. data/test/data/1.24/foreman_api.json +1 -0
  55. data/test/data/README.md +2 -2
  56. data/test/functional/commands/list_test.rb +2 -2
  57. data/test/functional/host_test.rb +0 -20
  58. data/test/functional/ping_test.rb +34 -0
  59. data/test/functional/status_test.rb +46 -0
  60. data/test/reports/TEST-HammerCLIForeman-Architecture-CreateCommand-parameters.xml +11 -0
  61. data/test/reports/TEST-HammerCLIForeman-Architecture-CreateCommand.xml +7 -0
  62. data/test/reports/TEST-HammerCLIForeman-Architecture-DeleteCommand-parameters.xml +13 -0
  63. data/test/reports/TEST-HammerCLIForeman-Architecture-DeleteCommand.xml +7 -0
  64. data/test/reports/TEST-HammerCLIForeman-Architecture-InfoCommand-output.xml +13 -0
  65. data/test/reports/TEST-HammerCLIForeman-Architecture-InfoCommand-parameters.xml +13 -0
  66. data/test/reports/TEST-HammerCLIForeman-Architecture-InfoCommand.xml +7 -0
  67. data/test/reports/TEST-HammerCLIForeman-Architecture-ListCommand-output.xml +13 -0
  68. data/test/reports/TEST-HammerCLIForeman-Architecture-ListCommand-parameters.xml +17 -0
  69. data/test/reports/TEST-HammerCLIForeman-Architecture-ListCommand.xml +7 -0
  70. data/test/reports/TEST-HammerCLIForeman-Architecture-UpdateCommand-parameters.xml +15 -0
  71. data/test/reports/TEST-HammerCLIForeman-Architecture-UpdateCommand.xml +7 -0
  72. data/test/reports/TEST-HammerCLIForeman-Architecture.xml +7 -0
  73. data/test/reports/TEST-HammerCLIForeman-CommonParameter-DeleteCommand-parameters.xml +11 -0
  74. data/test/reports/TEST-HammerCLIForeman-CommonParameter-DeleteCommand.xml +7 -0
  75. data/test/reports/TEST-HammerCLIForeman-CommonParameter-ListCommand-output.xml +13 -0
  76. data/test/reports/TEST-HammerCLIForeman-CommonParameter-ListCommand-parameters.xml +17 -0
  77. data/test/reports/TEST-HammerCLIForeman-CommonParameter-ListCommand.xml +7 -0
  78. data/test/reports/TEST-HammerCLIForeman-CommonParameter-SetCommand-parameters.xml +13 -0
  79. data/test/reports/TEST-HammerCLIForeman-CommonParameter-SetCommand.xml +7 -0
  80. data/test/reports/TEST-HammerCLIForeman-CommonParameter.xml +7 -0
  81. data/test/reports/TEST-HammerCLIForeman-ComputeResource-CreateCommand-parameters.xml +15 -0
  82. data/test/reports/TEST-HammerCLIForeman-ComputeResource-CreateCommand.xml +7 -0
  83. data/test/reports/TEST-HammerCLIForeman-ComputeResource-DeleteCommand-parameters.xml +13 -0
  84. data/test/reports/TEST-HammerCLIForeman-ComputeResource-DeleteCommand.xml +7 -0
  85. data/test/reports/TEST-HammerCLIForeman-ComputeResource-InfoCommand-output.xml +17 -0
  86. data/test/reports/TEST-HammerCLIForeman-ComputeResource-InfoCommand-parameters.xml +13 -0
  87. data/test/reports/TEST-HammerCLIForeman-ComputeResource-InfoCommand.xml +7 -0
  88. data/test/reports/TEST-HammerCLIForeman-ComputeResource-ListCommand-output.xml +15 -0
  89. data/test/reports/TEST-HammerCLIForeman-ComputeResource-ListCommand-parameters.xml +17 -0
  90. data/test/reports/TEST-HammerCLIForeman-ComputeResource-ListCommand.xml +7 -0
  91. data/test/reports/TEST-HammerCLIForeman-ComputeResource-UpdateCommand-parameters.xml +15 -0
  92. data/test/reports/TEST-HammerCLIForeman-ComputeResource-UpdateCommand.xml +7 -0
  93. data/test/reports/TEST-HammerCLIForeman-ComputeResource.xml +7 -0
  94. data/test/reports/TEST-HammerCLIForeman-Domain-CreateCommand-parameters.xml +11 -0
  95. data/test/reports/TEST-HammerCLIForeman-Domain-CreateCommand.xml +7 -0
  96. data/test/reports/TEST-HammerCLIForeman-Domain-DeleteCommand-parameters.xml +13 -0
  97. data/test/reports/TEST-HammerCLIForeman-Domain-DeleteCommand.xml +7 -0
  98. data/test/reports/TEST-HammerCLIForeman-Domain-DeleteParameterCommand-parameters.xml +15 -0
  99. data/test/reports/TEST-HammerCLIForeman-Domain-DeleteParameterCommand.xml +7 -0
  100. data/test/reports/TEST-HammerCLIForeman-Domain-InfoCommand-output.xml +21 -0
  101. data/test/reports/TEST-HammerCLIForeman-Domain-InfoCommand-parameters.xml +13 -0
  102. data/test/reports/TEST-HammerCLIForeman-Domain-InfoCommand.xml +7 -0
  103. data/test/reports/TEST-HammerCLIForeman-Domain-ListCommand-output.xml +13 -0
  104. data/test/reports/TEST-HammerCLIForeman-Domain-ListCommand-parameters.xml +17 -0
  105. data/test/reports/TEST-HammerCLIForeman-Domain-ListCommand.xml +7 -0
  106. data/test/reports/TEST-HammerCLIForeman-Domain-SetParameterCommand-parameters.xml +17 -0
  107. data/test/reports/TEST-HammerCLIForeman-Domain-SetParameterCommand.xml +7 -0
  108. data/test/reports/TEST-HammerCLIForeman-Domain-UpdateCommand-parameters.xml +15 -0
  109. data/test/reports/TEST-HammerCLIForeman-Domain-UpdateCommand.xml +7 -0
  110. data/test/reports/TEST-HammerCLIForeman-Domain.xml +7 -0
  111. data/test/reports/TEST-HammerCLIForeman-Environment-CreateCommand-parameters.xml +11 -0
  112. data/test/reports/TEST-HammerCLIForeman-Environment-CreateCommand.xml +7 -0
  113. data/test/reports/TEST-HammerCLIForeman-Environment-DeleteCommand-parameters.xml +13 -0
  114. data/test/reports/TEST-HammerCLIForeman-Environment-DeleteCommand.xml +7 -0
  115. data/test/reports/TEST-HammerCLIForeman-Environment-InfoCommand-output.xml +17 -0
  116. data/test/reports/TEST-HammerCLIForeman-Environment-InfoCommand-parameters.xml +13 -0
  117. data/test/reports/TEST-HammerCLIForeman-Environment-InfoCommand.xml +7 -0
  118. data/test/reports/TEST-HammerCLIForeman-Environment-ListCommand-output.xml +13 -0
  119. data/test/reports/TEST-HammerCLIForeman-Environment-ListCommand-parameters.xml +17 -0
  120. data/test/reports/TEST-HammerCLIForeman-Environment-ListCommand.xml +7 -0
  121. data/test/reports/TEST-HammerCLIForeman-Environment-UpdateCommand-parameters.xml +15 -0
  122. data/test/reports/TEST-HammerCLIForeman-Environment-UpdateCommand.xml +7 -0
  123. data/test/reports/TEST-HammerCLIForeman-Environment.xml +7 -0
  124. data/test/reports/TEST-HammerCLIForeman-ExceptionHandler.xml +13 -0
  125. data/test/reports/TEST-HammerCLIForeman-Host-CreateCommand-parameters.xml +46 -0
  126. data/test/reports/TEST-HammerCLIForeman-Host-CreateCommand.xml +7 -0
  127. data/test/reports/TEST-HammerCLIForeman-Host-DeleteCommand-parameters.xml +13 -0
  128. data/test/reports/TEST-HammerCLIForeman-Host-DeleteCommand.xml +7 -0
  129. data/test/reports/TEST-HammerCLIForeman-Host-DeleteParameterCommand-parameters.xml +15 -0
  130. data/test/reports/TEST-HammerCLIForeman-Host-DeleteParameterCommand.xml +7 -0
  131. data/test/reports/TEST-HammerCLIForeman-Host-InfoCommand-output.xml +85 -0
  132. data/test/reports/TEST-HammerCLIForeman-Host-InfoCommand-parameters.xml +13 -0
  133. data/test/reports/TEST-HammerCLIForeman-Host-InfoCommand.xml +7 -0
  134. data/test/reports/TEST-HammerCLIForeman-Host-ListCommand-output.xml +21 -0
  135. data/test/reports/TEST-HammerCLIForeman-Host-ListCommand-parameters.xml +17 -0
  136. data/test/reports/TEST-HammerCLIForeman-Host-ListCommand.xml +7 -0
  137. data/test/reports/TEST-HammerCLIForeman-Host-PuppetRunCommand-output.xml +9 -0
  138. data/test/reports/TEST-HammerCLIForeman-Host-PuppetRunCommand.xml +7 -0
  139. data/test/reports/TEST-HammerCLIForeman-Host-SetParameterCommand-parameters.xml +17 -0
  140. data/test/reports/TEST-HammerCLIForeman-Host-SetParameterCommand.xml +7 -0
  141. data/test/reports/TEST-HammerCLIForeman-Host-StatusCommand-output.xml +9 -0
  142. data/test/reports/TEST-HammerCLIForeman-Host-StatusCommand.xml +7 -0
  143. data/test/reports/TEST-HammerCLIForeman-Host-UpdateCommand-parameters.xml +40 -0
  144. data/test/reports/TEST-HammerCLIForeman-Host-UpdateCommand.xml +7 -0
  145. data/test/reports/TEST-HammerCLIForeman-Host.xml +7 -0
  146. data/test/reports/TEST-HammerCLIForeman-Hostgroup-CreateCommand-parameters.xml +11 -0
  147. data/test/reports/TEST-HammerCLIForeman-Hostgroup-CreateCommand.xml +7 -0
  148. data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteCommand-parameters.xml +11 -0
  149. data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteCommand.xml +7 -0
  150. data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteParameterCommand-parameters.xml +13 -0
  151. data/test/reports/TEST-HammerCLIForeman-Hostgroup-DeleteParameterCommand.xml +7 -0
  152. data/test/reports/TEST-HammerCLIForeman-Hostgroup-InfoCommand-output.xml +29 -0
  153. data/test/reports/TEST-HammerCLIForeman-Hostgroup-InfoCommand-parameters.xml +11 -0
  154. data/test/reports/TEST-HammerCLIForeman-Hostgroup-InfoCommand.xml +7 -0
  155. data/test/reports/TEST-HammerCLIForeman-Hostgroup-ListCommand-output.xml +27 -0
  156. data/test/reports/TEST-HammerCLIForeman-Hostgroup-ListCommand-parameters.xml +17 -0
  157. data/test/reports/TEST-HammerCLIForeman-Hostgroup-ListCommand.xml +7 -0
  158. data/test/reports/TEST-HammerCLIForeman-Hostgroup-SetParameterCommand-parameters.xml +15 -0
  159. data/test/reports/TEST-HammerCLIForeman-Hostgroup-SetParameterCommand.xml +7 -0
  160. data/test/reports/TEST-HammerCLIForeman-Hostgroup-UpdateCommand-parameters.xml +13 -0
  161. data/test/reports/TEST-HammerCLIForeman-Hostgroup-UpdateCommand.xml +7 -0
  162. data/test/reports/TEST-HammerCLIForeman-Hostgroup.xml +7 -0
  163. data/test/reports/TEST-HammerCLIForeman-Location-CreateCommand-parameters.xml +11 -0
  164. data/test/reports/TEST-HammerCLIForeman-Location-CreateCommand-resource-disabled.xml +11 -0
  165. data/test/reports/TEST-HammerCLIForeman-Location-CreateCommand.xml +7 -0
  166. data/test/reports/TEST-HammerCLIForeman-Location-DeleteCommand-parameters.xml +13 -0
  167. data/test/reports/TEST-HammerCLIForeman-Location-DeleteCommand-resource-disabled.xml +11 -0
  168. data/test/reports/TEST-HammerCLIForeman-Location-DeleteCommand.xml +7 -0
  169. data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand-output.xml +17 -0
  170. data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand-parameters.xml +13 -0
  171. data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand-resource-disabled.xml +11 -0
  172. data/test/reports/TEST-HammerCLIForeman-Location-InfoCommand.xml +7 -0
  173. data/test/reports/TEST-HammerCLIForeman-Location-ListCommand-output.xml +13 -0
  174. data/test/reports/TEST-HammerCLIForeman-Location-ListCommand-parameters.xml +17 -0
  175. data/test/reports/TEST-HammerCLIForeman-Location-ListCommand-resource-disabled.xml +11 -0
  176. data/test/reports/TEST-HammerCLIForeman-Location-ListCommand.xml +7 -0
  177. data/test/reports/TEST-HammerCLIForeman-Location-UpdateCommand-parameters.xml +15 -0
  178. data/test/reports/TEST-HammerCLIForeman-Location-UpdateCommand-resource-disabled.xml +11 -0
  179. data/test/reports/TEST-HammerCLIForeman-Location-UpdateCommand.xml +7 -0
  180. data/test/reports/TEST-HammerCLIForeman-Location.xml +7 -0
  181. data/test/reports/TEST-HammerCLIForeman-Medium-CreateCommand-parameters.xml +13 -0
  182. data/test/reports/TEST-HammerCLIForeman-Medium-CreateCommand.xml +7 -0
  183. data/test/reports/TEST-HammerCLIForeman-Medium-DeleteCommand-parameters.xml +13 -0
  184. data/test/reports/TEST-HammerCLIForeman-Medium-DeleteCommand.xml +7 -0
  185. data/test/reports/TEST-HammerCLIForeman-Medium-InfoCommand-output.xml +23 -0
  186. data/test/reports/TEST-HammerCLIForeman-Medium-InfoCommand-parameters.xml +13 -0
  187. data/test/reports/TEST-HammerCLIForeman-Medium-InfoCommand.xml +7 -0
  188. data/test/reports/TEST-HammerCLIForeman-Medium-ListCommand-output.xml +15 -0
  189. data/test/reports/TEST-HammerCLIForeman-Medium-ListCommand-parameters.xml +17 -0
  190. data/test/reports/TEST-HammerCLIForeman-Medium-ListCommand.xml +7 -0
  191. data/test/reports/TEST-HammerCLIForeman-Medium-UpdateCommand-parameters.xml +17 -0
  192. data/test/reports/TEST-HammerCLIForeman-Medium-UpdateCommand.xml +7 -0
  193. data/test/reports/TEST-HammerCLIForeman-Medium.xml +7 -0
  194. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-CreateCommand-parameters.xml +11 -0
  195. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-CreateCommand.xml +7 -0
  196. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteCommand-parameters.xml +13 -0
  197. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteCommand.xml +7 -0
  198. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteParameterCommand-parameters.xml +13 -0
  199. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-DeleteParameterCommand.xml +7 -0
  200. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-InfoCommand-output.xml +27 -0
  201. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-InfoCommand-parameters.xml +13 -0
  202. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-InfoCommand.xml +7 -0
  203. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-ListCommand-output.xml +17 -0
  204. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-ListCommand-parameters.xml +17 -0
  205. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-ListCommand.xml +7 -0
  206. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-SetParameterCommand-parameters.xml +15 -0
  207. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-SetParameterCommand.xml +7 -0
  208. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-UpdateCommand-parameters.xml +17 -0
  209. data/test/reports/TEST-HammerCLIForeman-OperatingSystem-UpdateCommand.xml +7 -0
  210. data/test/reports/TEST-HammerCLIForeman-OperatingSystem.xml +7 -0
  211. data/test/reports/TEST-HammerCLIForeman-Organization-CreateCommand-parameters.xml +11 -0
  212. data/test/reports/TEST-HammerCLIForeman-Organization-CreateCommand-resource-disabled.xml +11 -0
  213. data/test/reports/TEST-HammerCLIForeman-Organization-CreateCommand.xml +7 -0
  214. data/test/reports/TEST-HammerCLIForeman-Organization-DeleteCommand-parameters.xml +13 -0
  215. data/test/reports/TEST-HammerCLIForeman-Organization-DeleteCommand-resource-disabled.xml +11 -0
  216. data/test/reports/TEST-HammerCLIForeman-Organization-DeleteCommand.xml +7 -0
  217. data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand-output.xml +17 -0
  218. data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand-parameters.xml +13 -0
  219. data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand-resource-disabled.xml +11 -0
  220. data/test/reports/TEST-HammerCLIForeman-Organization-InfoCommand.xml +7 -0
  221. data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand-output.xml +13 -0
  222. data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand-parameters.xml +17 -0
  223. data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand-resource-disabled.xml +11 -0
  224. data/test/reports/TEST-HammerCLIForeman-Organization-ListCommand.xml +7 -0
  225. data/test/reports/TEST-HammerCLIForeman-Organization-UpdateCommand-parameters.xml +15 -0
  226. data/test/reports/TEST-HammerCLIForeman-Organization-UpdateCommand-resource-disabled.xml +11 -0
  227. data/test/reports/TEST-HammerCLIForeman-Organization-UpdateCommand.xml +7 -0
  228. data/test/reports/TEST-HammerCLIForeman-Organization.xml +7 -0
  229. data/test/reports/TEST-HammerCLIForeman-PartitionTable-CreateCommand-parameters.xml +13 -0
  230. data/test/reports/TEST-HammerCLIForeman-PartitionTable-CreateCommand.xml +7 -0
  231. data/test/reports/TEST-HammerCLIForeman-PartitionTable-DeleteCommand-parameters.xml +13 -0
  232. data/test/reports/TEST-HammerCLIForeman-PartitionTable-DeleteCommand.xml +7 -0
  233. data/test/reports/TEST-HammerCLIForeman-PartitionTable-DumpCommand-parameters.xml +15 -0
  234. data/test/reports/TEST-HammerCLIForeman-PartitionTable-DumpCommand.xml +7 -0
  235. data/test/reports/TEST-HammerCLIForeman-PartitionTable-InfoCommand-output.xml +19 -0
  236. data/test/reports/TEST-HammerCLIForeman-PartitionTable-InfoCommand-parameters.xml +13 -0
  237. data/test/reports/TEST-HammerCLIForeman-PartitionTable-InfoCommand.xml +7 -0
  238. data/test/reports/TEST-HammerCLIForeman-PartitionTable-ListCommand-output.xml +15 -0
  239. data/test/reports/TEST-HammerCLIForeman-PartitionTable-ListCommand-parameters.xml +17 -0
  240. data/test/reports/TEST-HammerCLIForeman-PartitionTable-ListCommand.xml +7 -0
  241. data/test/reports/TEST-HammerCLIForeman-PartitionTable-UpdateCommand-parameters.xml +13 -0
  242. data/test/reports/TEST-HammerCLIForeman-PartitionTable-UpdateCommand.xml +7 -0
  243. data/test/reports/TEST-HammerCLIForeman-PartitionTable.xml +7 -0
  244. data/test/reports/TEST-HammerCLIForeman-SmartProxy-CreateCommand-parameters.xml +13 -0
  245. data/test/reports/TEST-HammerCLIForeman-SmartProxy-CreateCommand.xml +7 -0
  246. data/test/reports/TEST-HammerCLIForeman-SmartProxy-DeleteCommand-parameters.xml +13 -0
  247. data/test/reports/TEST-HammerCLIForeman-SmartProxy-DeleteCommand.xml +7 -0
  248. data/test/reports/TEST-HammerCLIForeman-SmartProxy-InfoCommand-output.xml +21 -0
  249. data/test/reports/TEST-HammerCLIForeman-SmartProxy-InfoCommand-parameters.xml +13 -0
  250. data/test/reports/TEST-HammerCLIForeman-SmartProxy-InfoCommand.xml +7 -0
  251. data/test/reports/TEST-HammerCLIForeman-SmartProxy-ListCommand-output.xml +15 -0
  252. data/test/reports/TEST-HammerCLIForeman-SmartProxy-ListCommand-parameters.xml +11 -0
  253. data/test/reports/TEST-HammerCLIForeman-SmartProxy-ListCommand.xml +7 -0
  254. data/test/reports/TEST-HammerCLIForeman-SmartProxy-UpdateCommand-parameters.xml +15 -0
  255. data/test/reports/TEST-HammerCLIForeman-SmartProxy-UpdateCommand.xml +7 -0
  256. data/test/reports/TEST-HammerCLIForeman-SmartProxy.xml +7 -0
  257. data/test/reports/TEST-HammerCLIForeman-Subnet-CreateCommand-parameters.xml +15 -0
  258. data/test/reports/TEST-HammerCLIForeman-Subnet-CreateCommand.xml +7 -0
  259. data/test/reports/TEST-HammerCLIForeman-Subnet-DeleteCommand-parameters.xml +13 -0
  260. data/test/reports/TEST-HammerCLIForeman-Subnet-DeleteCommand.xml +7 -0
  261. data/test/reports/TEST-HammerCLIForeman-Subnet-InfoCommand-output.xml +43 -0
  262. data/test/reports/TEST-HammerCLIForeman-Subnet-InfoCommand-parameters.xml +13 -0
  263. data/test/reports/TEST-HammerCLIForeman-Subnet-InfoCommand.xml +7 -0
  264. data/test/reports/TEST-HammerCLIForeman-Subnet-ListCommand-output.xml +17 -0
  265. data/test/reports/TEST-HammerCLIForeman-Subnet-ListCommand-parameters.xml +17 -0
  266. data/test/reports/TEST-HammerCLIForeman-Subnet-ListCommand.xml +7 -0
  267. data/test/reports/TEST-HammerCLIForeman-Subnet-UpdateCommand-parameters.xml +15 -0
  268. data/test/reports/TEST-HammerCLIForeman-Subnet-UpdateCommand.xml +7 -0
  269. data/test/reports/TEST-HammerCLIForeman-Subnet.xml +7 -0
  270. data/test/reports/TEST-HammerCLIForeman-Template-CreateCommand-parameters.xml +15 -0
  271. data/test/reports/TEST-HammerCLIForeman-Template-CreateCommand.xml +7 -0
  272. data/test/reports/TEST-HammerCLIForeman-Template-DeleteCommand-parameters.xml +11 -0
  273. data/test/reports/TEST-HammerCLIForeman-Template-DeleteCommand.xml +7 -0
  274. data/test/reports/TEST-HammerCLIForeman-Template-DumpCommand-parameters.xml +12 -0
  275. data/test/reports/TEST-HammerCLIForeman-Template-DumpCommand.xml +7 -0
  276. data/test/reports/TEST-HammerCLIForeman-Template-InfoCommand-output.xml +17 -0
  277. data/test/reports/TEST-HammerCLIForeman-Template-InfoCommand-parameters.xml +11 -0
  278. data/test/reports/TEST-HammerCLIForeman-Template-InfoCommand.xml +7 -0
  279. data/test/reports/TEST-HammerCLIForeman-Template-ListCommand-output.xml +15 -0
  280. data/test/reports/TEST-HammerCLIForeman-Template-ListCommand-parameters.xml +17 -0
  281. data/test/reports/TEST-HammerCLIForeman-Template-ListCommand.xml +7 -0
  282. data/test/reports/TEST-HammerCLIForeman-Template-ListKindsCommand-parameters.xml +9 -0
  283. data/test/reports/TEST-HammerCLIForeman-Template-ListKindsCommand.xml +7 -0
  284. data/test/reports/TEST-HammerCLIForeman-Template-UpdateCommand-parameters.xml +11 -0
  285. data/test/reports/TEST-HammerCLIForeman-Template-UpdateCommand.xml +7 -0
  286. data/test/reports/TEST-HammerCLIForeman-Template.xml +7 -0
  287. data/test/reports/TEST-HammerCLIForeman-User-CreateCommand-parameters.xml +19 -0
  288. data/test/reports/TEST-HammerCLIForeman-User-CreateCommand.xml +7 -0
  289. data/test/reports/TEST-HammerCLIForeman-User-DeleteCommand-parameters.xml +11 -0
  290. data/test/reports/TEST-HammerCLIForeman-User-DeleteCommand.xml +7 -0
  291. data/test/reports/TEST-HammerCLIForeman-User-InfoCommand-output.xml +23 -0
  292. data/test/reports/TEST-HammerCLIForeman-User-InfoCommand-parameters.xml +11 -0
  293. data/test/reports/TEST-HammerCLIForeman-User-InfoCommand.xml +7 -0
  294. data/test/reports/TEST-HammerCLIForeman-User-ListCommand-output.xml +17 -0
  295. data/test/reports/TEST-HammerCLIForeman-User-ListCommand-parameters.xml +17 -0
  296. data/test/reports/TEST-HammerCLIForeman-User-ListCommand.xml +7 -0
  297. data/test/reports/TEST-HammerCLIForeman-User-UpdateCommand-parameters.xml +11 -0
  298. data/test/reports/TEST-HammerCLIForeman-User-UpdateCommand.xml +7 -0
  299. data/test/reports/TEST-HammerCLIForeman-User.xml +7 -0
  300. data/test/reports/TEST-MiniTest-Spec.xml +7 -0
  301. data/test/test_helper.rb +1 -1
  302. data/test/unit/api/interactive_basic_auth_test.rb +1 -1
  303. data/test/unit/api/oauth/oauth_authentication_code_grant_test.rb +88 -0
  304. data/test/unit/api/oauth/oauth_password_grant_test.rb +92 -0
  305. data/test/unit/api/session_authenticator_wrapper_test.rb +85 -70
  306. data/test/unit/sessions_test.rb +199 -0
  307. metadata +600 -81
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0cdf6461be3ef29ad406ca4e0b5df67a71d1696bdc30cc27a27fb5fcfe32b40
4
- data.tar.gz: 5e1effc59d2f218e0fc3ff07284f50b8d31aac6a31e444491e280c4840d00a08
3
+ metadata.gz: 39c04732f825e9e11d775e76b74b527ddb1db099cd29770530f2f7df1274a484
4
+ data.tar.gz: bbadb602bf0eb3836db5aaa90aad41b0d1f38be39749c2d7292398181d668dbc
5
5
  SHA512:
6
- metadata.gz: b6763b4f96743429ca23bf0ab687d725eeeeed0982c2c7eda4452d0454d96d87cae0b62449fcd0163391faaf77084319fa3741ba1f2567e495c60dad1671fd72
7
- data.tar.gz: '095b4445ef69d9aedc2174af90c191edb2b6cc58c50f3095f8e61af04d6858a1edd34cc5a1f0bbd04d32da6f4571dd060fd8de2220da3f5540252267c370f881'
6
+ metadata.gz: 567f870185f45995e3dd4341321ecea98ab099a7b387a63457ded17b6752d2cd0f27c3eb2fdf7649058762855f4583839ec73b5e9140f4c993f971ee230ae2e1
7
+ data.tar.gz: aeb5cea9ec9175f27045b57cfc43575fde5a559061dbcf243f048aa60401e734900746a1939c565adb503b562287bc47b15ea821813933fa98ab6284dc4b71fc
data/config/foreman.yml CHANGED
@@ -6,9 +6,29 @@
6
6
  :host: 'https://localhost/'
7
7
 
8
8
  # Credentials. You'll be asked for them interactively if you leave them blank here
9
+ # Possible values:
10
+
11
+ # Basic Auth:
12
+ #:default_auth_type: 'Basic_Auth'
9
13
  :username: 'admin'
10
14
  #:password: 'example'
11
15
 
16
+ # Oauth using the Password Grant Flow:
17
+ # This authentication method requires sessions to be enabled, uncomment the following
18
+ # lines to use this authentication method.
19
+ #:default_auth_type: 'Oauth_Password_Grant'
20
+ #:oidc_token_endpoint: https://keycloak.example.com/token
21
+ #:oidc_client_id: example-client-id
22
+
23
+ # Oauth using Authentication Code Flow(Two Factor):
24
+ # This authentication method requires sessions to be enabled, uncomment the following
25
+ # lines to use this authentication method.
26
+ #:default_auth_type: 'Oauth_Authentication_Code_Grant'
27
+ #:oidc_token_endpoint: https://keycloak.example.com/token
28
+ #:oidc_authorization_endpoint: https://keycloak.example.com/auth
29
+ #:oidc_client_id: example-client-id
30
+ #:oidc_redirect_uri: urn:ietf:wg:oauth:2.0:oob
31
+
12
32
  # Enable using sessions
13
33
  # When sessions are enabled, hammer ignores credentials stored in the config file
14
34
  # and asks for them interactively at the begining of each session.
data/doc/host_create.md CHANGED
@@ -175,17 +175,16 @@ Provider specific options
175
175
  Available keys for `--compute-attributes`:
176
176
  ```
177
177
  flavor_id # select one of available flavours
178
- image_id # select one of available images
179
178
  availability_zone
180
179
  security_group_ids
181
180
  managed_ip
181
+ groups
182
182
  ```
183
183
 
184
184
  ## GCE
185
185
  Available keys for `--compute-attributes`:
186
186
  ```
187
187
  machine_type # one of available flavors
188
- image_id
189
188
  network
190
189
  associate_external_ip
191
190
  ```
@@ -195,6 +194,7 @@ Available keys for `--compute-attributes`:
195
194
  ```
196
195
  cpus # number of CPUs
197
196
  memory # string, amount of memory, value in bytes
197
+ cpu_mode # possible values: default, host-model, host-passthrough
198
198
  start # Must be a 1 or 0, whether to start the machine or not
199
199
  ```
200
200
 
@@ -208,13 +208,16 @@ compute_model # one of [virtio, rtl8139, ne2k_pci, pcnet, e1
208
208
  Available keys for `--volume`:
209
209
  ```
210
210
  pool_name # list of available storage pools
211
- capacity # string value, eg. 10G
211
+ capacity # string value, e.g. 10G
212
212
  format_type # one of [raw, qcow2]
213
+ allocation # initial allocation, e.g. 0G
213
214
  ```
214
215
 
215
216
  ## OpenStack
216
217
  Available keys for `--compute-attributes`:
217
218
  ```
219
+ availability_zone
220
+ boot_from_volume
218
221
  flavor_ref
219
222
  image_ref
220
223
  tenant_id
@@ -228,6 +231,7 @@ Available keys for `--compute-attributes`:
228
231
  cluster
229
232
  template # hardware profile to use
230
233
  cores # int value, number of cores
234
+ sockets # int value, number of sockets
231
235
  memory # amount of memory, int value in bytes
232
236
  start # Must be a 1 or 0, whether to start the machine or not
233
237
  ```
@@ -236,20 +240,22 @@ Available keys for `--interface`:
236
240
  ```
237
241
  compute_name # eg. eth0
238
242
  compute_network # select one of available networks for a cluster
243
+ compute_interface # interface type
239
244
  ```
240
245
 
241
246
  Available keys for `--volume`:
242
247
  ```
243
- size_gb # volume size in GB, integer value
244
- storage_domain # select one of available storage domains
245
- bootable # boolean, only one volume can be bootable
248
+ size_gb # volume size in GB, integer value
249
+ storage_domain # select one of available storage domains
250
+ bootable # boolean, only one volume can be bootable
251
+ preallocate # boolean, set true to preallocate
252
+ wipe_after_delete # boolean, set true to wipe disk after delete
246
253
  ```
247
254
 
248
255
  ## Rackspace
249
256
  Available keys for `--compute-attributes`:
250
257
  ```
251
258
  flavor_id
252
- image_id
253
259
  ```
254
260
 
255
261
  ## VMware
@@ -263,13 +269,15 @@ cluster Cluster ID from VMware
263
269
  resource_pool Resource Pool ID from VMware
264
270
  path Path to folder
265
271
  guest_id Guest OS ID form VMware
266
- scsi_controller_type ID of the controller from VMware
267
272
  hardware_version Hardware version ID from VMware
268
273
  add_cdrom Must be a 1 or 0, Add a CD-ROM drive to the virtual machine
269
274
  cpuHotAddEnabled Must be a 1 or 0, lets you add memory resources while the machine is on
270
- memoryHotAddEnabled Must be a 1 or 0, lets you add CPU resources while the machine is on
271
- start Must be a 1 or 0, whether to start the machine or not
275
+ memoryHotAddEnabled Must be a 1 or 0, lets you add CPU resources while the machine is on the machine or not
272
276
  annotation Annotation Notes
277
+ scsi_controllers List with SCSI controllers definitions
278
+ type - ID of the controller from VMware
279
+ key - Key of the controller (e.g. 1000)
280
+ start # Must be a 1 or 0, whether to start the machine or not
273
281
  ```
274
282
 
275
283
  Available keys for `--interface`:
@@ -292,4 +300,5 @@ size_gb Integer number, volume size in GB
292
300
  thin true/false
293
301
  eager_zero true/false
294
302
  mode persistent/independent_persistent/independent_nonpersistent
303
+ controller_key Associated SCSI controller key
295
304
  ```
data/doc/release_notes.md CHANGED
@@ -1,10 +1,18 @@
1
1
  Release notes
2
2
  =============
3
- ### 0.18.2 (2019-11-18)
4
- * Fix method typo ([PR #450](https://github.com/theforeman/hammer-cli-foreman/pull/450)), [#27868](http://projects.theforeman.org/issues/27868)
5
-
6
- ### 0.18.1 (2019-10-31)
3
+ ### 0.19.0 (2019-10-26)
7
4
  * Add option to support host's param type ([PR #448](https://github.com/theforeman/hammer-cli-foreman/pull/448)), [#27868](http://projects.theforeman.org/issues/27868)
5
+ * Adding sso func. through cli using openid-connect ([PR #405](https://github.com/theforeman/hammer-cli-foreman/pull/405)), [#25848](http://projects.theforeman.org/issues/25848)
6
+ * Ping command ([PR #394](https://github.com/theforeman/hammer-cli-foreman/pull/394)), [#3036](http://projects.theforeman.org/issues/3036), [#12587](http://projects.theforeman.org/issues/12587), [#3956](http://projects.theforeman.org/issues/3956)
7
+ * Add description field to templates ([PR #449](https://github.com/theforeman/hammer-cli-foreman/pull/449)), [#27997](http://projects.theforeman.org/issues/27997)
8
+ * New lines in text attr dont break output ([PR #415](https://github.com/theforeman/hammer-cli-foreman/pull/415)), [#25878](http://projects.theforeman.org/issues/25878)
9
+ * Fixed inconsistent in output format, [#27597](http://projects.theforeman.org/issues/27597)
10
+ * Added gateway to subnet list, [#27596](http://projects.theforeman.org/issues/27596)
11
+ * Improve help for compute resources, [#25584](http://projects.theforeman.org/issues/25584)
12
+ * Fix interfaces when creating a host ([PR #439](https://github.com/theforeman/hammer-cli-foreman/pull/439)), [#27652](http://projects.theforeman.org/issues/27652)
13
+ * Additional compute resource attrs for ovirt ([PR #440](https://github.com/theforeman/hammer-cli-foreman/pull/440)), [#27554](http://projects.theforeman.org/issues/27554)
14
+ * Change the search fields to search / order fields, [#27602](http://projects.theforeman.org/issues/27602)
15
+ * Update docs for scl ruby to include bundle exec
8
16
 
9
17
  ### 0.18.0 (2019-08-01)
10
18
  * Report template schedule works with --name ([#27339](http://projects.theforeman.org/issues/27339))
@@ -0,0 +1,81 @@
1
+ module HammerCLIForeman
2
+ module Api
3
+ class Authenticator
4
+ attr_accessor :auth_type, :uri, :settings
5
+ def initialize(auth_type, uri, settings)
6
+ @auth_type = auth_type
7
+ @uri = uri
8
+ @settings = settings
9
+ end
10
+
11
+ def fetch
12
+ if ssl_cert_authentication? && !use_basic_auth?
13
+ void_auth
14
+ elsif auth_type == AUTH_TYPES[:basic_auth]
15
+ basic_auth
16
+ elsif auth_type == AUTH_TYPES[:oauth_password_grant]
17
+ oauth_password_grant
18
+ elsif auth_type == AUTH_TYPES[:oauth_authentication_code_grant]
19
+ oauth_authentication_code_grant
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def void_auth
26
+ VoidAuth.new(_('Using certificate authentication.'))
27
+ end
28
+
29
+ def basic_auth
30
+ if HammerCLIForeman::Sessions.enabled?
31
+ authenticator = InteractiveBasicAuth.new(
32
+ settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'],
33
+ settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD']
34
+ )
35
+ SessionAuthenticatorWrapper.new(authenticator, uri, auth_type)
36
+ else
37
+ username = settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'] || settings.get(:foreman, :username)
38
+ password = settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD']
39
+ if password.nil? && (username == settings.get(:foreman, :username))
40
+ password = settings.get(:foreman, :password)
41
+ end
42
+ InteractiveBasicAuth.new(username, password)
43
+ end
44
+ end
45
+
46
+ def oauth_password_grant
47
+ return unless HammerCLIForeman::Sessions.enabled?
48
+
49
+ authenticator = Oauth::PasswordGrant.new(
50
+ ENV['OIDC_TOKEN_ENDPOINT'] || settings.get(:foreman, :oidc_token_endpoint),
51
+ ENV['OIDC_CLIENT_ID'] || settings.get(:foreman, :oidc_client_id),
52
+ ENV['OIDC_USERNAME'],
53
+ ENV['OIDC_PASSWORD']
54
+ )
55
+ SessionAuthenticatorWrapper.new(authenticator, uri, auth_type)
56
+ end
57
+
58
+ def oauth_authentication_code_grant
59
+ return unless HammerCLIForeman::Sessions.enabled?
60
+
61
+ authenticator = Oauth::AuthenticationCodeGrant.new(
62
+ ENV['OIDC_TOKEN_ENDPOINT'] || settings.get(:foreman, :oidc_token_endpoint),
63
+ ENV['OIDC_AUTHORIZATION_URL'] || settings.get(:foreman, :oidc_authorization_endpoint),
64
+ ENV['OIDC_CLIENT_ID'] || settings.get(:foreman, :oidc_client_id),
65
+ ENV['OIDC_REDIRECT_URI'] || settings.get(:foreman, :oidc_redirect_uri)
66
+ )
67
+ SessionAuthenticatorWrapper.new(authenticator, uri, auth_type)
68
+ end
69
+
70
+ def ssl_cert_authentication?
71
+ (settings.get(:_params, :ssl_client_cert) || settings.get(:ssl, :ssl_client_cert)) &&
72
+ (settings.get(:_params, :ssl_client_key) || settings.get(:ssl, :ssl_client_key))
73
+ end
74
+
75
+ def use_basic_auth?
76
+ settings.get(:_params, :ssl_with_basic_auth) ||
77
+ settings.get(:ssl, :ssl_with_basic_auth)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,14 +1,26 @@
1
1
  require 'hammer_cli_foreman/api/session_authenticator_wrapper'
2
+ require 'hammer_cli_foreman/api/authenticator'
2
3
  require 'hammer_cli_foreman/api/interactive_basic_auth'
4
+ require 'hammer_cli_foreman/api/oauth/authentication_code_grant'
5
+ require 'hammer_cli_foreman/api/oauth/password_grant'
3
6
  require 'hammer_cli_foreman/api/void_auth'
7
+ require 'uri'
4
8
 
5
9
  module HammerCLIForeman
10
+ CONNECTION_NAME = 'foreman'
11
+ AUTH_TYPES = {
12
+ basic_auth: 'Basic_Auth',
13
+ oauth_authentication_code_grant: 'Oauth_Authentication_Code_Grant',
14
+ oauth_password_grant: 'Oauth_Password_Grant'
15
+ }.freeze
16
+
6
17
  module Api
7
18
  class Connection < HammerCLI::Apipie::ApiConnection
8
19
  attr_reader :authenticator
9
20
 
10
- def initialize(settings, logger = nil, locale = nil)
11
- default_params = build_default_params(settings, logger, locale)
21
+ def initialize(settings, logger = nil, locale = nil, auth_type = nil)
22
+ auth_type ||= default_auth_type(settings)
23
+ default_params = build_default_params(settings, logger, locale, auth_type)
12
24
  super(default_params,
13
25
  :logger => logger,
14
26
  :reload_cache => settings.get(:_params, :reload_cache) || settings.get(:reload_cache)
@@ -16,7 +28,7 @@ module HammerCLIForeman
16
28
  end
17
29
 
18
30
  def login
19
- # Call some api entry point to trigger the
31
+ # Call some api entry point to trigger the successful connection
20
32
  @api.resource(:home).action(:status).call
21
33
  end
22
34
 
@@ -30,40 +42,35 @@ module HammerCLIForeman
30
42
 
31
43
  protected
32
44
 
33
- def create_authenticator(uri, settings)
34
- return @authenticator if @authenticator
45
+ # If the settings in foreman.yml has use_sessions as false, use :basic_auth
46
+ # Else if the settings in foreman.yml has use_sessions as true
47
+ # and if there exists a session_file with valid contents, we use the auth_type from sessions_file
48
+ # Thus if the session expires (indicated by nil session_id), we use the
49
+ # same auth_type for re-authentication as was used by the previous session.
50
+ # Else we use the passed auth_type.
51
+ def default_auth_type(settings)
52
+ return AUTH_TYPES[:basic_auth] unless HammerCLIForeman::Sessions.enabled?
35
53
 
36
- if ssl_cert_authentication?(settings) && !use_basic_auth?(settings)
37
- @authenticator = VoidAuth.new(_('Using certificate authentication.'))
54
+ url = settings.get(:_params, :host) || settings.get(:foreman, :host)
55
+ username = settings.get(:_params, :username) || settings.get(:foreman, :username)
56
+ session = HammerCLIForeman::Sessions.get(url)
57
+ if !session.valid? && session.user_name == username && !session.auth_type.nil?
58
+ session.auth_type
38
59
  else
39
- if settings.get(:foreman, :use_sessions)
40
- @authenticator = InteractiveBasicAuth.new(
41
- settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'],
42
- settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD']
43
- )
44
- @authenticator = SessionAuthenticatorWrapper.new(@authenticator, uri)
45
- else
46
- username = settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'] || settings.get(:foreman, :username)
47
- password = settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD']
48
- if (password.nil? && (username == settings.get(:foreman, :username)))
49
- password = settings.get(:foreman, :password)
50
- end
51
- @authenticator = InteractiveBasicAuth.new(username, password)
52
- end
53
- @authenticator
60
+ # If the caller has not sepcified an 'auth_type'
61
+ # and the 'default_auth_type' in settings is also undefined
62
+ # use :basic_auth for authentication.
63
+ HammerCLI::Settings.get(:foreman, :default_auth_type) || AUTH_TYPES[:basic_auth]
54
64
  end
55
65
  end
56
66
 
57
- def ssl_cert_authentication?(settings)
58
- (settings.get(:_params, :ssl_client_cert) || settings.get(:ssl, :ssl_client_cert)) &&
59
- (settings.get(:_params, :ssl_client_key) || settings.get(:ssl, :ssl_client_key))
60
- end
67
+ def create_authenticator(uri, settings, auth_type)
68
+ return @authenticator if @authenticator
61
69
 
62
- def use_basic_auth?(settings)
63
- settings.get(:_params, :ssl_with_basic_auth) || settings.get(:ssl, :ssl_with_basic_auth)
70
+ @authenticator = HammerCLIForeman::Api::Authenticator.new(auth_type, uri, settings).fetch
64
71
  end
65
72
 
66
- def build_default_params(settings, logger, locale)
73
+ def build_default_params(settings, logger, locale, auth_type)
67
74
  config = {}
68
75
  config[:uri] = settings.get(:_params, :host) || settings.get(:foreman, :host)
69
76
  config[:logger] = logger unless logger.nil?
@@ -77,22 +84,30 @@ module HammerCLIForeman
77
84
  config[:timeout] = settings.get(:foreman, :request_timeout)
78
85
  config[:timeout] = -1 if (config[:timeout] && config[:timeout].to_i < 0)
79
86
  config[:apidoc_authenticated] = false
80
- config[:authenticator] = create_authenticator(config[:uri], settings)
87
+ config[:authenticator] = create_authenticator(config[:uri], settings, auth_type)
81
88
  config
82
89
  end
83
90
  end
84
91
  end
85
92
 
86
- CONNECTION_NAME = 'foreman'
87
-
88
93
  def self.foreman_api_connection
89
94
  HammerCLI.context[:api_connection].create(CONNECTION_NAME) do
90
95
  HammerCLIForeman::Api::Connection.new(HammerCLI::Settings, Logging.logger['API'], HammerCLI::I18n.locale)
91
96
  end
92
97
  end
93
98
 
99
+ def self.foreman_api_reconnect(auth_type)
100
+ HammerCLI.context[:api_connection].drop(CONNECTION_NAME)
101
+ HammerCLI.context[:api_connection].create(CONNECTION_NAME) do
102
+ HammerCLIForeman::Api::Connection.new(
103
+ HammerCLI::Settings,
104
+ Logging.logger['API'],
105
+ HammerCLI::I18n.locale,
106
+ auth_type)
107
+ end
108
+ end
109
+
94
110
  def self.init_api_connection
95
111
  foreman_api_connection
96
112
  end
97
113
  end
98
-
@@ -12,12 +12,12 @@ module HammerCLIForeman
12
12
  def error(ex)
13
13
  if ex.is_a?(RestClient::Unauthorized)
14
14
  self.clear
15
- message = _("Invalid username or password.")
15
+ message = _('Invalid username or password.')
16
16
  begin
17
17
  message = JSON.parse(ex.response.body)['error']['message']
18
18
  rescue
19
19
  end
20
- return UnauthorizedError.new(message)
20
+ UnauthorizedError.new(message)
21
21
  end
22
22
  end
23
23
 
@@ -0,0 +1,100 @@
1
+ require 'jwt'
2
+ require 'hammer_cli_foreman/openid_connect'
3
+
4
+ module HammerCLIForeman
5
+ module Api
6
+ module Oauth
7
+ class AuthenticationCodeGrant < ApipieBindings::Authenticators::TokenAuth
8
+ attr_accessor :oidc_token_endpoint, :oidc_authorization_endpoint, :oidc_client_id, :token, :oidc_redirect_uri
9
+
10
+ def initialize(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri)
11
+ @oidc_token_endpoint = oidc_token_endpoint
12
+ @oidc_authorization_endpoint = oidc_authorization_endpoint
13
+ @oidc_client_id = oidc_client_id
14
+ @oidc_redirect_uri = oidc_redirect_uri
15
+ super set_token(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri)
16
+ end
17
+
18
+ def authenticate(request, token)
19
+ if HammerCLI.interactive?
20
+ set_token_interactively
21
+ end
22
+ super
23
+ end
24
+
25
+ def set_token_interactively
26
+ @token ||= set_token(get_oidc_token_endpoint, get_oidc_authorization_endpoint, get_oidc_client_id, get_oidc_redirect_uri)
27
+ end
28
+
29
+ def set_token(input_oidc_token_endpoint, input_oidc_authorization_endpoint, input_oidc_client_id, input_oidc_redirect_uri)
30
+ @oidc_token_endpoint = input_oidc_token_endpoint if input_oidc_token_endpoint
31
+ @oidc_authorization_endpoint = input_oidc_authorization_endpoint if input_oidc_authorization_endpoint
32
+ @oidc_client_id = input_oidc_client_id if input_oidc_client_id
33
+ @oidc_redirect_uri = input_oidc_redirect_uri if input_oidc_redirect_uri
34
+
35
+ if @oidc_client_id && @oidc_authorization_endpoint && @oidc_redirect_uri && @oidc_token_endpoint
36
+ get_code
37
+ @token = HammerCLIForeman::OpenidConnect.new(
38
+ @oidc_token_endpoint, @oidc_client_id).get_token_via_2fa(@code, @oidc_redirect_uri)
39
+ else
40
+ @token = nil
41
+ end
42
+ end
43
+
44
+ def user
45
+ return nil unless @token
46
+ payload = JWT.decode(@token, nil, false)
47
+ payload.first["preferred_username"]
48
+ end
49
+
50
+ def error(ex)
51
+ if ex.is_a?(RestClient::InternalServerError)
52
+ @oidc_token_endpoint = @oidc_authorization_endpoint = @oidc_client_id = @oidc_client_id = nil
53
+ original_message = _("Invalid oidc-client-id or oidc-token-endpoint or oidc-authorization-endpoint.\n")
54
+ begin
55
+ message = JSON.parse(ex.response.body)['error']['message']
56
+ rescue
57
+ end
58
+ UnauthorizedError.new(original_message << message)
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def get_code
65
+ @token_url = "#{@oidc_authorization_endpoint}?"\
66
+ 'response_type=code'\
67
+ "&client_id=#{@oidc_client_id}"\
68
+ "&redirect_uri=#{@oidc_redirect_uri}"\
69
+ '&scope=openid'
70
+ HammerCLI.interactive_output.say("Enter URL in browser: #{@token_url}")
71
+ @code ||= ask_user(_("Code:%s") % " ")
72
+ end
73
+
74
+ def get_oidc_authorization_endpoint
75
+ @oidc_authorization_endpoint ||= ask_user(_("Openidc Provider Authorization Endpoint:%s") % " ")
76
+ end
77
+
78
+ def get_oidc_token_endpoint
79
+ @oidc_token_endpoint ||= ask_user(_("Openidc Provider Token Endpoint:%s") % " ")
80
+ end
81
+
82
+ def get_oidc_client_id
83
+ @oidc_client_id ||= ask_user(_("Client ID:%s") % " ")
84
+ end
85
+
86
+ def get_oidc_redirect_uri
87
+ @oidc_redirect_uri ||= ask_user(_("Redirect URI:%s") % " ")
88
+ end
89
+
90
+ def ask_user(prompt, silent=false)
91
+ if silent
92
+ HammerCLI.interactive_output.ask(prompt) { |q| q.echo = false }
93
+ else
94
+ HammerCLI.interactive_output.ask(prompt)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,81 @@
1
+ require 'hammer_cli_foreman/openid_connect'
2
+
3
+ module HammerCLIForeman
4
+ module Api
5
+ module Oauth
6
+ class PasswordGrant < ApipieBindings::Authenticators::TokenAuth
7
+ attr_accessor :oidc_token_endpoint, :oidc_client_id, :user, :password, :token
8
+
9
+ def initialize(oidc_token_endpoint, oidc_client_id, user, password)
10
+ @oidc_token_endpoint = oidc_token_endpoint
11
+ @oidc_client_id = oidc_client_id
12
+ @user = user
13
+ @password = password
14
+ super set_token(oidc_token_endpoint, oidc_client_id, user, password)
15
+ end
16
+
17
+ def authenticate(request, token)
18
+ if HammerCLI.interactive?
19
+ set_token_interactively
20
+ end
21
+ super
22
+ end
23
+
24
+ def set_token_interactively
25
+ @token ||= set_token(get_oidc_token_endpoint, get_oidc_client_id, get_user, get_password)
26
+ end
27
+
28
+ def set_token(input_oidc_token_endpoint, input_oidc_client_id, input_user, input_password)
29
+ @oidc_token_endpoint = input_oidc_token_endpoint if input_oidc_token_endpoint
30
+ @user = input_user
31
+ @password = input_password
32
+ @oidc_client_id = input_oidc_client_id if input_oidc_client_id
33
+ if @user && @password && @oidc_token_endpoint && @oidc_client_id
34
+ @token = HammerCLIForeman::OpenidConnect.new(
35
+ @oidc_token_endpoint, @oidc_client_id).get_token(@user, @password)
36
+ else
37
+ @token = nil
38
+ end
39
+ end
40
+
41
+ def error(ex)
42
+ if ex.is_a?(RestClient::InternalServerError)
43
+ @user = @password = @oidc_token_endpoint = @oidc_client_id = nil
44
+ original_message = _("Invalid credentials or oidc-client-id or oidc-token-endpoint.\n")
45
+ begin
46
+ message = JSON.parse(ex.response.body)['error']['message']
47
+ rescue
48
+ end
49
+ UnauthorizedError.new(original_message << message)
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def get_user
56
+ @user ||= ask_user(_("Username:%s") % " ")
57
+ end
58
+
59
+ def get_password
60
+ @password ||= ask_user(_("Password:%{wsp}") % {:wsp => " "}, true)
61
+ end
62
+
63
+ def get_oidc_token_endpoint
64
+ @oidc_token_endpoint ||= ask_user(_("Openidc Provider Token Endpoint:%s") % " ")
65
+ end
66
+
67
+ def get_oidc_client_id
68
+ @oidc_client_id ||= ask_user(_("Client ID:%s") % " ")
69
+ end
70
+
71
+ def ask_user(prompt, silent=false)
72
+ if silent
73
+ HammerCLI.interactive_output.ask(prompt) { |q| q.echo = false }
74
+ else
75
+ HammerCLI.interactive_output.ask(prompt)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end