/mandos/trunk

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

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2022-04-24 11:04:54 UTC
  • Revision ID: teddy@recompile.se-20220424110454-p1tgedieq5eg74q1
Server: Fix minor style issue

* mandos-ctl: Consistently use double quotes instead of single quotes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
 
90
90
locale.setlocale(locale.LC_ALL, "")
91
91
 
92
 
version = "1.8.12"
 
92
version = "1.8.14"
93
93
 
94
94
 
95
95
def main():
102
102
    clientnames = options.client
103
103
 
104
104
    if options.debug:
105
 
        log.setLevel(logging.DEBUG)
 
105
        logging.getLogger("").setLevel(logging.DEBUG)
106
106
 
107
107
    if dbussy is not None and ravel is not None:
108
108
        bus = dbussy_adapter.CachingBus(dbussy, ravel)
256
256
        return rfc3339_duration_to_delta(interval)
257
257
    except ValueError as e:
258
258
        log.warning("%s - Parsing as pre-1.6.1 interval instead",
259
 
                    ' '.join(e.args))
 
259
                    " ".join(e.args))
260
260
    return parse_pre_1_6_1_interval(interval)
261
261
 
262
262
 
395
395
    """Parse an interval string as documented by Mandos before 1.6.1,
396
396
    and return a datetime.timedelta
397
397
 
398
 
    >>> parse_pre_1_6_1_interval('7d') == datetime.timedelta(days=7)
399
 
    True
400
 
    >>> parse_pre_1_6_1_interval('60s') == datetime.timedelta(0, 60)
401
 
    True
402
 
    >>> parse_pre_1_6_1_interval('60m') == datetime.timedelta(hours=1)
403
 
    True
404
 
    >>> parse_pre_1_6_1_interval('24h') == datetime.timedelta(days=1)
405
 
    True
406
 
    >>> parse_pre_1_6_1_interval('1w') == datetime.timedelta(days=7)
407
 
    True
408
 
    >>> parse_pre_1_6_1_interval('5m 30s') == datetime.timedelta(0, 330)
409
 
    True
410
 
    >>> parse_pre_1_6_1_interval('') == datetime.timedelta(0)
 
398
    >>> parse_pre_1_6_1_interval("7d") == datetime.timedelta(days=7)
 
399
    True
 
400
    >>> parse_pre_1_6_1_interval("60s") == datetime.timedelta(0, 60)
 
401
    True
 
402
    >>> parse_pre_1_6_1_interval("60m") == datetime.timedelta(hours=1)
 
403
    True
 
404
    >>> parse_pre_1_6_1_interval("24h") == datetime.timedelta(days=1)
 
405
    True
 
406
    >>> parse_pre_1_6_1_interval("1w") == datetime.timedelta(days=7)
 
407
    True
 
408
    >>> parse_pre_1_6_1_interval("5m 30s") == datetime.timedelta(0, 330)
 
409
    True
 
410
    >>> parse_pre_1_6_1_interval("") == datetime.timedelta(0)
411
411
    True
412
412
    >>> # Ignore unknown characters, allow any order and repetitions
413
 
    >>> parse_pre_1_6_1_interval('2dxy7zz11y3m5m') == datetime.timedelta(2, 480, 18000)
 
413
    >>> parse_pre_1_6_1_interval("2dxy7zz11y3m5m") == datetime.timedelta(2, 480, 18000)
414
414
    True
415
415
 
416
416
    """
876
876
                    {key: properties[key]
877
877
                     for key in self.all_keywords}
878
878
                    for properties in clients.values()}
879
 
            print(json.dumps(data, indent=4, separators=(',', ': ')))
 
879
            print(json.dumps(data, indent=4, separators=(",", ": ")))
880
880
 
881
881
 
882
882
    class PrintTable(Output):
2439
2439
        busname = "se.recompile.Mandos"
2440
2440
        client_interface = "se.recompile.Mandos.Client"
2441
2441
        command.Approve().run(self.bus.clients, self.bus)
 
2442
        self.assertTrue(self.bus.clients)
2442
2443
        for clientpath in self.bus.clients:
2443
2444
            self.assertIn(("Approve", busname, clientpath,
2444
2445
                           client_interface, (True,)), self.bus.calls)
2447
2448
        busname = "se.recompile.Mandos"
2448
2449
        client_interface = "se.recompile.Mandos.Client"
2449
2450
        command.Deny().run(self.bus.clients, self.bus)
 
2451
        self.assertTrue(self.bus.clients)
2450
2452
        for clientpath in self.bus.clients:
2451
2453
            self.assertIn(("Approve", busname, clientpath,
2452
2454
                           client_interface, (False,)),
2453
2455
                          self.bus.calls)
2454
2456
 
2455
2457
    def test_Remove(self):
 
2458
        busname = "se.recompile.Mandos"
 
2459
        server_path = "/"
 
2460
        server_interface = "se.recompile.Mandos"
 
2461
        orig_clients = self.bus.clients.copy()
2456
2462
        command.Remove().run(self.bus.clients, self.bus)
2457
 
        for clientpath in self.bus.clients:
2458
 
            self.assertIn(("RemoveClient", dbus_busname,
2459
 
                           dbus_server_path, dbus_server_interface,
 
2463
        self.assertFalse(self.bus.clients)
 
2464
        for clientpath in orig_clients:
 
2465
            self.assertIn(("RemoveClient", busname,
 
2466
                           server_path, server_interface,
2460
2467
                           (clientpath,)), self.bus.calls)
2461
2468
 
2462
2469
    expected_json = {
2664
2671
        else:
2665
2672
            cmd_args = [() for x in range(len(self.values_to_get))]
2666
2673
            values_to_get = self.values_to_get
 
2674
        self.assertTrue(values_to_get)
2667
2675
        for value_to_get, cmd_arg in zip(values_to_get, cmd_args):
2668
2676
            for clientpath in self.bus.clients:
2669
2677
                self.bus.clients[clientpath][self.propname] = (
2670
2678
                    Unique())
2671
2679
            self.command(*cmd_arg).run(self.bus.clients, self.bus)
 
2680
            self.assertTrue(self.bus.clients)
2672
2681
            for clientpath in self.bus.clients:
2673
2682
                value = (self.bus.clients[clientpath]
2674
2683
                         [self.propname])