/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:49:03 UTC
  • mto: This revision was merged to the branch mainline in revision 382.
  • Revision ID: teddy@recompile.se-20190309184903-81a0vh49w1156a2o
mandos-ctl: Refactor

* mandos-ctl: Rename "property" to "propname" to not conflict with
              "property" builtin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
303
303
        log.debug("D-Bus: %s:%s:%s.Set(%r, %r, %r)", busname,
304
304
                  client.__dbus_object_path__,
305
305
                  dbus.PROPERTIES_IFACE, client_interface,
306
 
                  self.property, self.value_to_set
 
306
                  self.propname, self.value_to_set
307
307
                  if not isinstance(self.value_to_set, dbus.Boolean)
308
308
                  else bool(self.value_to_set))
309
 
        client.Set(client_interface, self.property, self.value_to_set,
 
309
        client.Set(client_interface, self.propname, self.value_to_set,
310
310
                   dbus_interface=dbus.PROPERTIES_IFACE)
311
311
 
312
312
class ValueArgumentMixIn(object):
462
462
                       dbus_interface=client_interface)
463
463
 
464
464
class EnableCmd(PropertyCmd):
465
 
    property = "Enabled"
 
465
    propname = "Enabled"
466
466
    value_to_set = dbus.Boolean(True)
467
467
 
468
468
class DisableCmd(PropertyCmd):
469
 
    property = "Enabled"
 
469
    propname = "Enabled"
470
470
    value_to_set = dbus.Boolean(False)
471
471
 
472
472
class BumpTimeoutCmd(PropertyCmd):
473
 
    property = "LastCheckedOK"
 
473
    propname = "LastCheckedOK"
474
474
    value_to_set = ""
475
475
 
476
476
class StartCheckerCmd(PropertyCmd):
477
 
    property = "CheckerRunning"
 
477
    propname = "CheckerRunning"
478
478
    value_to_set = dbus.Boolean(True)
479
479
 
480
480
class StopCheckerCmd(PropertyCmd):
481
 
    property = "CheckerRunning"
 
481
    propname = "CheckerRunning"
482
482
    value_to_set = dbus.Boolean(False)
483
483
 
484
484
class ApproveByDefaultCmd(PropertyCmd):
485
 
    property = "ApprovedByDefault"
 
485
    propname = "ApprovedByDefault"
486
486
    value_to_set = dbus.Boolean(True)
487
487
 
488
488
class DenyByDefaultCmd(PropertyCmd):
489
 
    property = "ApprovedByDefault"
 
489
    propname = "ApprovedByDefault"
490
490
    value_to_set = dbus.Boolean(False)
491
491
 
492
492
class SetCheckerCmd(PropertyCmd, ValueArgumentMixIn):
493
 
    property = "Checker"
 
493
    propname = "Checker"
494
494
 
495
495
class SetHostCmd(PropertyCmd, ValueArgumentMixIn):
496
 
    property = "Host"
 
496
    propname = "Host"
497
497
 
498
498
class SetSecretCmd(PropertyCmd, ValueArgumentMixIn):
 
499
    propname = "Secret"
499
500
    @property
500
501
    def value_to_set(self):
501
502
        return self._vts
504
505
        """When setting, read data from supplied file object"""
505
506
        self._vts = value.read()
506
507
        value.close()
507
 
    property = "Secret"
508
508
 
509
509
class SetTimeoutCmd(PropertyCmd, MillisecondsValueArgumentMixIn):
510
 
    property = "Timeout"
 
510
    propname = "Timeout"
511
511
 
512
512
class SetExtendedTimeoutCmd(PropertyCmd,
513
513
                            MillisecondsValueArgumentMixIn):
514
 
    property = "ExtendedTimeout"
 
514
    propname = "ExtendedTimeout"
515
515
 
516
516
class SetIntervalCmd(PropertyCmd, MillisecondsValueArgumentMixIn):
517
 
    property = "Interval"
 
517
    propname = "Interval"
518
518
 
519
519
class SetApprovalDelayCmd(PropertyCmd,
520
520
                          MillisecondsValueArgumentMixIn):
521
 
    property = "ApprovalDelay"
 
521
    propname = "ApprovalDelay"
522
522
 
523
523
class SetApprovalDurationCmd(PropertyCmd,
524
524
                             MillisecondsValueArgumentMixIn):
525
 
    property = "ApprovalDuration"
 
525
    propname = "ApprovalDuration"
526
526
 
527
527
def add_command_line_options(parser):
528
528
    parser.add_argument("--version", action="version",
841
841
                self.attributes = attributes
842
842
                self.attributes["Name"] = name
843
843
                self.calls = []
844
 
            def Set(self, interface, property, value, dbus_interface):
845
 
                testcase.assertEqual(interface, client_interface)
846
 
                testcase.assertEqual(dbus_interface,
847
 
                                     dbus.PROPERTIES_IFACE)
848
 
                self.attributes[property] = value
849
 
            def Get(self, interface, property, dbus_interface):
850
 
                testcase.assertEqual(interface, client_interface)
851
 
                testcase.assertEqual(dbus_interface,
852
 
                                     dbus.PROPERTIES_IFACE)
853
 
                return self.attributes[property]
 
844
            def Set(self, interface, propname, value, dbus_interface):
 
845
                testcase.assertEqual(interface, client_interface)
 
846
                testcase.assertEqual(dbus_interface,
 
847
                                     dbus.PROPERTIES_IFACE)
 
848
                self.attributes[propname] = value
 
849
            def Get(self, interface, propname, dbus_interface):
 
850
                testcase.assertEqual(interface, client_interface)
 
851
                testcase.assertEqual(dbus_interface,
 
852
                                     dbus.PROPERTIES_IFACE)
 
853
                return self.attributes[propname]
854
854
            def Approve(self, approve, dbus_interface):
855
855
                testcase.assertEqual(dbus_interface, client_interface)
856
856
                self.calls.append(("Approve", (approve,
1079
1079
        for value_to_set, value_to_get in zip(self.values_to_set,
1080
1080
                                              values_to_get):
1081
1081
            for client in self.clients:
1082
 
                old_value = client.attributes[self.property]
 
1082
                old_value = client.attributes[self.propname]
1083
1083
                self.assertNotIsInstance(old_value, Unique)
1084
 
                client.attributes[self.property] = Unique()
 
1084
                client.attributes[self.propname] = Unique()
1085
1085
            self.run_command(value_to_set, self.clients)
1086
1086
            for client in self.clients:
1087
 
                value = client.attributes[self.property]
 
1087
                value = client.attributes[self.propname]
1088
1088
                self.assertNotIsInstance(value, Unique)
1089
1089
                self.assertEqual(value, value_to_get)
1090
1090
    def run_command(self, value, clients):
1092
1092
 
1093
1093
class TestBumpTimeoutCmd(TestPropertyCmd):
1094
1094
    command = BumpTimeoutCmd
1095
 
    property = "LastCheckedOK"
 
1095
    propname = "LastCheckedOK"
1096
1096
    values_to_set = [""]
1097
1097
 
1098
1098
class TestStartCheckerCmd(TestPropertyCmd):
1099
1099
    command = StartCheckerCmd
1100
 
    property = "CheckerRunning"
 
1100
    propname = "CheckerRunning"
1101
1101
    values_to_set = [dbus.Boolean(True)]
1102
1102
 
1103
1103
class TestStopCheckerCmd(TestPropertyCmd):
1104
1104
    command = StopCheckerCmd
1105
 
    property = "CheckerRunning"
 
1105
    propname = "CheckerRunning"
1106
1106
    values_to_set = [dbus.Boolean(False)]
1107
1107
 
1108
1108
class TestApproveByDefaultCmd(TestPropertyCmd):
1109
1109
    command = ApproveByDefaultCmd
1110
 
    property = "ApprovedByDefault"
 
1110
    propname = "ApprovedByDefault"
1111
1111
    values_to_set = [dbus.Boolean(True)]
1112
1112
 
1113
1113
class TestDenyByDefaultCmd(TestPropertyCmd):
1114
1114
    command = DenyByDefaultCmd
1115
 
    property = "ApprovedByDefault"
 
1115
    propname = "ApprovedByDefault"
1116
1116
    values_to_set = [dbus.Boolean(False)]
1117
1117
 
1118
1118
class TestValueArgumentPropertyCmd(TestPropertyCmd):
1127
1127
 
1128
1128
class TestSetCheckerCmd(TestValueArgumentPropertyCmd):
1129
1129
    command = SetCheckerCmd
1130
 
    property = "Checker"
 
1130
    propname = "Checker"
1131
1131
    values_to_set = ["", ":", "fping -q -- %s"]
1132
1132
 
1133
1133
class TestSetHostCmd(TestValueArgumentPropertyCmd):
1134
1134
    command = SetHostCmd
1135
 
    property = "Host"
 
1135
    propname = "Host"
1136
1136
    values_to_set = ["192.0.2.3", "foo.example.org"]
1137
1137
 
1138
1138
class TestSetSecretCmd(TestValueArgumentPropertyCmd):
1139
1139
    command = SetSecretCmd
1140
 
    property = "Secret"
 
1140
    propname = "Secret"
1141
1141
    values_to_set = [io.BytesIO(b""),
1142
1142
                     io.BytesIO(b"secret\0xyzzy\nbar")]
1143
1143
    values_to_get = [b"", b"secret\0xyzzy\nbar"]
1144
1144
 
1145
1145
class TestSetTimeoutCmd(TestValueArgumentPropertyCmd):
1146
1146
    command = SetTimeoutCmd
1147
 
    property = "Timeout"
 
1147
    propname = "Timeout"
1148
1148
    values_to_set = [datetime.timedelta(),
1149
1149
                     datetime.timedelta(minutes=5),
1150
1150
                     datetime.timedelta(seconds=1),
1154
1154
 
1155
1155
class TestSetExtendedTimeoutCmd(TestValueArgumentPropertyCmd):
1156
1156
    command = SetExtendedTimeoutCmd
1157
 
    property = "ExtendedTimeout"
 
1157
    propname = "ExtendedTimeout"
1158
1158
    values_to_set = [datetime.timedelta(),
1159
1159
                     datetime.timedelta(minutes=5),
1160
1160
                     datetime.timedelta(seconds=1),
1164
1164
 
1165
1165
class TestSetIntervalCmd(TestValueArgumentPropertyCmd):
1166
1166
    command = SetIntervalCmd
1167
 
    property = "Interval"
 
1167
    propname = "Interval"
1168
1168
    values_to_set = [datetime.timedelta(),
1169
1169
                     datetime.timedelta(minutes=5),
1170
1170
                     datetime.timedelta(seconds=1),
1174
1174
 
1175
1175
class TestSetApprovalDelayCmd(TestValueArgumentPropertyCmd):
1176
1176
    command = SetApprovalDelayCmd
1177
 
    property = "ApprovalDelay"
 
1177
    propname = "ApprovalDelay"
1178
1178
    values_to_set = [datetime.timedelta(),
1179
1179
                     datetime.timedelta(minutes=5),
1180
1180
                     datetime.timedelta(seconds=1),
1184
1184
 
1185
1185
class TestSetApprovalDurationCmd(TestValueArgumentPropertyCmd):
1186
1186
    command = SetApprovalDurationCmd
1187
 
    property = "ApprovalDuration"
 
1187
    propname = "ApprovalDuration"
1188
1188
    values_to_set = [datetime.timedelta(),
1189
1189
                     datetime.timedelta(minutes=5),
1190
1190
                     datetime.timedelta(seconds=1),