hammer_cli_foreman 0.10.2 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/config/foreman.yml +4 -0
  3. data/doc/release_notes.md +21 -5
  4. data/lib/hammer_cli_foreman/api/connection.rb +14 -5
  5. data/lib/hammer_cli_foreman/api/interactive_basic_auth.rb +17 -5
  6. data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +27 -8
  7. data/lib/hammer_cli_foreman/auth.rb +14 -10
  8. data/lib/hammer_cli_foreman/auth_source_ldap.rb +38 -34
  9. data/lib/hammer_cli_foreman/compute_resource.rb +24 -0
  10. data/lib/hammer_cli_foreman/filter.rb +6 -2
  11. data/lib/hammer_cli_foreman/host.rb +2 -7
  12. data/lib/hammer_cli_foreman/hostgroup.rb +1 -0
  13. data/lib/hammer_cli_foreman/id_resolver.rb +27 -7
  14. data/lib/hammer_cli_foreman/location.rb +1 -0
  15. data/lib/hammer_cli_foreman/organization.rb +1 -0
  16. data/lib/hammer_cli_foreman/references.rb +10 -2
  17. data/lib/hammer_cli_foreman/smart_class_parameter.rb +10 -1
  18. data/lib/hammer_cli_foreman/smart_variable.rb +24 -16
  19. data/lib/hammer_cli_foreman/subnet.rb +33 -3
  20. data/lib/hammer_cli_foreman/template.rb +1 -1
  21. data/lib/hammer_cli_foreman/testing/api_expectations.rb +3 -1
  22. data/lib/hammer_cli_foreman/user.rb +37 -3
  23. data/lib/hammer_cli_foreman/version.rb +1 -1
  24. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  25. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  26. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  27. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  28. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  29. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  30. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  31. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  32. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  33. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  35. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/test/functional/filter_test.rb +146 -0
  38. data/test/functional/host_test.rb +12 -0
  39. data/test/functional/smart_variable_test.rb +4 -4
  40. data/test/functional/template_test.rb +20 -0
  41. data/test/functional/user_test.rb +13 -13
  42. data/test/unit/api/interactive_basic_auth_test.rb +18 -0
  43. data/test/unit/api/session_authenticator_wrapper_test.rb +72 -2
  44. data/test/unit/apipie_resource_mock.rb +3 -0
  45. data/test/unit/auth_source_ldap_test.rb +2 -3
  46. data/test/unit/commands_test.rb +1 -1
  47. data/test/unit/compute_resource_test.rb +24 -0
  48. data/test/unit/host_test.rb +1 -1
  49. data/test/unit/hostgroup_test.rb +1 -1
  50. data/test/unit/id_resolver_test.rb +59 -21
  51. data/test/unit/subnet_test.rb +1 -0
  52. data/test/unit/user_test.rb +7 -1
  53. metadata +35 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aca6597f50629e6d78d1c059677409a1bd28c0c5
4
- data.tar.gz: 52228db5fe22493aa3c0f2f2cd00e41ff0bf7f1c
3
+ metadata.gz: 5bbff81f4608f3747313bf8525acb14c1734db93
4
+ data.tar.gz: 9fe96408c5e413b1731c4196d1cb62c80895a20d
5
5
  SHA512:
6
- metadata.gz: d6cc4de6593ae729c30b614c1c8d239e8d009d55d5e3091cb89df8ad1522e9d5debaf16168da89502a4b38de1122630484a07900ce1041bbafd6251856efc33d
7
- data.tar.gz: 27a2c9cac09d0dd7513f060f06c3d560f803ee16f5bed12799a366cee5dc601c3de90a0080dfcdd0d9f5b60575198c2b961c797423d601d71bd870b186da2308
6
+ metadata.gz: 080d7ba7ce6424c9bf4ff975e3d3bf63336cb565d96455fa4e07e317cc447eb52b8c5ede99de581c5026f259fb9e7f9943acc6dec41651137e732ae654639067
7
+ data.tar.gz: 94cbec39dca93447a6105586a948f2c5708b8dad4563731d5203ec303c579fa9612003d993eadc186a0e248e8976dae2b11cecc32ad83356339185ecec92fc25
data/config/foreman.yml CHANGED
@@ -8,6 +8,10 @@
8
8
  # Credentials. You'll be asked for them interactively if you leave them blank here
9
9
  :username: 'admin'
10
10
  #:password: 'example'
11
+
12
+ # Enable using sessions
13
+ # When sessions are enabled, hammer ignores credentials stored in the config file
14
+ # and asks for them interactively at the begining of each session.
11
15
  :use_sessions: false
12
16
 
13
17
  # Check API documentation cache status on each request
data/doc/release_notes.md CHANGED
@@ -1,19 +1,35 @@
1
1
  Release notes
2
2
  =============
3
3
 
4
- ### 0.10.2 (2017-05-05)
4
+ ### 0.11.0 (2017-08-01)
5
+ * Adding a list normalizer to override-value-order ([#17135](http://projects.theforeman.org/issues/17135))
6
+ * Correctly reset taxonomies for overriding filters ([#20117](http://projects.theforeman.org/issues/20117))
7
+ * Sessions mutually exclusive with basic auth ([#20315](http://projects.theforeman.org/issues/20315))
8
+ * Disable auth login when sessions are off ([#19602](http://projects.theforeman.org/issues/19602))
9
+ * Add all_parameters to host info ([#20286](http://projects.theforeman.org/issues/20286))
10
+ * Fix Hammer-cli display groups base dn ([#20227](http://projects.theforeman.org/issues/20227))
11
+ * Fix Hammer-cli current user password update ([#18005](http://projects.theforeman.org/issues/18005))
12
+ * Don't send snippet flag when --type is undefined ([#20145](http://projects.theforeman.org/issues/20145))
13
+ * Fix merging .edit.po into .po files ([#17671](http://projects.theforeman.org/issues/17671))
14
+ * Enable taxonomy titles ([#19157](http://projects.theforeman.org/issues/19157))
5
15
  * Provide default exception handler ([#19470](http://projects.theforeman.org/issues/19470))
16
+ * Accept hostgroup title in host create ([#19048](http://projects.theforeman.org/issues/19048))
6
17
  * Retry command on session expiry ([#19431](http://projects.theforeman.org/issues/19431))
7
18
  * More detailed instructions on SSL verification fail ([#19390](http://projects.theforeman.org/issues/19390))
8
-
9
- ### 0.10.1 (2017-04-24)
19
+ * Add additional attributes on user list command ([#4396](http://projects.theforeman.org/issues/4396))
20
+ * Add description to hostgroup ([#19361](http://projects.theforeman.org/issues/19361))
10
21
  * Require apipie-bindings >= 0.2.0 ([#19362](http://projects.theforeman.org/issues/19362))
11
- * Require rest-client >= 1.8.0 ([PR #306](https://github.com/theforeman/hammer-cli-foreman/pull/306)) ([#19358](http://projects.theforeman.org/issues/19358))
12
- * Custom error for 401 unauthorized ([PR #305](https://github.com/theforeman/hammer-cli-foreman/pull/305)) ([#19362](http://projects.theforeman.org/issues/19362))
22
+ * Require rest-client >= 1.8.0 ([#19358](http://projects.theforeman.org/issues/19358))
23
+ * Rustom error for 401 unauthorized ([#19362](http://projects.theforeman.org/issues/19362))
24
+ * Correctly resolve empty arrays ([#18742](http://projects.theforeman.org/issues/18742))
13
25
  * Use Array for empty attributes ([#19312](http://projects.theforeman.org/issues/19312))
26
+ * Compute-resources has images subcommand ([#19156](http://projects.theforeman.org/issues/19156))
14
27
  * Prevent sending nil values in hostgroup update ([#14872](http://projects.theforeman.org/issues/14872))
15
28
  * Install server CA cert without root access ([#19083](http://projects.theforeman.org/issues/19083))
29
+ * Add description to subnet ([#19172](http://projects.theforeman.org/issues/19172))
30
+ * Replaces --subnet-parameters-attributes with parameter commands ([#18663](http://projects.theforeman.org/issues/18663))
16
31
  * Make session authenticator compatible with rest-client 1.8 ([#19159](http://projects.theforeman.org/issues/19159))
32
+ * Add vlan id field to subnet ([#19134](http://projects.theforeman.org/issues/19134))
17
33
 
18
34
  ### 0.10.0 (2017-03-28)
19
35
  * Adding --hidden-value option to parameters (#290) ([#18878](http://projects.theforeman.org/issues/18878))
@@ -36,11 +36,20 @@ module HammerCLIForeman
36
36
  if ssl_cert_authentication?(settings) && !use_basic_auth?(settings)
37
37
  @authenticator = VoidAuth.new
38
38
  else
39
- @authenticator = InteractiveBasicAuth.new(
40
- settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'] || settings.get(:foreman, :username),
41
- settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD'] || settings.get(:foreman, :password)
42
- )
43
- @authenticator = SessionAuthenticatorWrapper.new(@authenticator, uri) if settings.get(:foreman, :use_sessions)
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
44
53
  @authenticator
45
54
  end
46
55
  end
@@ -12,19 +12,31 @@ module HammerCLIForeman
12
12
  end
13
13
 
14
14
  def error(ex)
15
- return UnauthorizedError.new(_("Invalid username or password")) if ex.is_a?(RestClient::Unauthorized)
15
+ if ex.is_a?(RestClient::Unauthorized)
16
+ self.clear
17
+ return UnauthorizedError.new(_("Invalid username or password"))
18
+ end
16
19
  end
17
20
 
18
21
  def status
19
22
  unless @user.nil? || @password.nil?
20
- _("You are logged in as '%s'") % @user
23
+ _("Using configured credentials for user '%s'.") % @user
21
24
  else
22
- _("You are currently not logged in")
25
+ _("Credentials are not configured.")
23
26
  end
24
27
  end
25
28
 
26
- def user
27
- @user
29
+ def user(ask=nil)
30
+ @user ||= ask && get_user
31
+ end
32
+
33
+ def set_credentials(user, password)
34
+ @user = user
35
+ @password = password
36
+ end
37
+
38
+ def clear
39
+ set_credentials(nil, nil)
28
40
  end
29
41
 
30
42
  private
@@ -18,23 +18,33 @@ module HammerCLIForeman
18
18
 
19
19
  def clear
20
20
  destroy_session
21
+ @authenticator.clear if @authenticator.respond_to?(:clear)
21
22
  end
22
23
 
23
24
  def status
24
25
  if load_session
25
- _("Session exist, currently logged in as '%s'") % @user
26
+ _("Session exists, currently logged in as '%s'") % @user
26
27
  else
27
- _("You are currently not logged in")
28
+ _("Using sessions, you are currently not logged in.")
28
29
  end
29
30
  end
30
31
 
32
+ def force_user_change
33
+ @user_changed = true
34
+ end
35
+
36
+ def user_changed?
37
+ !!@user_changed
38
+ end
39
+
31
40
  def authenticate(request, args)
32
41
  load_session
33
42
 
34
43
  user = @authenticator.user
35
- destroy_session if (user && user != @user)
36
44
 
37
- if @permissions_ok && @session_id
45
+ @user_changed ||= (!user.nil? && user != @user)
46
+
47
+ if !@user_changed && @permissions_ok && @session_id
38
48
  jar = HTTP::CookieJar.new
39
49
  jar.add(HTTP::Cookie.new('_session_id', @session_id, domain: uri.hostname.downcase, path: '/', for_domain: true))
40
50
  request['Cookie'] = HTTP::Cookie.cookie_value(jar.cookies)
@@ -47,8 +57,12 @@ module HammerCLIForeman
47
57
  def error(ex)
48
58
  load_session
49
59
  if ex.is_a?(RestClient::Unauthorized) && !@session_id.nil?
50
- destroy_session
51
- return SessionExpired.new(_("Session has expired"))
60
+ if @user_changed
61
+ return UnauthorizedError.new(_("Invalid username or password, continuing with session for '%s'") % @user)
62
+ else
63
+ destroy_session
64
+ return SessionExpired.new(_("Session has expired"))
65
+ end
52
66
  else
53
67
  return @authenticator.error(ex)
54
68
  end
@@ -62,8 +76,12 @@ module HammerCLIForeman
62
76
  @authenticator.response(r)
63
77
  end
64
78
 
65
- def user
66
- @authenticator.user if @authenticator.respond_to?(:user)
79
+ def user(ask=nil)
80
+ @authenticator.user(ask) if @authenticator.respond_to?(:user)
81
+ end
82
+
83
+ def set_credentials(*args)
84
+ @authenticator.set_credentials(*args) if @authenticator.respond_to?(:set_credentials)
67
85
  end
68
86
 
69
87
  protected
@@ -83,6 +101,7 @@ module HammerCLIForeman
83
101
  @session_id = session_data['session_id']
84
102
  end
85
103
  rescue JSON::ParserError
104
+ destroy_session
86
105
  warn _('Invalid session file format')
87
106
  nil
88
107
  end
@@ -10,16 +10,21 @@ module HammerCLIForeman
10
10
  option ["-p", "--password"], "PASSWORD", _("password to access the remote system")
11
11
 
12
12
  def execute
13
- HammerCLIForeman.foreman_api_connection.logout
14
- context[:api_connection].drop_all
15
- HammerCLI::Settings.load({
16
- :_params => {
17
- :username => option_username,
18
- :password => option_password
19
- }
20
- })
13
+ if !(HammerCLIForeman.foreman_api_connection.authenticator.is_a?(HammerCLIForeman::Api::SessionAuthenticatorWrapper))
14
+ print_message(_("Can't perform login. Make sure sessions are enabled in hammer configuration file."))
15
+ return HammerCLI::EX_USAGE
16
+ end
17
+
18
+ # Make sure we reflect also credentials set for the main hammer command
19
+ # ( hammer -u test auth login )
20
+ HammerCLIForeman.foreman_api_connection.authenticator.set_credentials(
21
+ option_username || HammerCLI::Settings.get('_params', 'username'),
22
+ option_password || HammerCLI::Settings.get('_params', 'password')
23
+ )
24
+ HammerCLIForeman.foreman_api_connection.authenticator.force_user_change
21
25
  HammerCLIForeman.foreman_api_connection.login
22
- print_message(_("Successfully logged in."))
26
+
27
+ print_message(_("Successfully logged in as '%s'.") % HammerCLIForeman.foreman_api_connection.authenticator.user)
23
28
  HammerCLI::EX_OK
24
29
  end
25
30
  end
@@ -30,7 +35,6 @@ module HammerCLIForeman
30
35
 
31
36
  def execute
32
37
  HammerCLIForeman.foreman_api_connection.logout
33
- context[:api_connection].drop_all
34
38
  print_message(_("Logged out."))
35
39
  HammerCLI::EX_OK
36
40
  end
@@ -1,70 +1,74 @@
1
1
  module HammerCLIForeman
2
-
3
2
  class AuthSourceLdap < HammerCLIForeman::Command
4
-
5
3
  resource :auth_source_ldaps
6
4
  command_name 'ldap'
7
- desc _("Manage LDAP auth sources.")
8
-
5
+ desc _('Manage LDAP auth sources.')
9
6
 
10
7
  class ListCommand < HammerCLIForeman::ListCommand
11
-
12
8
  output do
13
- field :id , _("Id")
14
- field :name , _("Name")
15
- field :tls , _('LDAPS?')
16
- field :port , _('Port')
17
- field :type , _("Server Type")
9
+ field :id, _('Id')
10
+ field :name, _('Name')
11
+ field :host, _('Server')
12
+ field :port, _('Port')
13
+ field :tls, _('LDAPS?'), Fields::Boolean
18
14
  end
19
15
 
20
16
  build_options
21
17
  end
22
18
 
23
-
24
19
  class InfoCommand < HammerCLIForeman::InfoCommand
25
-
26
- output ListCommand.output_definition do
27
- field :account , _('Account Username')
28
- field :base_dn , _('Base DN')
29
- field :ldap_filter , _('LDAP filter')
30
- field :onthefly_register , _('Automatically Create Accounts?')
31
- field :attr_login , _('Login Name Attribute')
32
- field :attr_firstname , _('First Name Attribute')
33
- field :attr_lastname , _('Last Name Attribute')
34
- field :attr_mail , _('Email Address Attribute')
35
- field :attr_photo , _('Photo Attribute')
20
+ output do
21
+ label _('Server') do
22
+ field :id, _('Id')
23
+ field :name, _('Name')
24
+ field :host, _('Server')
25
+ field :tls, _('LDAPS'), Fields::Boolean
26
+ field :port, _('Port')
27
+ field :server_type, _('Server Type')
28
+ end
29
+ label _('Account') do
30
+ field :account, _('Account Username')
31
+ field :base_dn, _('Base DN')
32
+ field :groups_base, _('Groups base DN')
33
+ field :use_netgroups, _('Use Netgroups'), Fields::Boolean
34
+ field :ldap_filter, _('LDAP filter')
35
+ field :onthefly_register, _('Automatically Create Accounts?'), Fields::Boolean
36
+ field :usergroup_sync, _('Usergroup sync'), Fields::Boolean
37
+ end
38
+ label _('Attribute mappings') do
39
+ field :attr_login, _('Login Name Attribute')
40
+ field :attr_firstname, _('First Name Attribute')
41
+ field :attr_lastname, _('Last Name Attribute')
42
+ field :attr_mail, _('Email Address Attribute')
43
+ field :attr_photo, _('Photo Attribute')
44
+ end
45
+ HammerCLIForeman::References.taxonomies(self)
36
46
  end
37
47
 
38
48
  build_options
39
49
  end
40
50
 
41
-
42
51
  class CreateCommand < HammerCLIForeman::CreateCommand
43
- success_message _("Auth source created")
44
- failure_message _("Could not create the Auth Source")
52
+ success_message _('Auth source [%{name}] created')
53
+ failure_message _('Could not create the Auth Source')
45
54
 
46
55
  build_options
47
56
  end
48
57
 
49
-
50
58
  class DeleteCommand < HammerCLIForeman::DeleteCommand
51
- success_message _("Auth source deleted")
52
- failure_message _("Could not delete the Auth Source")
59
+ success_message _('Auth source [%{name}] deleted')
60
+ failure_message _('Could not delete the Auth Source')
53
61
 
54
62
  build_options
55
63
  end
56
64
 
57
-
58
65
  class UpdateCommand < HammerCLIForeman::UpdateCommand
59
- success_message _("Auth source updated")
60
- failure_message _("Could not update the Auth Source")
66
+ success_message _('Auth source [%{name}] updated')
67
+ failure_message _('Could not update the Auth Source')
61
68
 
62
69
  build_options
63
70
  end
64
71
 
65
72
  autoload_subcommands
66
73
  end
67
-
68
74
  end
69
-
70
-
@@ -96,6 +96,30 @@ module HammerCLIForeman
96
96
  build_options
97
97
  end
98
98
 
99
+ class AvailableNetworksCommand < HammerCLIForeman::ListCommand
100
+
101
+ resource :compute_resources, :available_networks
102
+ command_name 'networks'
103
+ desc _("Show available networks")
104
+
105
+ build_options
106
+
107
+ validate_options do
108
+ any(:option_id, :option_name).required
109
+ end
110
+
111
+ def request_params
112
+ params = super
113
+ params['id'] ||= get_identifier
114
+ params
115
+ end
116
+
117
+ output do
118
+ field :name, _("Name")
119
+ field :id, _("Id")
120
+ end
121
+
122
+ end
99
123
 
100
124
  autoload_subcommands
101
125
  subcommand 'image', HammerCLIForeman::Image.desc, HammerCLIForeman::Image
@@ -93,7 +93,7 @@ module HammerCLIForeman
93
93
 
94
94
  def request_params
95
95
  params = super
96
- if override?
96
+ if !override?
97
97
  # Clear taxonomies in case the filter is switching override from true to false
98
98
  params['filter']['location_ids'] = []
99
99
  params['filter']['organization_ids'] = []
@@ -107,7 +107,11 @@ module HammerCLIForeman
107
107
  end
108
108
 
109
109
  def override?
110
- option_override || filter['override?']
110
+ if option_override.nil?
111
+ filter['override?']
112
+ else
113
+ option_override
114
+ end
111
115
  end
112
116
 
113
117
  def filter
@@ -52,12 +52,6 @@ module HammerCLIForeman
52
52
  host
53
53
  end
54
54
 
55
- def get_parameters(host_id)
56
- params = HammerCLIForeman.foreman_resource!(:parameters).call(:index, :host_id => host_id)
57
- HammerCLIForeman.collection_to_common_format(params)
58
- end
59
-
60
-
61
55
  output do
62
56
  field :id, _("Id")
63
57
  field :uuid, _("UUID"), Fields::Field, :hide_blank => true
@@ -115,6 +109,7 @@ module HammerCLIForeman
115
109
  end
116
110
 
117
111
  HammerCLIForeman::References.parameters(self)
112
+ HammerCLIForeman::References.all_parameters(self)
118
113
 
119
114
  # additional info
120
115
  label _("Additional info") do
@@ -233,7 +228,7 @@ module HammerCLIForeman
233
228
 
234
229
  def validate_options
235
230
  super
236
- unless validator.any(:option_hostgroup_id, :option_hostgroup_name).exist?
231
+ unless validator.any(:option_hostgroup_id, :option_hostgroup_name, :option_hostgroup_title).exist?
237
232
  if option_managed
238
233
  validator.any(:option_architecture_name, :option_architecture_id).required
239
234
  validator.any(:option_domain_name, :option_domain_id).required
@@ -72,6 +72,7 @@ module HammerCLIForeman
72
72
  class InfoCommand < HammerCLIForeman::InfoCommand
73
73
 
74
74
  output ListCommand.output_definition do
75
+ field :description, _("Description"), Fields::LongText, :hide_blank => true
75
76
  field nil, _("Subnet"), Fields::SingleReference, :key => :subnet
76
77
 
77
78
  field nil, _("Domain"), Fields::SingleReference, :key => :domain