/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-03-03 14:21:15 UTC
  • mto: (237.7.594 trunk)
  • mto: This revision was merged to the branch mainline in revision 382.
  • Revision ID: teddy@recompile.se-20190303142115-qdbpaz17ms5cq7y5
mandos-ctl: Refactor

* mandos-ctl (main): Move argument parsing into separate function.
  (commands_and_clients_from_options): New.

Show diffs side-by-side

added added

removed removed

Lines of Context:
515
515
                options.deny))
516
516
 
517
517
 
518
 
def main():
 
518
def commands_and_clients_from_options():
519
519
    parser = argparse.ArgumentParser()
520
520
    parser.add_argument("--version", action="version",
521
521
                        version="%(prog)s {}".format(version),
593
593
    if options.is_enabled and len(options.client) > 1:
594
594
            parser.error("--is-enabled requires exactly one client")
595
595
 
596
 
    try:
597
 
        bus = dbus.SystemBus()
598
 
        mandos_dbus_objc = bus.get_object(busname, server_path)
599
 
    except dbus.exceptions.DBusException:
600
 
        log.critical("Could not connect to Mandos server")
601
 
        sys.exit(1)
602
 
 
603
 
    mandos_serv = dbus.Interface(mandos_dbus_objc,
604
 
                                 dbus_interface=server_interface)
605
 
    mandos_serv_object_manager = dbus.Interface(
606
 
        mandos_dbus_objc, dbus_interface=dbus.OBJECT_MANAGER_IFACE)
607
 
 
608
596
    commands = []
609
597
 
610
598
    if options.dump_json:
674
662
    if not commands:
675
663
        commands.append(PrintTableCmd(verbose=options.verbose))
676
664
 
 
665
    return commands, options.client
 
666
 
 
667
 
 
668
def main():
 
669
    commands, clientnames = commands_and_clients_from_options()
 
670
 
 
671
    try:
 
672
        bus = dbus.SystemBus()
 
673
        mandos_dbus_objc = bus.get_object(busname, server_path)
 
674
    except dbus.exceptions.DBusException:
 
675
        log.critical("Could not connect to Mandos server")
 
676
        sys.exit(1)
 
677
 
 
678
    mandos_serv = dbus.Interface(mandos_dbus_objc,
 
679
                                 dbus_interface=server_interface)
 
680
    mandos_serv_object_manager = dbus.Interface(
 
681
        mandos_dbus_objc, dbus_interface=dbus.OBJECT_MANAGER_IFACE)
 
682
 
677
683
    # Filter out log message from dbus module
678
684
    dbus_logger = logging.getLogger("dbus.proxies")
679
685
    class NullFilter(logging.Filter):
699
705
    # Compile dict of (clients: properties) to process
700
706
    clients = {}
701
707
 
702
 
    if options.all or not options.client:
 
708
    if not clientnames:
703
709
        clients = {bus.get_object(busname, path): properties
704
710
                   for path, properties in mandos_clients.items()}
705
711
    else:
706
 
        for name in options.client:
 
712
        for name in clientnames:
707
713
            for path, client in mandos_clients.items():
708
714
                if client["Name"] == name:
709
715
                    client_objc = bus.get_object(busname, path)