Skip to content
Snippets Groups Projects
Commit 903cf117 authored by Martin Mareš's avatar Martin Mareš
Browse files

Implemented "shc list"

parent b375b13d
Branches
No related tags found
No related merge requests found
......@@ -52,15 +52,10 @@ def setup_container(args: argparse.Namespace, require_root: bool, container: Opt
except ConfigError as e:
die(str(e))
if args.as_user is None:
uid = 0
else:
uid = args.as_user
if require_root and uid != 0:
if require_root and args.as_user != 0:
die('This operation must be performed by root')
if not check_rights(cc, uid, args.as_groups):
if not check_rights(cc, args.as_user, args.as_groups):
die('You do not have permission to operate this container')
return cc
......@@ -308,6 +303,14 @@ def cmd_rsync(args: argparse.Namespace) -> None:
run_command(cmd)
def cmd_list(args: argparse.Namespace) -> None:
for conf in Path(config.container_config_dir).iterdir():
if conf.suffix == '.toml':
cc = ContainerConfig.load(config, conf.stem)
if args.all or check_rights(cc, args.as_user, args.as_groups):
print(cc.container)
def parse_int_list(s: str) -> List[int]:
return list(map(int, s.split(',')))
......@@ -316,14 +319,11 @@ def main() -> None:
parser = argparse.ArgumentParser(
description="Ship's Cat -- a container management tool",
)
parser.add_argument('--as-user', type=int, metavar='UID', help='user ID of requesting user')
parser.add_argument('--as-user', type=int, default=0, metavar='UID', help='user ID of requesting user')
parser.add_argument('--as-groups', type=parse_int_list, metavar='GID,...', help='group IDs of requesting user (primary first)')
parser.add_argument('--verbose', '-v', default=False, action='store_true', help='be chatty and explain what is going on')
subparsers = parser.add_subparsers(help='action to perform', dest='action', required=True, metavar='ACTION')
init_parser = subparsers.add_parser('init', help='initialize a new container', description='Initialize a new container. Should be called by root.')
init_parser.add_argument('name', help='name of the container')
create_parser = subparsers.add_parser('create', help='create a container from an image', description='Create a container from an image.')
create_parser.add_argument('name', help='name of the container')
......@@ -339,6 +339,12 @@ def main() -> None:
create_parser.add_argument('--tty', '-t', default=False, action='store_true', help='stdio will be attached to a pseudo-terminal')
create_parser.add_argument('--user', '-u', metavar='USER[:GROUP]', help='user/group to run the command under (default: root)')
init_parser = subparsers.add_parser('init', help='initialize a new container', description='Initialize a new container. Should be called by root.')
init_parser.add_argument('name', help='name of the container')
list_parser = subparsers.add_parser('list', help='list available containers', description='List available containers.')
list_parser.add_argument('--all', '-a', default=False, action='store_true', help='include containers with no permission to operate')
start_parser = subparsers.add_parser('rsync', help='rsync connection wrapper', description="""
Connection wrapper for rsync.
......@@ -368,6 +374,7 @@ def main() -> None:
'enable': cmd_enable,
'exec': cmd_exec,
'init': cmd_init,
'list': cmd_list,
'rsync': cmd_rsync,
'shell': cmd_shell,
'start': cmd_start,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment