Skip to content

Commit fd288fe

Browse files
authored
Refs #38077 - Don't build hidden params as options (#634)
1 parent fb0970e commit fd288fe

10 files changed

+7
-34
lines changed

lib/hammer_cli_foreman/commands.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def exception_handler_class
9696
def self.create_option_builder
9797
configurator = BuilderConfigurator.new(searchables, dependency_resolver)
9898

99-
builder = ForemanOptionBuilder.new(searchables)
99+
builder = ForemanOptionBuilder.new(searchables, resource_defined? ? resource.action(action) : nil)
100100
builder.builders = super.builders
101101
builder.builders += configurator.builders_for(resource, resource.action(action)) if resource_defined?
102102
builder

lib/hammer_cli_foreman/option_builders.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,17 @@ def builders_for(resource, action)
9595

9696
class ForemanOptionBuilder < HammerCLI::OptionBuilderContainer
9797

98-
def initialize(searchables)
98+
def initialize(searchables, action = nil)
9999
@searchables = searchables
100+
@action = action
100101
end
101102

102103
def build(builder_params={})
103104
expansion_options = builder_params[:expand] || {}
104105

106+
except_default = @action&.params&.select { |p| !p.show? }&.map { |p| HammerCLIForeman.param_to_resource(p.name).name } || []
105107
allowed_resources = expansion_options[:only] || default_dependent_resources
106-
allowed_resources -= expansion_options[:except] || []
108+
allowed_resources -= expansion_options[:except] || except_default
107109
allowed_resources += expansion_options[:including] || []
108110
allowed_resources.uniq!
109111

test/data/3.14/foreman_api.json

+1
Large diffs are not rendered by default.

test/functional/architecture_test.rb

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
)
4040
defaults.stubs(:write_to_file).returns(true)
4141
defaults.stubs(:providers).returns(providers)
42-
api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
43-
api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
4442
api_expects(:architectures, :index, 'List architectures').returns(@architectures)
4543

4644
result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })

test/functional/settings_test.rb

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
)
4646
defaults.stubs(:write_to_file).returns(true)
4747
defaults.stubs(:providers).returns(providers)
48-
api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
49-
api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
5048
api_expects(:settings, :index, 'List settings').returns(setting)
5149

5250
result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })

test/functional/usergroup_test.rb

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
)
4141
defaults.stubs(:write_to_file).returns(true)
4242
defaults.stubs(:providers).returns(providers)
43-
api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_organization' => { 'id' => 2 } }]))
44-
api_expects(:users, :index, 'Find user').with_params(search: 'login=admin').returns(index_response([{ 'default_location' => { 'id' => 1 } }]))
4543
api_expects(:usergroups, :index, 'List user groups').returns(@user_groups)
4644

4745
result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })

test/test_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
require 'hammer_cli'
1717
require 'hammer_cli_foreman/testing/api_expectations'
1818

19-
FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '3.12'
19+
FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '3.14'
2020
unless Dir.entries('test/data').include? FOREMAN_VERSION
2121
raise StandardError.new "Version is not correct"
2222
end

test/unit/architecture_test.rb

-10
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
describe "parameters" do
1818
it_should_accept "no arguments"
1919
it_should_accept_search_params
20-
it_should_accept 'organization', ['--organization-id=1']
21-
it_should_accept 'location', ['--location-id=1']
2220
end
2321

2422
describe "output" do
@@ -39,8 +37,6 @@
3937
describe "parameters" do
4038
it_should_accept "id", ["--id=1"]
4139
it_should_accept "name", ["--name=arch"]
42-
it_should_accept 'organization', %w[--id=1 --organization-id=1]
43-
it_should_accept 'location', %w[--id=1 --location-id=1]
4440
# it_should_fail_with "no arguments" # TODO: temporarily disabled, parameters are checked in the id resolver
4541
end
4642

@@ -61,8 +57,6 @@
6157

6258
describe "parameters" do
6359
it_should_accept "name", ["--name=arch"]
64-
it_should_accept 'organization', %w[--name=arch --organization-id=1]
65-
it_should_accept 'location', %w[--name=arch --location-id=1]
6660
# it_should_fail_with "name missing", []
6761
# TODO: temporarily disabled, parameters are checked in the api
6862
end
@@ -77,8 +71,6 @@
7771
describe "parameters" do
7872
it_should_accept "name", ["--name=arch"]
7973
it_should_accept "id", ["--id=1"]
80-
it_should_accept 'organization', %w[--id=1 --organization-id=1]
81-
it_should_accept 'location', %w[--id=1 --location-id=1]
8274
# it_should_fail_with "name or id missing", [] # TODO: temporarily disabled, parameters are checked in the id resolver
8375
end
8476

@@ -92,8 +84,6 @@
9284
describe "parameters" do
9385
it_should_accept "name", ["--name=arch", "--new-name=arch2"]
9486
it_should_accept "id", ["--id=1", "--new-name=arch2"]
95-
it_should_accept 'organization', %w[--id=1 --new-name=arch2 --organization-id=1]
96-
it_should_accept 'location', %w[--id=1 --new-name=arch2 --location-id=1]
9787
# it_should_fail_with "no params", [] # TODO: temporarily disabled, parameters are checked in the id resolver
9888
# it_should_fail_with "name or id missing", ["--new-name=arch2"] # TODO: temporarily disabled, parameters are checked in the id resolver
9989
end

test/unit/settings_test.rb

-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
describe "parameters" do
1919
it_should_accept "no arguments"
2020
it_should_accept_search_params
21-
it_should_accept 'organization', ['--organization-id=1']
22-
it_should_accept 'location', ['--location-id=1']
2321
end
2422

2523
describe "output" do
@@ -40,8 +38,6 @@
4038
describe "parameters" do
4139
it_should_accept "name", ["--name=setting1", "--value=setting2"]
4240
it_should_accept "id", ["--id=1", "--value=setting2"]
43-
it_should_accept 'organization', %w[--id=1 --organization-id=1]
44-
it_should_accept 'location', %w[--id=1 --location-id=1]
4541
end
4642

4743
end

test/unit/usergroup_test.rb

-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
describe "parameters" do
1919
it_should_accept "no arguments"
2020
it_should_accept_search_params
21-
it_should_accept 'organization', ['--organization-id=1']
22-
it_should_accept 'location', ['--location-id=1']
2321
end
2422

2523
describe "output" do
@@ -37,8 +35,6 @@
3735
describe "parameters" do
3836
it_should_accept "id", ["--id=1"]
3937
it_should_accept "name", ["--name=ug"]
40-
it_should_accept 'organization', %w[--id=1 --organization-id=1]
41-
it_should_accept 'location', %w[--id=1 --location-id=1]
4238
end
4339

4440
describe "output" do
@@ -62,8 +58,6 @@
6258
describe "parameters" do
6359
it_should_accept "name", ["--name=ug"]
6460
it_should_accept "name, role ids, user group ids and user ids", ["--name=ug", "--role-ids=1,2,3", "--user-group-ids=1,2,3", "--user-ids=1,2,3"]
65-
it_should_accept 'organization', %w[--name=ug --organization-id=1]
66-
it_should_accept 'location', %w[--name=ug --location-id=1]
6761
end
6862
end
6963

@@ -74,8 +68,6 @@
7468
describe "parameters" do
7569
it_should_accept "name", ["--name=ug"]
7670
it_should_accept "id", ["--id=1"]
77-
it_should_accept 'organization', %w[--id=1 --organization-id=1]
78-
it_should_accept 'location', %w[--id=1 --location-id=1]
7971
end
8072
end
8173

@@ -88,8 +80,6 @@
8880
it_should_accept "id", ["--id=1"]
8981
it_should_accept "name and new name", ["--name=ug", "--new-name=ug2"]
9082
it_should_accept "id, new name, role ids, user group ids and user ids", ["--id=1", "--new-name=ug", "--role-ids=1,2,3", "--user-group-ids=1,2,3", "--user-ids=1,2,3"]
91-
it_should_accept 'organization', %w[--id=1 --organization-id=1]
92-
it_should_accept 'location', %w[--id=1 --location-id=1]
9383
end
9484
end
9585
end

0 commit comments

Comments
 (0)