hammer_cli_foreman 2.0.1 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/doc/developer_docs.md +1 -0
  3. data/doc/plugin.md +22 -0
  4. data/doc/release_notes.md +35 -2
  5. data/lib/hammer_cli_foreman.rb +9 -1
  6. data/lib/hammer_cli_foreman/api/connection.rb +1 -18
  7. data/lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb +7 -4
  8. data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +0 -1
  9. data/lib/hammer_cli_foreman/associating_commands.rb +33 -5
  10. data/lib/hammer_cli_foreman/audit.rb +7 -0
  11. data/lib/hammer_cli_foreman/auth.rb +10 -10
  12. data/lib/hammer_cli_foreman/bookmark.rb +50 -0
  13. data/lib/hammer_cli_foreman/command_extensions.rb +2 -0
  14. data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +13 -7
  15. data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +13 -7
  16. data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -0
  17. data/lib/hammer_cli_foreman/command_extensions/user.rb +17 -0
  18. data/lib/hammer_cli_foreman/commands.rb +14 -9
  19. data/lib/hammer_cli_foreman/compute_resource.rb +15 -0
  20. data/lib/hammer_cli_foreman/compute_resource/ec2.rb +11 -0
  21. data/lib/hammer_cli_foreman/compute_resource/gce.rb +9 -0
  22. data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +11 -0
  23. data/lib/hammer_cli_foreman/compute_resource/openstack.rb +7 -0
  24. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +21 -9
  25. data/lib/hammer_cli_foreman/compute_resource/vmware.rb +15 -2
  26. data/lib/hammer_cli_foreman/hostgroup.rb +11 -19
  27. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +32 -10
  28. data/lib/hammer_cli_foreman/id_resolver.rb +12 -11
  29. data/lib/hammer_cli_foreman/mail_notification.rb +31 -0
  30. data/lib/hammer_cli_foreman/operating_system.rb +1 -1
  31. data/lib/hammer_cli_foreman/option_builders.rb +70 -48
  32. data/lib/hammer_cli_foreman/option_sources.rb +1 -0
  33. data/lib/hammer_cli_foreman/option_sources/referenced_resource_id_params.rb +47 -0
  34. data/lib/hammer_cli_foreman/sessions.rb +1 -3
  35. data/lib/hammer_cli_foreman/subnet.rb +26 -15
  36. data/lib/hammer_cli_foreman/task_helper.rb +180 -0
  37. data/lib/hammer_cli_foreman/user.rb +7 -17
  38. data/lib/hammer_cli_foreman/user_mail_notification.rb +51 -0
  39. data/lib/hammer_cli_foreman/version.rb +1 -1
  40. data/lib/hammer_cli_foreman/virtual_machine.rb +55 -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/2.1/foreman_api.json +1 -0
  55. data/test/functional/associating_commands_test.rb +134 -30
  56. data/test/functional/bookmark_test.rb +193 -0
  57. data/test/functional/host_test.rb +27 -1
  58. data/test/functional/http_proxy_test.rb +1 -4
  59. data/test/functional/mail_notification_test.rb +57 -0
  60. data/test/functional/subnet/create_test.rb +28 -5
  61. data/test/functional/template_test.rb +2 -2
  62. data/test/functional/user_mail_notification_test.rb +89 -0
  63. data/test/functional/virtual_machine_test.rb +129 -0
  64. data/test/test_helper.rb +1 -1
  65. data/test/unit/audit_test.rb +1 -0
  66. data/test/unit/sessions_test.rb +2 -13
  67. metadata +59 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e4300f1b8ab9e071be65dc562712932ef44499e28e01f11502f65a0aa22db4b
4
- data.tar.gz: 4b3fac38f6ddbd89edf22c8acf1527b0de4c96108ebec0abe5b40ced20c9e4f2
3
+ metadata.gz: 67582a7a91083bfc42e83382188653feb0f869c311eb99d0471562c2e528c0d4
4
+ data.tar.gz: aaecc05bc2d6100a135f02fad79d76f89da7ba3520f87ba90566382165abc97b
5
5
  SHA512:
6
- metadata.gz: abd5212ed633e2bd27569245799acfa43bea0c15e5db1d5d9708a32df3e329459234922f460a78e945db37f73b423ac3746fa374a333f7252c7ed8ebfea51c18
7
- data.tar.gz: 6e261fe585fde6b260d2fcd1ba6ef2a0035ea0683be542bad4ad4c2f1590d220631bec3670c840f8c2a1c9dba1160c265108913fcb21f103f0713080839b1134
6
+ metadata.gz: 95d9f3c0ad3bf6109f3b7b3abf6879c844db0b6d94991cea9a033400b86aad077b682893b6f1b92227f3470ba926cc6093ee9701d17d527a125c9c23c08597da
7
+ data.tar.gz: 0d27c46e8c93ca33c3e0c5228a8a9255dea918d5ca49c99bfeedb448394bbc5eac850a77913a8e6a4a161d9470c7946620dc5d6c8521c3607a23925c6f2861fb
@@ -10,6 +10,7 @@ Foreman plugin extends the Hammer Core in following areas:
10
10
  - [Building options](option_builder.md#option-builders)
11
11
  - [Automatic name resolution](name_id_resolution.md#name-to-id-resolution)
12
12
  - [Testing commands](testing.md#testing-hammer-commands)
13
+ - [Writing a plugin](plugin.md#writing-a-plugin)
13
14
 
14
15
  It's recommended that you set `:refresh_cache: true` in the plugin settings if
15
16
  engaging in API development to enable aggressive apidoc cache checking.
@@ -0,0 +1,22 @@
1
+ # Writing a plugin
2
+
3
+ ### Basic
4
+
5
+ If you want to create a plugin for hammer-cli-foreman, you might want to create
6
+ a simple draft at first.
7
+
8
+ To do so, just run the following:
9
+ ```
10
+ # You will need to checkout this repository first if you don't have it already
11
+ $ git checkout https://github.com/theforeman/hammer-cli-foreman.git
12
+ $ cd hammer-cli-foreman
13
+ $ rake plugin:draft
14
+ # fill prompts
15
+ ```
16
+ This will create a directory called `hammer-cli-foreman-prompted-name` with
17
+ basic structure where you can put your code afterwards. Please, don't forget to
18
+ take a look at `TODO`s as there might be places you want to change or adjust to
19
+ your needs first.
20
+
21
+ For more information, please see: https://github.com/theforeman/hammer-cli/blob/master/doc/developer_docs.md
22
+ as well as https://github.com/theforeman/hammer-cli-foreman/blob/master/doc/developer_docs.md
@@ -1,7 +1,40 @@
1
1
  Release notes
2
2
  =============
3
- ### 2.0.1 (2020-02-25)
4
- * Remove duplicate api requests on addassociatedcommand ([PR #503](https://github.com/theforeman/hammer-cli-foreman/pull/503)) ([PR #504](https://github.com/theforeman/hammer-cli-foreman/pull/504)), [#29096](http://projects.theforeman.org/issues/29096)
3
+ ### 2.1.3 (2020-09-04)
4
+ * Use underscores in `login oauth` option values ([PR #536](https://github.com/theforeman/hammer-cli-foreman/pull/536)) ([PR #538](https://github.com/theforeman/hammer-cli-foreman/pull/538)), [#30720](http://projects.theforeman.org/issues/30720)
5
+
6
+ ### 2.1.2 (2020-07-14)
7
+ * Change config templates to provisioning templates ([PR #531](https://github.com/theforeman/hammer-cli-foreman/pull/531)), [#29971](http://projects.theforeman.org/issues/29971)
8
+ * Return 'set current context for request' to help ([PR #530](https://github.com/theforeman/hammer-cli-foreman/pull/530)), [#30182](http://projects.theforeman.org/issues/30182)
9
+ * Display request uuid for audit ([PR #528](https://github.com/theforeman/hammer-cli-foreman/pull/528)) ([PR #529](https://github.com/theforeman/hammer-cli-foreman/pull/529)), [#30130](http://projects.theforeman.org/issues/30130)
10
+
11
+ ### 2.1.1 (2020-05-29)
12
+ * Revert "skip one test on ruby 2.7" ([PR #520](https://github.com/theforeman/hammer-cli-foreman/pull/520)), [#28601](http://projects.theforeman.org/issues/28601)
13
+ * Eliminate auth_type from sessions file ([PR #521](https://github.com/theforeman/hammer-cli-foreman/pull/521)), [#29876](http://projects.theforeman.org/issues/29876)
14
+ * Add disable option for user ([PR #497](https://github.com/theforeman/hammer-cli-foreman/pull/497)), [#28973](http://projects.theforeman.org/issues/28973)
15
+ * Added manage command to user mail notifications ([PR #513](https://github.com/theforeman/hammer-cli-foreman/pull/513)), [#7665](http://projects.theforeman.org/issues/7665)
16
+
17
+ ### 2.1.0 (2020-05-14)
18
+ * Bump hammer_cli to 2.1.0 ([PR #519](https://github.com/theforeman/hammer-cli-foreman/pull/519))
19
+ * Ask for oauth code only when needed ([PR #517](https://github.com/theforeman/hammer-cli-foreman/pull/517)), [#29635](http://projects.theforeman.org/issues/29635)
20
+ * Possibility to create ipv6 subnet, [#28760](http://projects.theforeman.org/issues/28760)
21
+ * Add the ability to manage bookmarks ([PR #510](https://github.com/theforeman/hammer-cli-foreman/pull/510)), [#12845](http://projects.theforeman.org/issues/12845)
22
+ * Add aliases for info/list/delete commands ([PR #512](https://github.com/theforeman/hammer-cli-foreman/pull/512)), [#29413](http://projects.theforeman.org/issues/29413)
23
+ * Help contains squeezed options ([PR #489](https://github.com/theforeman/hammer-cli-foreman/pull/489)), [#28440](http://projects.theforeman.org/issues/28440)
24
+ * Add cr to hostgroup info, [#29140](http://projects.theforeman.org/issues/29140)
25
+ * Add rake task with plugin template
26
+ * Added virtual machine command for compute resource ([PR #469](https://github.com/theforeman/hammer-cli-foreman/pull/469)), [#20451](http://projects.theforeman.org/issues/20451)
27
+ * Add display options to host creation on ovirt ([PR #507](https://github.com/theforeman/hammer-cli-foreman/pull/507)), [#29254](http://projects.theforeman.org/issues/29254)
28
+ * Add mail notification command ([PR #509](https://github.com/theforeman/hammer-cli-foreman/pull/509)), [#29326](http://projects.theforeman.org/issues/29326)
29
+ * Use right param for os default template ([PR #508](https://github.com/theforeman/hammer-cli-foreman/pull/508)), [#29274](http://projects.theforeman.org/issues/29274)
30
+ * Update api docs to 2.1
31
+ * Correct hot add options ([PR #505](https://github.com/theforeman/hammer-cli-foreman/pull/505)), [#29253](http://projects.theforeman.org/issues/29253)
32
+ * Feature #28836 - allow multiple disassociating of provisioning templates ([PR #502](https://github.com/theforeman/hammer-cli-foreman/pull/502)), [#28836](http://projects.theforeman.org/issues/28836)
33
+ * Fixed updating host owner when ownertype is usergroup ([PR #501](https://github.com/theforeman/hammer-cli-foreman/pull/501)), [#11279](http://projects.theforeman.org/issues/11279)
34
+ * Remove duplicate api requests on addassociatedcommand ([PR #503](https://github.com/theforeman/hammer-cli-foreman/pull/503)), [#29096](http://projects.theforeman.org/issues/29096)
35
+ * Fix help for ovirt boolean values, [#29026](http://projects.theforeman.org/issues/29026)
36
+ * Deprecate --root-pass in host group, [#22573](http://projects.theforeman.org/issues/22573)
37
+ * Bump to 2.1.0-develop
5
38
 
6
39
  ### 2.0.0 (2020-02-12)
7
40
  * Change the description of the scoped loc and org ([PR #494](https://github.com/theforeman/hammer-cli-foreman/pull/494)), [#28869](http://projects.theforeman.org/issues/28869)
@@ -11,6 +11,7 @@ module HammerCLIForeman
11
11
  require 'hammer_cli_foreman/i18n'
12
12
 
13
13
  require 'hammer_cli_foreman/version'
14
+ require 'hammer_cli_foreman/task_helper'
14
15
  require 'hammer_cli_foreman/output'
15
16
  require 'hammer_cli_foreman/output/fields'
16
17
  require 'hammer_cli_foreman/exception_handler'
@@ -153,7 +154,7 @@ module HammerCLIForeman
153
154
  'HammerCLIForeman::Subnet', 'hammer_cli_foreman/subnet'
154
155
  )
155
156
 
156
- HammerCLI::MainCommand.lazy_subcommand('template', _("Manipulate config templates"),
157
+ HammerCLI::MainCommand.lazy_subcommand('template', _("Manipulate provisioning templates"),
157
158
  'HammerCLIForeman::Template', 'hammer_cli_foreman/template'
158
159
  )
159
160
 
@@ -180,6 +181,13 @@ module HammerCLIForeman
180
181
  HammerCLI::MainCommand.lazy_subcommand('trend', _("Manage trends"),
181
182
  'HammerCLIForeman::Trend', 'hammer_cli_foreman/trend'
182
183
  )
184
+
185
+ HammerCLI::MainCommand.lazy_subcommand('mail-notification', _("Manage mail notifications"),
186
+ 'HammerCLIForeman::MailNotification', 'hammer_cli_foreman/mail_notification'
187
+ )
188
+
189
+ HammerCLI::MainCommand.lazy_subcommand('bookmark', _("Manage bookmarks"),
190
+ 'HammerCLIForeman::Bookmark', 'hammer_cli_foreman/bookmark')
183
191
  rescue => e
184
192
  handler = HammerCLIForeman::ExceptionHandler.new(:context => {}, :adapter => :base)
185
193
  handler.handle_exception(e)
@@ -42,26 +42,9 @@ module HammerCLIForeman
42
42
 
43
43
  protected
44
44
 
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
45
  def default_auth_type(settings)
52
46
  return AUTH_TYPES[:basic_auth] unless HammerCLIForeman::Sessions.enabled?
53
-
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
59
- else
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]
64
- end
47
+ HammerCLI::Settings.get(:foreman, :default_auth_type) || AUTH_TYPES[:basic_auth]
65
48
  end
66
49
 
67
50
  def create_authenticator(uri, settings, auth_type)
@@ -5,19 +5,22 @@ module HammerCLIForeman
5
5
  module Api
6
6
  module Oauth
7
7
  class AuthenticationCodeGrant < ApipieBindings::Authenticators::TokenAuth
8
- attr_accessor :oidc_token_endpoint, :oidc_authorization_endpoint, :oidc_client_id, :token, :oidc_redirect_uri
8
+ attr_accessor :oidc_token_endpoint, :oidc_authorization_endpoint,
9
+ :oidc_client_id, :token, :oidc_redirect_uri
9
10
 
10
11
  def initialize(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri)
11
12
  @oidc_token_endpoint = oidc_token_endpoint
12
13
  @oidc_authorization_endpoint = oidc_authorization_endpoint
13
14
  @oidc_client_id = oidc_client_id
14
15
  @oidc_redirect_uri = oidc_redirect_uri
15
- super set_token(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri)
16
+ super(nil)
16
17
  end
17
18
 
18
19
  def authenticate(request, token)
19
20
  if HammerCLI.interactive?
20
21
  set_token_interactively
22
+ else
23
+ set_token(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri)
21
24
  end
22
25
  super
23
26
  end
@@ -35,7 +38,7 @@ module HammerCLIForeman
35
38
  if @oidc_client_id.to_s.empty? || @oidc_authorization_endpoint.to_s.empty? || @oidc_redirect_uri.to_s.empty? || @oidc_token_endpoint.to_s.empty?
36
39
  @token = nil
37
40
  else
38
- get_code
41
+ @code ||= get_code
39
42
  @token = HammerCLIForeman::OpenidConnect.new(
40
43
  @oidc_token_endpoint, @oidc_client_id).get_token_via_2fa(@code, @oidc_redirect_uri)
41
44
  end
@@ -68,7 +71,7 @@ module HammerCLIForeman
68
71
  "&redirect_uri=#{@oidc_redirect_uri}"\
69
72
  '&scope=openid'
70
73
  HammerCLI.interactive_output.say("Enter URL in browser: #{@token_url}")
71
- @code ||= ask_user(_("Code:%s") % " ")
74
+ ask_user(_("Code:%s") % " ")
72
75
  end
73
76
 
74
77
  def get_oidc_authorization_endpoint
@@ -69,7 +69,6 @@ module HammerCLIForeman
69
69
  if (r.cookies['_session_id'] && r.code != 401)
70
70
  session.id = r.cookies['_session_id']
71
71
  session.user_name = @authenticator.user
72
- session.auth_type = @auth_type
73
72
  session.store
74
73
  end
75
74
  @authenticator.response(r)
@@ -245,6 +245,7 @@ module HammerCLIForeman
245
245
  def request_params
246
246
  params = super
247
247
 
248
+ template_ids = params['operatingsystem']['provisioning_template_ids']
248
249
  if options['option_provisioning_template_search']
249
250
  templates = HammerCLIForeman.collection_to_common_format(
250
251
  associated_resource.call(
@@ -255,10 +256,10 @@ module HammerCLIForeman
255
256
 
256
257
  templates.each do |template|
257
258
  template_id = template['id']
258
- params['operatingsystem']['provisioning_template_ids'] << template_id.to_s
259
+ template_ids << template_id.to_s
259
260
  end
260
261
  end
261
- params['operatingsystem']['provisioning_template_ids'] = params['operatingsystem']['provisioning_template_ids'].uniq
262
+ params['operatingsystem']['provisioning_template_ids'] = template_ids.uniq
262
263
  params
263
264
  end
264
265
 
@@ -269,10 +270,37 @@ module HammerCLIForeman
269
270
 
270
271
  class RemoveProvisioningTemplateCommand < HammerCLIForeman::RemoveAssociatedCommand
271
272
  associated_resource :provisioning_templates
272
- desc _("Disassociate a provisioning template")
273
+ desc _("Disassociate provisioning templates")
273
274
 
274
- success_message _("The provisioning template has been disassociated.")
275
- failure_message _("Could not disassociate the provisioning template")
275
+ option "--provisioning-template-ids", "PROVISIONING_TEMPLATE_IDS", _("List of provisioning template ids"),
276
+ format: HammerCLI::Options::Normalizers::List.new
277
+ option "--provisioning-templates", "PROVISIONING_TEMPLATE_NAMES", _("List of provisioning template names"),
278
+ format: HammerCLI::Options::Normalizers::List.new, attribute_name: :option_provisioning_template_names
279
+ option "--provisioning-template-search", "PROVISIONING_TEMPLATE_SEARCH", _("Provisioning template name regex to search, all matching templates will be disassociated")
280
+
281
+ def request_params
282
+ params = super
283
+
284
+ template_ids = params['operatingsystem']['provisioning_template_ids']
285
+ if options['option_provisioning_template_search']
286
+ templates = HammerCLIForeman.collection_to_common_format(
287
+ associated_resource.call(
288
+ :index,
289
+ :search => "name ~ \"#{options['option_provisioning_template_search']}\"")
290
+ )
291
+ raise ResolverError.new(_("%s not found.") % associated_resource.singular_name, associated_resource) if templates.empty?
292
+
293
+ templates.each do |template|
294
+ template_id = template['id']
295
+ template_ids.delete(template_id.to_s)
296
+ end
297
+ end
298
+ params['operatingsystem']['provisioning_template_ids'] = template_ids.uniq
299
+ params
300
+ end
301
+
302
+ success_message _("The provisioning templates were disassociated.")
303
+ failure_message _("Could not disassociate the provisioning templates")
276
304
  end
277
305
  end
278
306
 
@@ -28,6 +28,7 @@ module HammerCLIForeman
28
28
  field :action, _("Action")
29
29
  field :auditable_type, _("Audit type")
30
30
  field nil, _("Audit record"), Fields::SingleReference, :key => :auditable
31
+ field :request_uuid, _("Request UUID"), Fields::Field, sets: ['ALL']
31
32
  end
32
33
 
33
34
  build_options
@@ -63,6 +64,12 @@ module HammerCLIForeman
63
64
  end
64
65
  end
65
66
 
67
+ extend_output_definition do |definition|
68
+ definition.insert(:replace, :request_uuid) do
69
+ field :request_uuid, _("Request UUID"), Fields::Field, sets: ['ALL', 'DEFAULT']
70
+ end
71
+ end
72
+
66
73
  build_options
67
74
  end
68
75
 
@@ -36,26 +36,26 @@ module HammerCLIForeman
36
36
 
37
37
  option ["-u", "--username"], "USERNAME", _("Username to access the remote system")
38
38
  option ["-p", "--password"], "PASSWORD", _("Password to access the remote system")
39
- option ["-t", "--oidc-token-endpoint"], "OPENIDC-TOKEN-ENDPOINT", _("Openidc provider URL which issues access token")
40
- option ["-a", "--oidc-authorization-endpoint"], "OPENIDC-AUTHORIZATION-ENDPOINT", _("Openidc provider URL which issues authentication code (two factor only)")
41
- option ["-c", "--oidc-client-id"], "OPENIDC-CLIENT-ID", _("Client id used in the Openidc provider")
39
+ option ["-t", "--oidc-token-endpoint"], "OPENIDC_TOKEN_ENDPOINT", _("Openidc provider URL which issues access token")
40
+ option ["-a", "--oidc-authorization-endpoint"], "OPENIDC_AUTHORIZATION_ENDPOINT", _("Openidc provider URL which issues authentication code (two factor only)")
41
+ option ["-c", "--oidc-client-id"], "OPENIDC_CLIENT_ID", _("Client id used in the Openidc provider")
42
42
  option ["-f", "--two-factor"], :flag, _("Authenticate with two factor")
43
- option ["-r", "--oidc-redirect-uri"], "OPENIDC-REDIRECT-URI", _("Redirect URI for the authentication code grant flow")
43
+ option ["-r", "--oidc-redirect-uri"], "OPENIDC_REDIRECT_URI", _("Redirect URI for the authentication code grant flow")
44
44
 
45
45
  def execute
46
46
  if option_two_factor?
47
47
  Oauth.execute_with_params(
48
48
  AUTH_TYPES[:oauth_authentication_code_grant],
49
- option_oidc_token_endpoint,
50
- option_oidc_authorization_endpoint,
51
- option_oidc_client_id,
52
- option_oidc_redirect_uri
49
+ option_oidc_token_endpoint || HammerCLI::Settings.get(:foreman, :oidc_token_endpoint),
50
+ option_oidc_authorization_endpoint || HammerCLI::Settings.get(:foreman, :oidc_authorization_endpoint),
51
+ option_oidc_client_id || HammerCLI::Settings.get(:foreman, :oidc_client_id),
52
+ option_oidc_redirect_uri || HammerCLI::Settings.get(:foreman, :oidc_redirect_uri)
53
53
  )
54
54
  else
55
55
  Oauth.execute_with_params(
56
56
  AUTH_TYPES[:oauth_password_grant],
57
- option_oidc_token_endpoint,
58
- option_oidc_client_id,
57
+ option_oidc_token_endpoint || HammerCLI::Settings.get(:foreman, :oidc_token_endpoint),
58
+ option_oidc_client_id || HammerCLI::Settings.get(:foreman, :oidc_client_id),
59
59
  option_username || HammerCLI::Settings.get('_params', 'username'),
60
60
  option_password || HammerCLI::Settings.get('_params', 'password')
61
61
  )
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HammerCLIForeman
4
+ class Bookmark < HammerCLIForeman::Command
5
+ resource :bookmarks
6
+
7
+ class ListCommand < HammerCLIForeman::ListCommand
8
+ output do
9
+ field :id, _('Id')
10
+ field :name, _('Name')
11
+ field :controller, _('Controller')
12
+ field :query, _('Search Query')
13
+ field :public, _('Public')
14
+ field :owner_id, _('Owner Id')
15
+ field :owner_type, _('Owner Type')
16
+ end
17
+
18
+ build_options
19
+ end
20
+
21
+ class InfoCommand < HammerCLIForeman::InfoCommand
22
+ output ListCommand.output_definition
23
+
24
+ build_options
25
+ end
26
+
27
+ class CreateCommand < HammerCLIForeman::CreateCommand
28
+ success_message _('Bookmark %<name>s created.')
29
+ failure_message _('Failed to create %<name>s bookmark')
30
+
31
+ build_options
32
+ end
33
+
34
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
35
+ success_message _('Bookmark %<name>s updated successfully.')
36
+ failure_message _('Failed to update %<name>s bookmark')
37
+
38
+ build_options
39
+ end
40
+
41
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
42
+ success_message _('Bookmark deleted successfully.')
43
+ failure_message _('Failed to delete bookmark')
44
+
45
+ build_options
46
+ end
47
+
48
+ autoload_subcommands
49
+ end
50
+ end
@@ -5,3 +5,5 @@ require 'hammer_cli_foreman/command_extensions/option_sources'
5
5
  require 'hammer_cli_foreman/command_extensions/hosts'
6
6
  require 'hammer_cli_foreman/command_extensions/ping'
7
7
  require 'hammer_cli_foreman/command_extensions/status'
8
+ require 'hammer_cli_foreman/command_extensions/user'
9
+ require 'hammer_cli_foreman/command_extensions/subnet'
@@ -2,13 +2,19 @@ module HammerCLIForeman
2
2
  module CommandExtensions
3
3
  class PuppetEnvironment < HammerCLI::CommandExtensions
4
4
  # Remove when support of --environment options is ended.
5
- option '--environment', 'ENVIRONMENT_NAME', _('Environment name'),
6
- attribute_name: :option_environment_name,
7
- deprecated: { '--environment' => _('Use --puppet-environment instead') }
8
- option '--environment-id', 'ENVIRONMENT_ID', _(''),
9
- format: HammerCLI::Options::Normalizers::Number.new,
10
- attribute_name: :option_environment_id,
11
- deprecated: { '--environment-id' => _('Use --puppet-environment-id instead') }
5
+ option_family(
6
+ aliased_resource: 'environment',
7
+ description: _('Puppet environment'),
8
+ deprecation: _("Use %s instead") % '--puppet-environment[-id]',
9
+ deprecated: { '--environment' => _("Use %s instead") % '--puppet-environment[-id]',
10
+ '--environment-id' => _("Use %s instead") % '--puppet-environment[-id]'}
11
+ ) do
12
+ parent '--environment-id', 'ENVIRONMENT_ID', _(''),
13
+ format: HammerCLI::Options::Normalizers::Number.new,
14
+ attribute_name: :option_environment_id
15
+ child '--environment', 'ENVIRONMENT_NAME', _('Environment name'),
16
+ attribute_name: :option_environment_name
17
+ end
12
18
 
13
19
  option_sources do |sources, command|
14
20
  sources.find_by_name('IdResolution').insert_relative(
@@ -2,13 +2,19 @@ module HammerCLIForeman
2
2
  module CommandExtensions
3
3
  class PuppetEnvironments < HammerCLI::CommandExtensions
4
4
  # Remove when support of --environments options is ended.
5
- option '--environments', 'ENVIRONMENT_NAMES', _(''),
6
- attribute_name: :option_environment_names,
7
- deprecated: { '--environments' => _('Use --puppet-environments instead') }
8
- option '--environment-ids', 'ENVIRONMENT_IDS', _('Environment IDs'),
9
- format: HammerCLI::Options::Normalizers::List.new,
10
- attribute_name: :option_environment_ids,
11
- deprecated: { '--environment-ids' => _('Use --puppet-environment-ids instead') }
5
+ option_family(
6
+ aliased_resource: 'environment',
7
+ description: _('Puppet environments'),
8
+ deprecation: _("Use %s instead") % '--puppet-environment[s|-ids]',
9
+ deprecated: { '--environments' => _("Use %s instead") % '--puppet-environment[s|-ids]',
10
+ '--environment-ids' => _("Use %s instead") % '--puppet-environment[s|-ids]' }
11
+ ) do
12
+ parent '--environment-ids', 'ENVIRONMENT_IDS', _('Environment IDs'),
13
+ format: HammerCLI::Options::Normalizers::List.new,
14
+ attribute_name: :option_environment_ids
15
+ child '--environments', 'ENVIRONMENT_NAMES', _(''),
16
+ attribute_name: :option_environment_names
17
+ end
12
18
 
13
19
  option_sources do |sources, command|
14
20
  sources.find_by_name('IdResolution').insert_relative(
@@ -0,0 +1,25 @@
1
+ module HammerCLIForeman
2
+ module CommandExtensions
3
+ class Subnet < HammerCLI::CommandExtensions
4
+ option "--dns", "DNS_NAME", _("DNS Proxy to use within this subnet"),
5
+ attribute_name: :option_dns_name,
6
+ referenced_resource: :smart_proxy
7
+ option "--dhcp", "DHCP_NAME", _("DHCP Proxy to use within this subnet"),
8
+ attribute_name: :option_dhcp_name,
9
+ referenced_resource: :smart_proxy
10
+ option "--tftp", "TFTP_NAME", _("TFTP Proxy to use within this subnet"),
11
+ attribute_name: :option_tftp_name,
12
+ referenced_resource: :smart_proxy
13
+ option "--prefix", "PREFIX", _("Network prefix in CIDR notation (e.g. 64) for this subnet")
14
+
15
+ option_sources do |sources, command|
16
+ sources.find_by_name('IdResolution').insert_relative(
17
+ :after,
18
+ 'IdParams',
19
+ HammerCLIForeman::OptionSources::ReferencedResourceIdParams.new(command)
20
+ )
21
+ sources
22
+ end
23
+ end
24
+ end
25
+ end