malcontent-client: Disambiguate usage of path

The cmdline arguments may refer to both paths or flatpak refs so lets
disambiguate here for clarity.

Signed-off-by: Andre Moreira Magalhaes <andre@endlessm.com>
This commit is contained in:
Andre Moreira Magalhaes 2019-06-13 01:44:51 +00:00
parent 3800cd3818
commit 6c7c386ce2
1 changed files with 18 additions and 16 deletions

View File

@ -194,36 +194,36 @@ def command_monitor(user, quiet=False, interactive=True):
break break
def command_check(user, path, quiet=False, interactive=True): def command_check(user, arg, quiet=False, interactive=True):
"""Check the given path or flatpak ref is runnable by the given user, """Check the given path or flatpak ref is runnable by the
according to their app filter.""" given user, according to their app filter."""
user_id = __lookup_user_id_or_error(user) user_id = __lookup_user_id_or_error(user)
app_filter = __get_app_filter_or_error(user_id, interactive) app_filter = __get_app_filter_or_error(user_id, interactive)
if path.startswith('app/') and path.count('/') < 3: if arg.startswith('app/') and arg.count('/') < 3:
# Flatpak app ID # Flatpak app ID
path = path[4:] arg = arg[4:]
is_allowed = app_filter.is_flatpak_app_allowed(path) is_allowed = app_filter.is_flatpak_app_allowed(arg)
noun = 'Flatpak app ID' noun = 'Flatpak app ID'
elif path.startswith('app/') or path.startswith('runtime/'): elif arg.startswith('app/') or arg.startswith('runtime/'):
# Flatpak ref # Flatpak ref
is_allowed = app_filter.is_flatpak_ref_allowed(path) is_allowed = app_filter.is_flatpak_ref_allowed(arg)
noun = 'Flatpak ref' noun = 'Flatpak ref'
else: else:
# File system path # File system path
path = os.path.abspath(path) arg = os.path.abspath(arg)
is_allowed = app_filter.is_path_allowed(path) is_allowed = app_filter.is_path_allowed(arg)
noun = 'Path' noun = 'Path'
if is_allowed: if is_allowed:
if not quiet: if not quiet:
print('{} {} is allowed by app filter for user {}'.format( print('{} {} is allowed by app filter for user {}'.format(
noun, path, user_id)) noun, arg, user_id))
return return
else: else:
if not quiet: if not quiet:
print('{} {} is not allowed by app filter for user {}'.format( print('{} {} is not allowed by app filter for user {}'.format(
noun, path, user_id)) noun, arg, user_id))
raise SystemExit(EXIT_PATH_NOT_ALLOWED) raise SystemExit(EXIT_PATH_NOT_ALLOWED)
@ -312,14 +312,15 @@ def main():
# check command # check command
parser_check = subparsers.add_parser('check', parents=[common_parser], parser_check = subparsers.add_parser('check', parents=[common_parser],
help='check whether a path is ' help='check whether a path or '
'flatpak ref is '
'allowed by app filter') 'allowed by app filter')
parser_check.set_defaults(function=command_check) parser_check.set_defaults(function=command_check)
parser_check.add_argument('user', default='', nargs='?', parser_check.add_argument('user', default='', nargs='?',
help='user ID or username to get the app filter ' help='user ID or username to get the app filter '
'for (default: current user)') 'for (default: current user)')
parser_check.add_argument('path', parser_check.add_argument('arg',
help='path to a program to check') help='path to a program or flatpak ref to check')
# oars-section command # oars-section command
parser_oars_section = subparsers.add_parser('oars-section', parser_oars_section = subparsers.add_parser('oars-section',
@ -362,7 +363,8 @@ def main():
help='unconditionally disallow installation to ' help='unconditionally disallow installation to '
'the system flatpak repo') 'the system flatpak repo')
parser_set.add_argument('app_filter_args', nargs='*', parser_set.add_argument('app_filter_args', nargs='*',
help='paths to blacklist and OARS section=value ' help='paths or flatpak refs to '
'blacklist and OARS section=value '
'pairs to store') 'pairs to store')
parser_set.set_defaults(allow_user_installation=True, parser_set.set_defaults(allow_user_installation=True,
allow_system_installation=False) allow_system_installation=False)