Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Fixed

Contributed by @blackstrip

* Fix issue with pack option not working when running policy list cli #5534

Contributed by @momokuri-3

Added
~~~~~

Expand Down
27 changes: 13 additions & 14 deletions st2client/st2client/commands/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,19 @@ def __init__(self, resource, *args, **kwargs):

@resource.add_auth_token_to_kwargs_from_cli
def run(self, args, **kwargs):
if args.resource_ref or args.policy_type:
filters = {}

if args.resource_ref:
filters["resource_ref"] = args.resource_ref

if args.policy_type:
filters["policy_type"] = args.policy_type

filters.update(**kwargs)

return self.manager.query(**filters)
else:
return self.manager.get_all(**kwargs)
filters = {}
if args.pack:
filters["pack"] = args.pack
if args.resource_ref:
filters["resource_ref"] = args.resource_ref
if args.policy_type:
filters["policy_type"] = args.policy_type
filters.update(**kwargs)
include_attributes = self._get_include_attributes(args=args)
if include_attributes:
include_attributes = ",".join(include_attributes)
filters["params"] = {"include_attributes": include_attributes}
return self.manager.query(**filters)


class PolicyGetCommand(resource.ContentPackResourceGetCommand):
Expand Down
15 changes: 15 additions & 0 deletions st2client/tests/unit/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,21 @@ def test_dont_warn_multiple_times(self):
shell.LOG.info.call_args_list[1][0][0], "Skipping parsing CLI config"
)

def test_policy_list_with_pack_option(self):
argv = ["policy", "list", "-p", "test"]
mock_obj = mock.MagicMock(
return_value=base.FakeResponse(json.dumps(base.RESOURCES), 200, "OK")
)
with mock.patch.object(httpclient.HTTPClient, "get", mock_obj):
self.shell.run(argv)
self.assertEqual(
mock_obj.mock_calls[0],
mock.call(
"/policies/?include_attributes=ref%2Cresource_ref%2C"
"policy_type%2Cenabled&pack=test"
),
)


class CLITokenCachingTestCase(unittest2.TestCase):
def setUp(self):
Expand Down