Unverified Commit b31184e5 authored by themylogin's avatar themylogin Committed by GitHub
Browse files

Merge pull request #30 from truenas/NAS-112365

NAS-112365 / 21.10 / Do not pass `select` to query method, filter fields after processing …
Showing with 25 additions and 9 deletions
+25 -9
......@@ -28,7 +28,7 @@ class CallMixin(object):
"""
return args
def call(self, name, *args, job=False, raise_=False):
def call(self, name, *args, job=False, output_processor=None, raise_=False):
try:
args = self._process_call_args(copy.deepcopy(args))
......@@ -37,6 +37,9 @@ class CallMixin(object):
for op in self.output_processors:
rv = op(self.context, rv)
if output_processor is not None:
rv = output_processor(rv)
except Exception as e:
if raise_:
raise
......
......@@ -34,11 +34,10 @@ def patch_users(context, users):
}
for user in users:
if "group" in user:
user["group"].pop("id")
user["group"] = {k[len("bsdgrp_"):]: v for k, v in user["group"].items()}
if "groups" in user:
user["groups"] = [groups[id] for id in user["groups"]]
user["group"].pop("id")
user["group"] = {k[len("bsdgrp_"):]: v for k, v in user["group"].items()}
user["groups"] = [groups[id] for id in user["groups"]]
class AccountQueryCommand(QueryCommand):
......@@ -165,8 +164,7 @@ def patch_groups(context, groups):
if k in group
}
if "users" in group:
group["users"] = [users[id] for id in group["users"]]
group["users"] = [users[id] for id in group["users"]]
class GroupQueryCommand(QueryCommand):
......
# -*- coding=utf-8 -*-
import functools
import logging
from midcli.command.call_mixin import CallMixin
......@@ -12,6 +13,17 @@ logger = logging.getLogger(__name__)
__all__ = ["QueryCommand"]
def output_processor(select, rv):
if select is not None:
if isinstance(rv, dict):
return {k: v for k, v in rv.items() if k in select}
if isinstance(rv, list):
return [output_processor(select, item) for item in rv]
return rv
class QueryCommand(CallMixin, Command):
def __init__(self, *args, method=None, **kwargs):
self.method = method
......@@ -24,7 +36,10 @@ class QueryCommand(CallMixin, Command):
print(e.args[0])
return
self.call(self.method["name"], parsed.filters, parsed.options)
select = parsed.options.pop("select", None)
self.call(self.method["name"], parsed.filters, parsed.options,
output_processor=functools.partial(output_processor, select))
def get_completions(self, text):
return get_completions(self.method["filterable_schema"], text)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment