hammer_cli_foreman 0.19.1 → 0.19.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a05fd4bedcc468c977bef7bafd5bdbe7cdafb966ad2435a2c4ef3501db97d53
4
- data.tar.gz: f819931de46c659607b94b4a4e5909ac9749221bd14f94c7cdfc86ea9e7b79c1
3
+ metadata.gz: 47cf21ecf7cd77a148ab586f7d81fc4e6377ca516d5a03717a1dc1167ced4d02
4
+ data.tar.gz: fcf4efd442f73297a86d2073da2d784e4506d7b9f381b805c1e586664a0d818a
5
5
  SHA512:
6
- metadata.gz: 17e7e96c06e286cc62d2e085cd013f8b0f192d546312a2ada3239113e166abc629504f27a587bd683bb7a78c70ad768a7c631679a5a9d7f84d66fb89bb98a8a2
7
- data.tar.gz: 4fb887133aa59f44aa7dbd76764a3ebfdfb5ec5bc6ab34d1d1f5640136ebe6f08dfa5f025357caa17687faa573b85768dc20f5121c2c962c5b0980b70caa4d79
6
+ metadata.gz: cc62264df55fce5594302365182c1ae8aeed28ae25bb56eb4ac5624bebd253643a1548832638f55dbccfb222594edcce88ce07623aed52c6f133b690d35c1f83
7
+ data.tar.gz: c67a781b13dd94ae6fd37c5b3b47e888cc19b65338fac891a941d47b2b1a4576e16f6e31aa4c95441c40f8ae99af7cb4a391ee48618d76a7cb113f1e08bcbb8f
data/doc/release_notes.md CHANGED
@@ -1,5 +1,11 @@
1
1
  Release notes
2
2
  =============
3
+ ### 0.19.2 (2019-11-25)
4
+ * Handle empty params for codegrant flow ([PR #456](https://github.com/theforeman/hammer-cli-foreman/pull/456)), [#28196](http://projects.theforeman.org/issues/28196)
5
+ * Add http-proxy to hammer ([PR #454](https://github.com/theforeman/hammer-cli-foreman/pull/454)), [#28176](http://projects.theforeman.org/issues/28176)
6
+ * Handle error when empty parameters are passed ([PR #453](https://github.com/theforeman/hammer-cli-foreman/pull/453)), [#28196](http://projects.theforeman.org/issues/28196)
7
+ * Allow login in tty-less execution ([PR #452](https://github.com/theforeman/hammer-cli-foreman/pull/452)), [#28318](http://projects.theforeman.org/issues/28318)
8
+
3
9
  ### 0.19.1 (2019-11-18)
4
10
  * Fix method typo ([PR #450](https://github.com/theforeman/hammer-cli-foreman/pull/450)), [#27868](http://projects.theforeman.org/issues/27868)
5
11
 
@@ -84,6 +84,10 @@ module HammerCLIForeman
84
84
  'HammerCLIForeman::Hostgroup', 'hammer_cli_foreman/hostgroup'
85
85
  )
86
86
 
87
+ HammerCLI::MainCommand.lazy_subcommand('http-proxy', _("Manipulate http proxies"),
88
+ 'HammerCLIForeman::HttpProxy', 'hammer_cli_foreman/http_proxy'
89
+ )
90
+
87
91
  HammerCLI::MainCommand.lazy_subcommand('location', _("Manipulate locations"),
88
92
  'HammerCLIForeman::Location', 'hammer_cli_foreman/location'
89
93
  )
@@ -32,12 +32,12 @@ module HammerCLIForeman
32
32
  @oidc_client_id = input_oidc_client_id if input_oidc_client_id
33
33
  @oidc_redirect_uri = input_oidc_redirect_uri if input_oidc_redirect_uri
34
34
 
35
- if @oidc_client_id && @oidc_authorization_endpoint && @oidc_redirect_uri && @oidc_token_endpoint
35
+ 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
+ @token = nil
37
+ else
36
38
  get_code
37
39
  @token = HammerCLIForeman::OpenidConnect.new(
38
40
  @oidc_token_endpoint, @oidc_client_id).get_token_via_2fa(@code, @oidc_redirect_uri)
39
- else
40
- @token = nil
41
41
  end
42
42
  end
43
43
 
@@ -30,11 +30,11 @@ module HammerCLIForeman
30
30
  @user = input_user
31
31
  @password = input_password
32
32
  @oidc_client_id = input_oidc_client_id if input_oidc_client_id
33
- if @user && @password && @oidc_token_endpoint && @oidc_client_id
33
+ if @user.to_s.empty? || @password.to_s.empty? || @oidc_token_endpoint.to_s.empty? || @oidc_client_id.to_s.empty?
34
+ @token = nil
35
+ else
34
36
  @token = HammerCLIForeman::OpenidConnect.new(
35
37
  @oidc_token_endpoint, @oidc_client_id).get_token(@user, @password)
36
- else
37
- @token = nil
38
38
  end
39
39
  end
40
40
 
@@ -22,6 +22,9 @@ module HammerCLIForeman
22
22
  option_username || HammerCLI::Settings.get('_params', 'username'),
23
23
  option_password || HammerCLI::Settings.get('_params', 'password')
24
24
  )
25
+ logged_user = HammerCLIForeman.foreman_api_connection.authenticator.user
26
+ print_message(_("Successfully logged in as '%s'.") % logged_user)
27
+ HammerCLI::EX_OK
25
28
  end
26
29
  end
27
30
 
@@ -57,6 +60,9 @@ module HammerCLIForeman
57
60
  option_password || HammerCLI::Settings.get('_params', 'password')
58
61
  )
59
62
  end
63
+ logged_user = HammerCLIForeman.foreman_api_connection.authenticator.user
64
+ print_message(_("Successfully logged in as '%s'.") % logged_user)
65
+ HammerCLI::EX_OK
60
66
  end
61
67
  autoload_subcommands
62
68
  end
@@ -4,17 +4,12 @@ module HammerCLIForeman
4
4
  def execute_with_params(auth_type, *args)
5
5
  connection = HammerCLIForeman.foreman_api_reconnect(auth_type)
6
6
  if !(connection.authenticator.is_a?(HammerCLIForeman::Api::SessionAuthenticatorWrapper))
7
- HammerCLI.interactive_output.say(_("Can't perform login. Make sure sessions are enabled in hammer"\
8
- " configuration file."))
9
- return HammerCLI::EX_USAGE
7
+ raise ArgumentError, _("Can't perform login. Make sure sessions are enabled in hammer"\
8
+ " configuration file.")
10
9
  end
11
10
  connection.authenticator.set_auth_params(*args)
12
11
  connection.authenticator.force_user_change
13
12
  connection.login
14
-
15
- HammerCLI.interactive_output.say(_("Successfully logged in as '%s'.") %
16
- connection.authenticator.user)
17
- HammerCLI::EX_OK
18
13
  end
19
14
  end
20
15
  end
@@ -0,0 +1,49 @@
1
+ module HammerCLIForeman
2
+
3
+ class HttpProxy < HammerCLIForeman::Command
4
+
5
+ resource :http_proxies
6
+
7
+ class ListCommand < HammerCLIForeman::ListCommand
8
+
9
+ output do
10
+ field :id, _("Id")
11
+ field :name, _("Name")
12
+ end
13
+
14
+ build_options
15
+ end
16
+
17
+ class InfoCommand < HammerCLIForeman::InfoCommand
18
+ output ListCommand.output_definition do
19
+ field :username, _("Username")
20
+ field :url, _("URL")
21
+ end
22
+
23
+ build_options
24
+ end
25
+
26
+ class CreateCommand < HammerCLIForeman::CreateCommand
27
+ success_message _("Http proxy created.")
28
+ failure_message _("Could not create the http proxy")
29
+
30
+ build_options
31
+ end
32
+
33
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
34
+ success_message _("Http proxy deleted.")
35
+ failure_message _("Could not delete the http proxy")
36
+
37
+ build_options
38
+ end
39
+
40
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
41
+ success_message _("Http proxy updated.")
42
+ failure_message _("Could not update the http proxy")
43
+
44
+ build_options
45
+ end
46
+
47
+ autoload_subcommands
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  module HammerCLIForeman
2
2
  def self.version
3
- @version ||= Gem::Version.new "0.19.1"
3
+ @version ||= Gem::Version.new "0.19.2"
4
4
  end
5
5
  end
@@ -0,0 +1,69 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe 'httpproxy' do
4
+ let(:http_proxy) do
5
+ {
6
+ :id => 1,
7
+ :name => 'proxy1',
8
+ :url => 'http://proxy.example.com',
9
+ :username => 'user'
10
+ }
11
+ end
12
+
13
+ it 'list a http proxy' do
14
+ api_expects(:http_proxies, :index, 'List').with_params(
15
+ 'page' => 1, 'per_page' => 1000
16
+ ).returns(index_response([http_proxy]))
17
+
18
+ output = IndexMatcher.new([
19
+ ['ID', 'NAME'],
20
+ ['1', 'proxy1']
21
+ ])
22
+ expected_result = success_result(output)
23
+
24
+ result = run_cmd(%w(http-proxy list))
25
+ assert_cmd(expected_result, result)
26
+ end
27
+
28
+ it 'updates an http proxy' do
29
+ params = ['--id', http_proxy[:id],
30
+ '--password', 'katello']
31
+ api_expects(:http_proxies, :update, params)
32
+ .returns(http_proxy)
33
+
34
+ expected_result = success_result("Http proxy updated.\n")
35
+
36
+ result = run_cmd(%w(http-proxy update --id 1 --password katello))
37
+ assert_cmd(expected_result, result)
38
+ end
39
+
40
+ it 'shows info on an http proxy' do
41
+ params = ['--id', http_proxy[:id]]
42
+ api_expects(:http_proxies, :show, params)
43
+ .returns(http_proxy)
44
+ expected_result = success_result("Id: 1\nName: proxy1\nUsername: user\nURL: http://proxy.example.com\n\n")
45
+ result = run_cmd(%w(http-proxy info --id 1))
46
+ assert_cmd(expected_result, result)
47
+ end
48
+
49
+ it 'creates an http proxy' do
50
+ params = ['--url', http_proxy[:key],
51
+ '--name', http_proxy[:name],
52
+ '--password', 'foreman',
53
+ '--username', http_proxy[:username]]
54
+ api_expects(:http_proxies, :create, params)
55
+ .returns(http_proxy)
56
+
57
+ expected_result = success_result("Http proxy created.\n")
58
+
59
+ result = run_cmd(%w(http-proxy create --url "http://proxy.example.com" --name proxy1 --username user --password foreman))
60
+ assert_cmd(expected_result, result)
61
+ end
62
+
63
+ it 'deletes an http proxy' do
64
+ expected_result = success_result("Http proxy deleted.\n")
65
+
66
+ result = run_cmd(%w(http-proxy delete --id 1))
67
+ assert_cmd(expected_result, result)
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1
4
+ version: 0.19.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomáš Strachota
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-11-18 00:00:00.000000000 Z
12
+ date: 2019-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hammer_cli
@@ -157,6 +157,7 @@ files:
157
157
  - lib/hammer_cli_foreman/host.rb
158
158
  - lib/hammer_cli_foreman/hostgroup.rb
159
159
  - lib/hammer_cli_foreman/hosts/common_update_options.rb
160
+ - lib/hammer_cli_foreman/http_proxy.rb
160
161
  - lib/hammer_cli_foreman/i18n.rb
161
162
  - lib/hammer_cli_foreman/id_resolver.rb
162
163
  - lib/hammer_cli_foreman/image.rb
@@ -241,6 +242,7 @@ files:
241
242
  - test/functional/host_test.rb
242
243
  - test/functional/hostgroup/create_test.rb
243
244
  - test/functional/hostgroup/update_test.rb
245
+ - test/functional/http_proxy_test.rb
244
246
  - test/functional/location_test.rb
245
247
  - test/functional/organization_test.rb
246
248
  - test/functional/personal_access_token_test.rb
@@ -410,6 +412,7 @@ test_files:
410
412
  - test/data/1.20/foreman_api.json
411
413
  - test/data/README.md
412
414
  - test/data/1.16/foreman_api.json
415
+ - test/functional/http_proxy_test.rb
413
416
  - test/functional/commands/list_test.rb
414
417
  - test/functional/smart_variable_test.rb
415
418
  - test/functional/user_test.rb