/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-09 18:30:17 UTC
  • mfrom: (237.26.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 382.
  • Revision ID: teddy@recompile.se-20190309183017-5z0892yksb1rpulx
mandos-ctl: Merge refactoring changes and debug output

Show diffs side-by-side

added added

removed removed

Lines of Context:
294
294
                    "ApprovalDuration", "Checker", "ExtendedTimeout",
295
295
                    "Expires", "LastCheckerStatus")
296
296
    def run(self, mandos, clients):
297
 
        print(self.output(clients))
 
297
        print(self.output(clients.values()))
298
298
 
299
299
class PropertyCmd(Command):
300
300
    """Abstract class for Actions for setting one client property"""
336
336
        keywords = default_keywords
337
337
        if self.verbose:
338
338
            keywords = self.all_keywords
339
 
        return str(self.TableOfClients(clients.values(), keywords))
 
339
        return str(self.TableOfClients(clients, keywords))
340
340
 
341
341
    class TableOfClients(object):
342
342
        tableheaders = {
433
433
            sys.exit(0)
434
434
        sys.exit(1)
435
435
    def is_enabled(self, client, properties):
436
 
        return bool(properties["Enabled"])
 
436
        log.debug("D-Bus: %s:%s:%s.Get(%r, %r)", busname,
 
437
                  client.__dbus_object_path__,
 
438
                  dbus.PROPERTIES_IFACE, client_interface,
 
439
                  "Enabled")
 
440
        return bool(client.Get(client_interface, "Enabled",
 
441
                               dbus_interface=dbus.PROPERTIES_IFACE))
437
442
 
438
443
class RemoveCmd(Command):
439
444
    def run_on_one_client(self, client, properties):
757
762
    clients = {}
758
763
 
759
764
    if not clientnames:
760
 
        clients = {bus.get_object(busname, path): properties
 
765
        clients = {(log.debug("D-Bus: Connect to: (name=%r, path=%r)",
 
766
                              busname, str(path)) and False) or
 
767
                   bus.get_object(busname, path): properties
761
768
                   for path, properties in mandos_clients.items()}
762
769
    else:
763
770
        for name in clientnames:
764
771
            for path, client in mandos_clients.items():
765
772
                if client["Name"] == name:
 
773
                    log.debug("D-Bus: Connect to: (name=%r, path=%r)",
 
774
                              busname, str(path))
766
775
                    client_objc = bus.get_object(busname, path)
767
776
                    clients[client_objc] = client
768
777
                    break
903
912
 
904
913
class TestPrintTableCmd(TestCmd):
905
914
    def test_normal(self):
906
 
        output = PrintTableCmd().output(self.clients)
 
915
        output = PrintTableCmd().output(self.clients.values())
907
916
        expected_output = """
908
917
Name   Enabled Timeout  Last Successful Check
909
918
foo    Yes     00:05:00 2019-02-03T00:00:00  
911
920
"""[1:-1]
912
921
        self.assertEqual(output, expected_output)
913
922
    def test_verbose(self):
914
 
        output = PrintTableCmd(verbose=True).output(self.clients)
 
923
        output = PrintTableCmd(verbose=True).output(
 
924
            self.clients.values())
915
925
        expected_output = """
916
926
Name   Enabled Timeout  Last Successful Check Created             Interval Host            Key ID                                                           Fingerprint                              Check Is Running Last Enabled        Approval Is Pending Approved By Default Last Approval Request Approval Delay Approval Duration Checker              Extended Timeout Expires             Last Checker Status
917
927
foo    Yes     00:05:00 2019-02-03T00:00:00   2019-01-02T00:00:00 00:02:00 foo.example.org 92ed150794387c03ce684574b1139a6594a34f895daaaf09fd8ea90a27cddb12 778827225BA7DE539C5A7CFA59CFF7CDBD9A5920 No               2019-01-03T00:00:00 No                  Yes                                       00:00:00       00:00:01          fping -q -- %(host)s 00:15:00         2019-02-04T00:00:00 0                  
919
929
"""[1:-1]
920
930
        self.assertEqual(output, expected_output)
921
931
    def test_one_client(self):
922
 
        output = PrintTableCmd().output(self.one_client)
 
932
        output = PrintTableCmd().output(self.one_client.values())
923
933
        expected_output = """
924
934
Name Enabled Timeout  Last Successful Check
925
935
foo  Yes     00:05:00 2019-02-03T00:00:00