ominfra 0.0.0.dev148__py3-none-any.whl → 0.0.0.dev150__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- ominfra/clouds/aws/auth.py +7 -9
- ominfra/clouds/aws/cli.py +1 -1
- ominfra/clouds/aws/journald2aws/driver.py +4 -4
- ominfra/clouds/aws/logs.py +4 -5
- ominfra/clouds/gcp/auth.py +1 -1
- ominfra/configs.py +3 -4
- ominfra/journald/messages.py +3 -3
- ominfra/journald/tailer.py +2 -2
- ominfra/manage/commands/base.py +2 -2
- ominfra/manage/commands/interp.py +3 -3
- ominfra/manage/commands/subprocess.py +3 -4
- ominfra/manage/deploy/paths.py +12 -15
- ominfra/manage/main.py +72 -75
- ominfra/manage/remote/_main.py +6 -7
- ominfra/manage/remote/execution.py +7 -10
- ominfra/manage/remote/spawning.py +3 -3
- ominfra/scripts/journald2aws.py +508 -147
- ominfra/scripts/manage.py +772 -183
- ominfra/scripts/supervisor.py +1144 -783
- ominfra/supervisor/dispatchers.py +1 -1
- ominfra/supervisor/groupsimpl.py +2 -2
- ominfra/supervisor/http.py +7 -7
- ominfra/supervisor/inject.py +4 -4
- ominfra/supervisor/io.py +1 -1
- ominfra/supervisor/main.py +1 -1
- ominfra/supervisor/processimpl.py +2 -2
- ominfra/supervisor/spawningimpl.py +9 -10
- ominfra/supervisor/supervisor.py +3 -3
- ominfra/supervisor/types.py +1 -1
- ominfra/tailscale/cli.py +1 -1
- {ominfra-0.0.0.dev148.dist-info → ominfra-0.0.0.dev150.dist-info}/METADATA +3 -3
- {ominfra-0.0.0.dev148.dist-info → ominfra-0.0.0.dev150.dist-info}/RECORD +36 -36
- {ominfra-0.0.0.dev148.dist-info → ominfra-0.0.0.dev150.dist-info}/LICENSE +0 -0
- {ominfra-0.0.0.dev148.dist-info → ominfra-0.0.0.dev150.dist-info}/WHEEL +0 -0
- {ominfra-0.0.0.dev148.dist-info → ominfra-0.0.0.dev150.dist-info}/entry_points.txt +0 -0
- {ominfra-0.0.0.dev148.dist-info → ominfra-0.0.0.dev150.dist-info}/top_level.txt +0 -0
ominfra/scripts/journald2aws.py
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
import abc
|
8
8
|
import argparse
|
9
9
|
import base64
|
10
|
+
import collections
|
10
11
|
import collections.abc
|
11
12
|
import contextlib
|
12
13
|
import dataclasses as dc
|
@@ -62,6 +63,11 @@ CallableT = ta.TypeVar('CallableT', bound=ta.Callable)
|
|
62
63
|
|
63
64
|
# ../../../../omlish/lite/check.py
|
64
65
|
SizedT = ta.TypeVar('SizedT', bound=ta.Sized)
|
66
|
+
CheckMessage = ta.Union[str, ta.Callable[..., ta.Optional[str]], None] # ta.TypeAlias
|
67
|
+
CheckLateConfigureFn = ta.Callable[['Checks'], None]
|
68
|
+
CheckOnRaiseFn = ta.Callable[[Exception], None] # ta.TypeAlias
|
69
|
+
CheckExceptionFactory = ta.Callable[..., Exception] # ta.TypeAlias
|
70
|
+
CheckArgsRenderer = ta.Callable[..., ta.Optional[str]] # ta.TypeAlias
|
65
71
|
|
66
72
|
# ../../../../omlish/lite/contextmanagers.py
|
67
73
|
ExitStackedT = ta.TypeVar('ExitStackedT', bound='ExitStacked')
|
@@ -952,99 +958,454 @@ def async_cached_nullary(fn): # ta.Callable[..., T]) -> ta.Callable[..., T]:
|
|
952
958
|
|
953
959
|
########################################
|
954
960
|
# ../../../../../omlish/lite/check.py
|
961
|
+
"""
|
962
|
+
TODO:
|
963
|
+
- def maybe(v: lang.Maybe[T])
|
964
|
+
- patch / override lite.check ?
|
965
|
+
- checker interface?
|
966
|
+
"""
|
967
|
+
|
968
|
+
|
969
|
+
##
|
970
|
+
|
971
|
+
|
972
|
+
class Checks:
|
973
|
+
def __init__(self) -> None:
|
974
|
+
super().__init__()
|
975
|
+
|
976
|
+
self._config_lock = threading.RLock()
|
977
|
+
self._on_raise_fns: ta.Sequence[CheckOnRaiseFn] = []
|
978
|
+
self._exception_factory: CheckExceptionFactory = Checks.default_exception_factory
|
979
|
+
self._args_renderer: ta.Optional[CheckArgsRenderer] = None
|
980
|
+
self._late_configure_fns: ta.Sequence[CheckLateConfigureFn] = []
|
981
|
+
|
982
|
+
@staticmethod
|
983
|
+
def default_exception_factory(exc_cls: ta.Type[Exception], *args, **kwargs) -> Exception:
|
984
|
+
return exc_cls(*args, **kwargs) # noqa
|
985
|
+
|
986
|
+
#
|
987
|
+
|
988
|
+
def register_on_raise(self, fn: CheckOnRaiseFn) -> None:
|
989
|
+
with self._config_lock:
|
990
|
+
self._on_raise_fns = [*self._on_raise_fns, fn]
|
991
|
+
|
992
|
+
def unregister_on_raise(self, fn: CheckOnRaiseFn) -> None:
|
993
|
+
with self._config_lock:
|
994
|
+
self._on_raise_fns = [e for e in self._on_raise_fns if e != fn]
|
995
|
+
|
996
|
+
#
|
997
|
+
|
998
|
+
def set_exception_factory(self, factory: CheckExceptionFactory) -> None:
|
999
|
+
self._exception_factory = factory
|
1000
|
+
|
1001
|
+
def set_args_renderer(self, renderer: ta.Optional[CheckArgsRenderer]) -> None:
|
1002
|
+
self._args_renderer = renderer
|
1003
|
+
|
1004
|
+
#
|
1005
|
+
|
1006
|
+
def register_late_configure(self, fn: CheckLateConfigureFn) -> None:
|
1007
|
+
with self._config_lock:
|
1008
|
+
self._late_configure_fns = [*self._late_configure_fns, fn]
|
1009
|
+
|
1010
|
+
def _late_configure(self) -> None:
|
1011
|
+
if not self._late_configure_fns:
|
1012
|
+
return
|
1013
|
+
|
1014
|
+
with self._config_lock:
|
1015
|
+
if not (lc := self._late_configure_fns):
|
1016
|
+
return
|
1017
|
+
|
1018
|
+
for fn in lc:
|
1019
|
+
fn(self)
|
1020
|
+
|
1021
|
+
self._late_configure_fns = []
|
1022
|
+
|
1023
|
+
#
|
1024
|
+
|
1025
|
+
class _ArgsKwargs:
|
1026
|
+
def __init__(self, *args, **kwargs):
|
1027
|
+
self.args = args
|
1028
|
+
self.kwargs = kwargs
|
1029
|
+
|
1030
|
+
def _raise(
|
1031
|
+
self,
|
1032
|
+
exception_type: ta.Type[Exception],
|
1033
|
+
default_message: str,
|
1034
|
+
message: CheckMessage,
|
1035
|
+
ak: _ArgsKwargs = _ArgsKwargs(),
|
1036
|
+
*,
|
1037
|
+
render_fmt: ta.Optional[str] = None,
|
1038
|
+
) -> ta.NoReturn:
|
1039
|
+
exc_args = ()
|
1040
|
+
if callable(message):
|
1041
|
+
message = ta.cast(ta.Callable, message)(*ak.args, **ak.kwargs)
|
1042
|
+
if isinstance(message, tuple):
|
1043
|
+
message, *exc_args = message # type: ignore
|
1044
|
+
|
1045
|
+
if message is None:
|
1046
|
+
message = default_message
|
1047
|
+
|
1048
|
+
self._late_configure()
|
1049
|
+
|
1050
|
+
if render_fmt is not None and (af := self._args_renderer) is not None:
|
1051
|
+
rendered_args = af(render_fmt, *ak.args)
|
1052
|
+
if rendered_args is not None:
|
1053
|
+
message = f'{message} : {rendered_args}'
|
1054
|
+
|
1055
|
+
exc = self._exception_factory(
|
1056
|
+
exception_type,
|
1057
|
+
message,
|
1058
|
+
*exc_args,
|
1059
|
+
*ak.args,
|
1060
|
+
**ak.kwargs,
|
1061
|
+
)
|
1062
|
+
|
1063
|
+
for fn in self._on_raise_fns:
|
1064
|
+
fn(exc)
|
1065
|
+
|
1066
|
+
raise exc
|
1067
|
+
|
1068
|
+
#
|
1069
|
+
|
1070
|
+
def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
|
1071
|
+
if isinstance(spec, type):
|
1072
|
+
return (spec,)
|
1073
|
+
if not isinstance(spec, tuple):
|
1074
|
+
spec = (spec,)
|
1075
|
+
if None in spec:
|
1076
|
+
spec = tuple(filter(None, spec)) + (None.__class__,) # noqa
|
1077
|
+
if ta.Any in spec:
|
1078
|
+
spec = (object,)
|
1079
|
+
return spec
|
1080
|
+
|
1081
|
+
def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
|
1082
|
+
if not isinstance(v, self._unpack_isinstance_spec(spec)):
|
1083
|
+
self._raise(
|
1084
|
+
TypeError,
|
1085
|
+
'Must be instance',
|
1086
|
+
msg,
|
1087
|
+
Checks._ArgsKwargs(v, spec),
|
1088
|
+
render_fmt='not isinstance(%s, %s)',
|
1089
|
+
)
|
1090
|
+
|
1091
|
+
return v
|
1092
|
+
|
1093
|
+
def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
|
1094
|
+
def inner(v):
|
1095
|
+
return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
|
1096
|
+
|
1097
|
+
return inner
|
1098
|
+
|
1099
|
+
def cast(self, v: ta.Any, cls: ta.Type[T], msg: CheckMessage = None) -> T: # noqa
|
1100
|
+
if not isinstance(v, cls):
|
1101
|
+
self._raise(
|
1102
|
+
TypeError,
|
1103
|
+
'Must be instance',
|
1104
|
+
msg,
|
1105
|
+
Checks._ArgsKwargs(v, cls),
|
1106
|
+
)
|
1107
|
+
|
1108
|
+
return v
|
1109
|
+
|
1110
|
+
def of_cast(self, cls: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[T], T]:
|
1111
|
+
def inner(v):
|
1112
|
+
return self.cast(v, cls, msg)
|
1113
|
+
|
1114
|
+
return inner
|
1115
|
+
|
1116
|
+
def not_isinstance(self, v: T, spec: ta.Any, msg: CheckMessage = None) -> T: # noqa
|
1117
|
+
if isinstance(v, self._unpack_isinstance_spec(spec)):
|
1118
|
+
self._raise(
|
1119
|
+
TypeError,
|
1120
|
+
'Must not be instance',
|
1121
|
+
msg,
|
1122
|
+
Checks._ArgsKwargs(v, spec),
|
1123
|
+
render_fmt='isinstance(%s, %s)',
|
1124
|
+
)
|
1125
|
+
|
1126
|
+
return v
|
955
1127
|
|
1128
|
+
def of_not_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[T], T]:
|
1129
|
+
def inner(v):
|
1130
|
+
return self.not_isinstance(v, self._unpack_isinstance_spec(spec), msg)
|
956
1131
|
|
957
|
-
|
958
|
-
if not isinstance(v, spec):
|
959
|
-
raise TypeError(v)
|
960
|
-
return v
|
1132
|
+
return inner
|
961
1133
|
|
1134
|
+
##
|
962
1135
|
|
963
|
-
def
|
964
|
-
|
965
|
-
|
966
|
-
|
1136
|
+
def issubclass(self, v: ta.Type[T], spec: ta.Any, msg: CheckMessage = None) -> ta.Type[T]: # noqa
|
1137
|
+
if not issubclass(v, spec):
|
1138
|
+
self._raise(
|
1139
|
+
TypeError,
|
1140
|
+
'Must be subclass',
|
1141
|
+
msg,
|
1142
|
+
Checks._ArgsKwargs(v, spec),
|
1143
|
+
render_fmt='not issubclass(%s, %s)',
|
1144
|
+
)
|
1145
|
+
|
1146
|
+
return v
|
1147
|
+
|
1148
|
+
def not_issubclass(self, v: ta.Type[T], spec: ta.Any, msg: CheckMessage = None) -> ta.Type[T]: # noqa
|
1149
|
+
if issubclass(v, spec):
|
1150
|
+
self._raise(
|
1151
|
+
TypeError,
|
1152
|
+
'Must not be subclass',
|
1153
|
+
msg,
|
1154
|
+
Checks._ArgsKwargs(v, spec),
|
1155
|
+
render_fmt='issubclass(%s, %s)',
|
1156
|
+
)
|
1157
|
+
|
1158
|
+
return v
|
1159
|
+
|
1160
|
+
#
|
1161
|
+
|
1162
|
+
def in_(self, v: T, c: ta.Container[T], msg: CheckMessage = None) -> T:
|
1163
|
+
if v not in c:
|
1164
|
+
self._raise(
|
1165
|
+
ValueError,
|
1166
|
+
'Must be in',
|
1167
|
+
msg,
|
1168
|
+
Checks._ArgsKwargs(v, c),
|
1169
|
+
render_fmt='%s not in %s',
|
1170
|
+
)
|
1171
|
+
|
1172
|
+
return v
|
1173
|
+
|
1174
|
+
def not_in(self, v: T, c: ta.Container[T], msg: CheckMessage = None) -> T:
|
1175
|
+
if v in c:
|
1176
|
+
self._raise(
|
1177
|
+
ValueError,
|
1178
|
+
'Must not be in',
|
1179
|
+
msg,
|
1180
|
+
Checks._ArgsKwargs(v, c),
|
1181
|
+
render_fmt='%s in %s',
|
1182
|
+
)
|
1183
|
+
|
1184
|
+
return v
|
1185
|
+
|
1186
|
+
def empty(self, v: SizedT, msg: CheckMessage = None) -> SizedT:
|
1187
|
+
if len(v) != 0:
|
1188
|
+
self._raise(
|
1189
|
+
ValueError,
|
1190
|
+
'Must be empty',
|
1191
|
+
msg,
|
1192
|
+
Checks._ArgsKwargs(v),
|
1193
|
+
render_fmt='%s',
|
1194
|
+
)
|
1195
|
+
|
1196
|
+
return v
|
1197
|
+
|
1198
|
+
def iterempty(self, v: ta.Iterable[T], msg: CheckMessage = None) -> ta.Iterable[T]:
|
1199
|
+
it = iter(v)
|
1200
|
+
try:
|
1201
|
+
next(it)
|
1202
|
+
except StopIteration:
|
1203
|
+
pass
|
1204
|
+
else:
|
1205
|
+
self._raise(
|
1206
|
+
ValueError,
|
1207
|
+
'Must be empty',
|
1208
|
+
msg,
|
1209
|
+
Checks._ArgsKwargs(v),
|
1210
|
+
render_fmt='%s',
|
1211
|
+
)
|
1212
|
+
|
1213
|
+
return v
|
1214
|
+
|
1215
|
+
def not_empty(self, v: SizedT, msg: CheckMessage = None) -> SizedT:
|
1216
|
+
if len(v) == 0:
|
1217
|
+
self._raise(
|
1218
|
+
ValueError,
|
1219
|
+
'Must not be empty',
|
1220
|
+
msg,
|
1221
|
+
Checks._ArgsKwargs(v),
|
1222
|
+
render_fmt='%s',
|
1223
|
+
)
|
1224
|
+
|
1225
|
+
return v
|
1226
|
+
|
1227
|
+
def unique(self, it: ta.Iterable[T], msg: CheckMessage = None) -> ta.Iterable[T]:
|
1228
|
+
dupes = [e for e, c in collections.Counter(it).items() if c > 1]
|
1229
|
+
if dupes:
|
1230
|
+
self._raise(
|
1231
|
+
ValueError,
|
1232
|
+
'Must be unique',
|
1233
|
+
msg,
|
1234
|
+
Checks._ArgsKwargs(it, dupes),
|
1235
|
+
)
|
967
1236
|
|
1237
|
+
return it
|
968
1238
|
|
969
|
-
def
|
970
|
-
|
971
|
-
|
1239
|
+
def single(self, obj: ta.Iterable[T], message: CheckMessage = None) -> T:
|
1240
|
+
try:
|
1241
|
+
[value] = obj
|
1242
|
+
except ValueError:
|
1243
|
+
self._raise(
|
1244
|
+
ValueError,
|
1245
|
+
'Must be single',
|
1246
|
+
message,
|
1247
|
+
Checks._ArgsKwargs(obj),
|
1248
|
+
render_fmt='%s',
|
1249
|
+
)
|
972
1250
|
|
1251
|
+
return value
|
973
1252
|
|
974
|
-
def
|
975
|
-
|
976
|
-
|
977
|
-
|
1253
|
+
def opt_single(self, obj: ta.Iterable[T], message: CheckMessage = None) -> ta.Optional[T]:
|
1254
|
+
it = iter(obj)
|
1255
|
+
try:
|
1256
|
+
value = next(it)
|
1257
|
+
except StopIteration:
|
1258
|
+
return None
|
978
1259
|
|
1260
|
+
try:
|
1261
|
+
next(it)
|
1262
|
+
except StopIteration:
|
1263
|
+
return value # noqa
|
1264
|
+
|
1265
|
+
self._raise(
|
1266
|
+
ValueError,
|
1267
|
+
'Must be empty or single',
|
1268
|
+
message,
|
1269
|
+
Checks._ArgsKwargs(obj),
|
1270
|
+
render_fmt='%s',
|
1271
|
+
)
|
979
1272
|
|
980
|
-
|
981
|
-
if v:
|
982
|
-
raise ValueError(v)
|
983
|
-
return v
|
1273
|
+
raise RuntimeError # noqa
|
984
1274
|
|
1275
|
+
#
|
985
1276
|
|
986
|
-
def
|
987
|
-
|
988
|
-
|
989
|
-
|
1277
|
+
def none(self, v: ta.Any, msg: CheckMessage = None) -> None:
|
1278
|
+
if v is not None:
|
1279
|
+
self._raise(
|
1280
|
+
ValueError,
|
1281
|
+
'Must be None',
|
1282
|
+
msg,
|
1283
|
+
Checks._ArgsKwargs(v),
|
1284
|
+
render_fmt='%s',
|
1285
|
+
)
|
990
1286
|
|
1287
|
+
def not_none(self, v: ta.Optional[T], msg: CheckMessage = None) -> T:
|
1288
|
+
if v is None:
|
1289
|
+
self._raise(
|
1290
|
+
ValueError,
|
1291
|
+
'Must not be None',
|
1292
|
+
msg,
|
1293
|
+
Checks._ArgsKwargs(v),
|
1294
|
+
render_fmt='%s',
|
1295
|
+
)
|
991
1296
|
|
992
|
-
|
993
|
-
if not v:
|
994
|
-
raise ValueError(msg)
|
1297
|
+
return v
|
995
1298
|
|
1299
|
+
#
|
996
1300
|
|
997
|
-
def
|
998
|
-
|
999
|
-
|
1000
|
-
|
1301
|
+
def equal(self, v: T, o: ta.Any, msg: CheckMessage = None) -> T:
|
1302
|
+
if o != v:
|
1303
|
+
self._raise(
|
1304
|
+
ValueError,
|
1305
|
+
'Must be equal',
|
1306
|
+
msg,
|
1307
|
+
Checks._ArgsKwargs(v, o),
|
1308
|
+
render_fmt='%s != %s',
|
1309
|
+
)
|
1001
1310
|
|
1311
|
+
return v
|
1002
1312
|
|
1003
|
-
def
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1313
|
+
def is_(self, v: T, o: ta.Any, msg: CheckMessage = None) -> T:
|
1314
|
+
if o is not v:
|
1315
|
+
self._raise(
|
1316
|
+
ValueError,
|
1317
|
+
'Must be the same',
|
1318
|
+
msg,
|
1319
|
+
Checks._ArgsKwargs(v, o),
|
1320
|
+
render_fmt='%s is not %s',
|
1321
|
+
)
|
1007
1322
|
|
1323
|
+
return v
|
1008
1324
|
|
1009
|
-
def
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1325
|
+
def is_not(self, v: T, o: ta.Any, msg: CheckMessage = None) -> T:
|
1326
|
+
if o is v:
|
1327
|
+
self._raise(
|
1328
|
+
ValueError,
|
1329
|
+
'Must not be the same',
|
1330
|
+
msg,
|
1331
|
+
Checks._ArgsKwargs(v, o),
|
1332
|
+
render_fmt='%s is %s',
|
1333
|
+
)
|
1013
1334
|
|
1335
|
+
return v
|
1014
1336
|
|
1015
|
-
def
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1337
|
+
def callable(self, v: T, msg: CheckMessage = None) -> T: # noqa
|
1338
|
+
if not callable(v):
|
1339
|
+
self._raise(
|
1340
|
+
TypeError,
|
1341
|
+
'Must be callable',
|
1342
|
+
msg,
|
1343
|
+
Checks._ArgsKwargs(v),
|
1344
|
+
render_fmt='%s',
|
1345
|
+
)
|
1019
1346
|
|
1347
|
+
return v # type: ignore
|
1020
1348
|
|
1021
|
-
def
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1349
|
+
def non_empty_str(self, v: ta.Optional[str], msg: CheckMessage = None) -> str:
|
1350
|
+
if not isinstance(v, str) or not v:
|
1351
|
+
self._raise(
|
1352
|
+
ValueError,
|
1353
|
+
'Must be non-empty str',
|
1354
|
+
msg,
|
1355
|
+
Checks._ArgsKwargs(v),
|
1356
|
+
render_fmt='%s',
|
1357
|
+
)
|
1025
1358
|
|
1359
|
+
return v
|
1026
1360
|
|
1027
|
-
def
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1361
|
+
def replacing(self, expected: ta.Any, old: ta.Any, new: T, msg: CheckMessage = None) -> T:
|
1362
|
+
if old != expected:
|
1363
|
+
self._raise(
|
1364
|
+
ValueError,
|
1365
|
+
'Must be replacing',
|
1366
|
+
msg,
|
1367
|
+
Checks._ArgsKwargs(expected, old, new),
|
1368
|
+
render_fmt='%s -> %s -> %s',
|
1369
|
+
)
|
1031
1370
|
|
1371
|
+
return new
|
1032
1372
|
|
1033
|
-
def
|
1034
|
-
|
1035
|
-
|
1373
|
+
def replacing_none(self, old: ta.Any, new: T, msg: CheckMessage = None) -> T:
|
1374
|
+
if old is not None:
|
1375
|
+
self._raise(
|
1376
|
+
ValueError,
|
1377
|
+
'Must be replacing None',
|
1378
|
+
msg,
|
1379
|
+
Checks._ArgsKwargs(old, new),
|
1380
|
+
render_fmt='%s -> %s',
|
1381
|
+
)
|
1036
1382
|
|
1383
|
+
return new
|
1037
1384
|
|
1038
|
-
|
1039
|
-
if len(v):
|
1040
|
-
raise ValueError(v)
|
1041
|
-
return v
|
1385
|
+
#
|
1042
1386
|
|
1387
|
+
def arg(self, v: bool, msg: CheckMessage = None) -> None:
|
1388
|
+
if not v:
|
1389
|
+
self._raise(
|
1390
|
+
RuntimeError,
|
1391
|
+
'Argument condition not met',
|
1392
|
+
msg,
|
1393
|
+
Checks._ArgsKwargs(v),
|
1394
|
+
render_fmt='%s',
|
1395
|
+
)
|
1396
|
+
|
1397
|
+
def state(self, v: bool, msg: CheckMessage = None) -> None:
|
1398
|
+
if not v:
|
1399
|
+
self._raise(
|
1400
|
+
RuntimeError,
|
1401
|
+
'State condition not met',
|
1402
|
+
msg,
|
1403
|
+
Checks._ArgsKwargs(v),
|
1404
|
+
render_fmt='%s',
|
1405
|
+
)
|
1043
1406
|
|
1044
|
-
|
1045
|
-
|
1046
|
-
raise ValueError(v)
|
1047
|
-
return v
|
1407
|
+
|
1408
|
+
check = Checks()
|
1048
1409
|
|
1049
1410
|
|
1050
1411
|
########################################
|
@@ -1319,7 +1680,7 @@ class AwsSigner:
|
|
1319
1680
|
@staticmethod
|
1320
1681
|
def _host_from_url(url: str) -> str:
|
1321
1682
|
url_parts = urllib.parse.urlsplit(url)
|
1322
|
-
host =
|
1683
|
+
host = check.non_empty_str(url_parts.hostname)
|
1323
1684
|
default_ports = {
|
1324
1685
|
'http': 80,
|
1325
1686
|
'https': 443,
|
@@ -1333,7 +1694,7 @@ class AwsSigner:
|
|
1333
1694
|
def _lower_case_http_map(d: ta.Mapping[str, ta.Sequence[str]]) -> ta.Mapping[str, ta.Sequence[str]]:
|
1334
1695
|
o: ta.Dict[str, ta.List[str]] = {}
|
1335
1696
|
for k, vs in d.items():
|
1336
|
-
o.setdefault(k.lower(), []).extend(
|
1697
|
+
o.setdefault(k.lower(), []).extend(check.not_isinstance(vs, str))
|
1337
1698
|
return o
|
1338
1699
|
|
1339
1700
|
#
|
@@ -1366,12 +1727,12 @@ class AwsSigner:
|
|
1366
1727
|
])
|
1367
1728
|
|
1368
1729
|
def _validate_request(self, req: Request) -> None:
|
1369
|
-
|
1370
|
-
|
1730
|
+
check.non_empty_str(req.method)
|
1731
|
+
check.equal(req.method.upper(), req.method)
|
1371
1732
|
for k, vs in req.headers.items():
|
1372
|
-
|
1733
|
+
check.equal(k.strip(), k)
|
1373
1734
|
for v in vs:
|
1374
|
-
|
1735
|
+
check.equal(v.strip(), v)
|
1375
1736
|
|
1376
1737
|
|
1377
1738
|
AwsSigner._EMPTY_SHA256 = AwsSigner._sha256(b'') # noqa
|
@@ -1630,65 +1991,7 @@ class AwsDataclassMeta:
|
|
1630
1991
|
|
1631
1992
|
|
1632
1993
|
########################################
|
1633
|
-
# ../../../../../omlish/
|
1634
|
-
|
1635
|
-
|
1636
|
-
##
|
1637
|
-
|
1638
|
-
|
1639
|
-
class ExitStacked:
|
1640
|
-
_exit_stack: ta.Optional[contextlib.ExitStack] = None
|
1641
|
-
|
1642
|
-
def __enter__(self: ExitStackedT) -> ExitStackedT:
|
1643
|
-
check_state(self._exit_stack is None)
|
1644
|
-
es = self._exit_stack = contextlib.ExitStack()
|
1645
|
-
es.__enter__()
|
1646
|
-
return self
|
1647
|
-
|
1648
|
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
1649
|
-
if (es := self._exit_stack) is None:
|
1650
|
-
return None
|
1651
|
-
self._exit_contexts()
|
1652
|
-
return es.__exit__(exc_type, exc_val, exc_tb)
|
1653
|
-
|
1654
|
-
def _exit_contexts(self) -> None:
|
1655
|
-
pass
|
1656
|
-
|
1657
|
-
def _enter_context(self, cm: ta.ContextManager[T]) -> T:
|
1658
|
-
es = check_not_none(self._exit_stack)
|
1659
|
-
return es.enter_context(cm)
|
1660
|
-
|
1661
|
-
|
1662
|
-
##
|
1663
|
-
|
1664
|
-
|
1665
|
-
@contextlib.contextmanager
|
1666
|
-
def defer(fn: ta.Callable) -> ta.Generator[ta.Callable, None, None]:
|
1667
|
-
try:
|
1668
|
-
yield fn
|
1669
|
-
finally:
|
1670
|
-
fn()
|
1671
|
-
|
1672
|
-
|
1673
|
-
@contextlib.contextmanager
|
1674
|
-
def attr_setting(obj, attr, val, *, default=None): # noqa
|
1675
|
-
not_set = object()
|
1676
|
-
orig = getattr(obj, attr, not_set)
|
1677
|
-
try:
|
1678
|
-
setattr(obj, attr, val)
|
1679
|
-
if orig is not not_set:
|
1680
|
-
yield orig
|
1681
|
-
else:
|
1682
|
-
yield default
|
1683
|
-
finally:
|
1684
|
-
if orig is not_set:
|
1685
|
-
delattr(obj, attr)
|
1686
|
-
else:
|
1687
|
-
setattr(obj, attr, orig)
|
1688
|
-
|
1689
|
-
|
1690
|
-
########################################
|
1691
|
-
# ../../../../../omlish/lite/io.py
|
1994
|
+
# ../../../../../omlish/io/buffers.py
|
1692
1995
|
|
1693
1996
|
|
1694
1997
|
class DelimitingBuffer:
|
@@ -1722,7 +2025,7 @@ class DelimitingBuffer:
|
|
1722
2025
|
) -> None:
|
1723
2026
|
super().__init__()
|
1724
2027
|
|
1725
|
-
self._delimiters = frozenset(
|
2028
|
+
self._delimiters = frozenset(check.isinstance(d, int) for d in delimiters)
|
1726
2029
|
self._keep_ends = keep_ends
|
1727
2030
|
self._max_size = max_size
|
1728
2031
|
|
@@ -1753,7 +2056,7 @@ class DelimitingBuffer:
|
|
1753
2056
|
return r
|
1754
2057
|
|
1755
2058
|
def _append_and_reset(self, chunk: bytes) -> bytes:
|
1756
|
-
buf =
|
2059
|
+
buf = check.not_none(self._buf)
|
1757
2060
|
if not buf.tell():
|
1758
2061
|
return chunk
|
1759
2062
|
|
@@ -1875,7 +2178,7 @@ class IncrementalWriteBuffer:
|
|
1875
2178
|
) -> None:
|
1876
2179
|
super().__init__()
|
1877
2180
|
|
1878
|
-
|
2181
|
+
check.not_empty(data)
|
1879
2182
|
self._len = len(data)
|
1880
2183
|
self._write_size = write_size
|
1881
2184
|
|
@@ -1890,11 +2193,11 @@ class IncrementalWriteBuffer:
|
|
1890
2193
|
return self._len - self._pos
|
1891
2194
|
|
1892
2195
|
def write(self, fn: ta.Callable[[bytes], int]) -> int:
|
1893
|
-
lst =
|
2196
|
+
lst = check.not_empty(self._lst)
|
1894
2197
|
|
1895
2198
|
t = 0
|
1896
2199
|
for i, d in enumerate(lst): # noqa
|
1897
|
-
n = fn(
|
2200
|
+
n = fn(check.not_empty(d))
|
1898
2201
|
if not n:
|
1899
2202
|
break
|
1900
2203
|
t += n
|
@@ -1909,6 +2212,64 @@ class IncrementalWriteBuffer:
|
|
1909
2212
|
return t
|
1910
2213
|
|
1911
2214
|
|
2215
|
+
########################################
|
2216
|
+
# ../../../../../omlish/lite/contextmanagers.py
|
2217
|
+
|
2218
|
+
|
2219
|
+
##
|
2220
|
+
|
2221
|
+
|
2222
|
+
class ExitStacked:
|
2223
|
+
_exit_stack: ta.Optional[contextlib.ExitStack] = None
|
2224
|
+
|
2225
|
+
def __enter__(self: ExitStackedT) -> ExitStackedT:
|
2226
|
+
check.state(self._exit_stack is None)
|
2227
|
+
es = self._exit_stack = contextlib.ExitStack()
|
2228
|
+
es.__enter__()
|
2229
|
+
return self
|
2230
|
+
|
2231
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
2232
|
+
if (es := self._exit_stack) is None:
|
2233
|
+
return None
|
2234
|
+
self._exit_contexts()
|
2235
|
+
return es.__exit__(exc_type, exc_val, exc_tb)
|
2236
|
+
|
2237
|
+
def _exit_contexts(self) -> None:
|
2238
|
+
pass
|
2239
|
+
|
2240
|
+
def _enter_context(self, cm: ta.ContextManager[T]) -> T:
|
2241
|
+
es = check.not_none(self._exit_stack)
|
2242
|
+
return es.enter_context(cm)
|
2243
|
+
|
2244
|
+
|
2245
|
+
##
|
2246
|
+
|
2247
|
+
|
2248
|
+
@contextlib.contextmanager
|
2249
|
+
def defer(fn: ta.Callable) -> ta.Generator[ta.Callable, None, None]:
|
2250
|
+
try:
|
2251
|
+
yield fn
|
2252
|
+
finally:
|
2253
|
+
fn()
|
2254
|
+
|
2255
|
+
|
2256
|
+
@contextlib.contextmanager
|
2257
|
+
def attr_setting(obj, attr, val, *, default=None): # noqa
|
2258
|
+
not_set = object()
|
2259
|
+
orig = getattr(obj, attr, not_set)
|
2260
|
+
try:
|
2261
|
+
setattr(obj, attr, val)
|
2262
|
+
if orig is not not_set:
|
2263
|
+
yield orig
|
2264
|
+
else:
|
2265
|
+
yield default
|
2266
|
+
finally:
|
2267
|
+
if orig is not_set:
|
2268
|
+
delattr(obj, attr)
|
2269
|
+
else:
|
2270
|
+
setattr(obj, attr, orig)
|
2271
|
+
|
2272
|
+
|
1912
2273
|
########################################
|
1913
2274
|
# ../../../../../omlish/lite/logs.py
|
1914
2275
|
"""
|
@@ -2220,10 +2581,10 @@ class ProxyObjMarshaler(ObjMarshaler):
|
|
2220
2581
|
m: ta.Optional[ObjMarshaler] = None
|
2221
2582
|
|
2222
2583
|
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2223
|
-
return
|
2584
|
+
return check.not_none(self.m).marshal(o, ctx)
|
2224
2585
|
|
2225
2586
|
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2226
|
-
return
|
2587
|
+
return check.not_none(self.m).unmarshal(o, ctx)
|
2227
2588
|
|
2228
2589
|
|
2229
2590
|
@dc.dataclass(frozen=True)
|
@@ -2382,19 +2743,19 @@ class DatetimeObjMarshaler(ObjMarshaler):
|
|
2382
2743
|
|
2383
2744
|
class DecimalObjMarshaler(ObjMarshaler):
|
2384
2745
|
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2385
|
-
return str(
|
2746
|
+
return str(check.isinstance(o, decimal.Decimal))
|
2386
2747
|
|
2387
2748
|
def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2388
|
-
return decimal.Decimal(
|
2749
|
+
return decimal.Decimal(check.isinstance(v, str))
|
2389
2750
|
|
2390
2751
|
|
2391
2752
|
class FractionObjMarshaler(ObjMarshaler):
|
2392
2753
|
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2393
|
-
fr =
|
2754
|
+
fr = check.isinstance(o, fractions.Fraction)
|
2394
2755
|
return [fr.numerator, fr.denominator]
|
2395
2756
|
|
2396
2757
|
def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
2397
|
-
num, denom =
|
2758
|
+
num, denom = check.isinstance(v, list)
|
2398
2759
|
return fractions.Fraction(num, denom)
|
2399
2760
|
|
2400
2761
|
|
@@ -2770,8 +3131,8 @@ class AwsLogMessageBuilder:
|
|
2770
3131
|
) -> None:
|
2771
3132
|
super().__init__()
|
2772
3133
|
|
2773
|
-
self._log_group_name =
|
2774
|
-
self._log_stream_name =
|
3134
|
+
self._log_group_name = check.non_empty_str(log_group_name)
|
3135
|
+
self._log_stream_name = check.non_empty_str(log_stream_name)
|
2775
3136
|
|
2776
3137
|
if url is None:
|
2777
3138
|
url = self.DEFAULT_URL.format(region_name=region_name)
|
@@ -2845,7 +3206,7 @@ class AwsLogMessageBuilder:
|
|
2845
3206
|
|
2846
3207
|
post = AwsLogMessageBuilder.Post(
|
2847
3208
|
url=self._url,
|
2848
|
-
headers={k:
|
3209
|
+
headers={k: check.single(v) for k, v in sig_req.headers.items()},
|
2849
3210
|
data=sig_req.payload,
|
2850
3211
|
)
|
2851
3212
|
|
@@ -2913,7 +3274,7 @@ def build_config_named_children(
|
|
2913
3274
|
lst: ta.List[ConfigMapping] = []
|
2914
3275
|
if isinstance(o, ta.Mapping):
|
2915
3276
|
for k, v in o.items():
|
2916
|
-
|
3277
|
+
check.isinstance(v, ta.Mapping)
|
2917
3278
|
if name_key in v:
|
2918
3279
|
n = v[name_key]
|
2919
3280
|
if k != n:
|
@@ -2923,7 +3284,7 @@ def build_config_named_children(
|
|
2923
3284
|
lst.append({name_key: k, **v})
|
2924
3285
|
|
2925
3286
|
else:
|
2926
|
-
|
3287
|
+
check.not_isinstance(o, str)
|
2927
3288
|
lst.extend(o)
|
2928
3289
|
|
2929
3290
|
seen = set()
|
@@ -3005,7 +3366,7 @@ class JournalctlMessageBuilder:
|
|
3005
3366
|
def feed(self, data: bytes) -> ta.Sequence[JournalctlMessage]:
|
3006
3367
|
ret: ta.List[JournalctlMessage] = []
|
3007
3368
|
for line in self._buf.feed(data):
|
3008
|
-
ret.append(self._make_message(
|
3369
|
+
ret.append(self._make_message(check.isinstance(line, bytes)))
|
3009
3370
|
return ret
|
3010
3371
|
|
3011
3372
|
|
@@ -3943,7 +4304,7 @@ class JournalctlTailerWorker(ThreadWorker):
|
|
3943
4304
|
stdout=subprocess.PIPE,
|
3944
4305
|
) as self._proc:
|
3945
4306
|
try:
|
3946
|
-
stdout =
|
4307
|
+
stdout = check.not_none(self._proc.stdout)
|
3947
4308
|
|
3948
4309
|
fd = stdout.fileno()
|
3949
4310
|
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
|
@@ -4075,15 +4436,15 @@ class JournalctlToAwsDriver(ExitStacked):
|
|
4075
4436
|
return None
|
4076
4437
|
|
4077
4438
|
return AwsSigner.Credentials(
|
4078
|
-
access_key_id=
|
4079
|
-
secret_access_key=
|
4439
|
+
access_key_id=check.non_empty_str(self._config.aws_access_key_id),
|
4440
|
+
secret_access_key=check.non_empty_str(self._config.aws_secret_access_key),
|
4080
4441
|
)
|
4081
4442
|
|
4082
4443
|
@cached_nullary
|
4083
4444
|
def _aws_log_message_builder(self) -> AwsLogMessageBuilder:
|
4084
4445
|
return AwsLogMessageBuilder(
|
4085
4446
|
log_group_name=self._config.aws_log_group_name,
|
4086
|
-
log_stream_name=
|
4447
|
+
log_stream_name=check.non_empty_str(self._config.aws_log_stream_name),
|
4087
4448
|
region_name=self._config.aws_region_name,
|
4088
4449
|
credentials=self._aws_credentials(),
|
4089
4450
|
)
|