cap-sdk-python 2.13.3__py3-none-any.whl → 2.16.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cap/__init__.py +92 -25
- cap/client.py +14 -11
- cap/handshake.py +24 -13
- cap/heartbeat.py +56 -36
- cap/metrics.py +16 -1
- cap/packet_boundary.py +155 -0
- cap/pb/cordum/agent/v1/alert_pb2_grpc.py +1 -1
- cap/pb/cordum/agent/v1/buspacket_pb2.py +4 -2
- cap/pb/cordum/agent/v1/buspacket_pb2_grpc.py +1 -1
- cap/pb/cordum/agent/v1/handshake_pb2.py +22 -7
- cap/pb/cordum/agent/v1/handshake_pb2_grpc.py +1 -1
- cap/pb/cordum/agent/v1/heartbeat_pb2_grpc.py +1 -1
- cap/pb/cordum/agent/v1/job_pb2.py +42 -35
- cap/pb/cordum/agent/v1/job_pb2_grpc.py +1 -1
- cap/pb/cordum/agent/v1/policy_pb2_grpc.py +1 -1
- cap/pb/cordum/agent/v1/safety_pb2.py +28 -28
- cap/pb/cordum/agent/v1/safety_pb2_grpc.py +1 -1
- cap/production_events.py +222 -0
- cap/production_replay.py +79 -0
- cap/production_resource.py +163 -0
- cap/production_signing.py +293 -0
- cap/production_validation.py +50 -0
- cap/progress.py +25 -23
- cap/py.typed +1 -0
- cap/runtime.py +882 -116
- cap/subjects.py +2 -0
- cap/testing.py +10 -2
- cap/trust_signing.py +148 -0
- cap/validate.py +119 -78
- cap/worker.py +272 -121
- cap/worker_trust.py +223 -0
- cap/worker_trust_async.py +85 -0
- cap/worker_trust_build.py +128 -0
- cap/worker_trust_codec.py +34 -0
- cap/worker_trust_runtime.py +272 -0
- cap/worker_trust_runtime_config.py +148 -0
- cap/worker_trust_validate.py +213 -0
- cap/worker_trust_verify.py +117 -0
- cap_sdk_python-2.16.1.dist-info/METADATA +414 -0
- cap_sdk_python-2.16.1.dist-info/RECORD +54 -0
- cap_sdk_python-2.16.1.dist-info/licenses/LICENSE +190 -0
- cap_sdk_python-2.13.3.dist-info/METADATA +0 -241
- cap_sdk_python-2.13.3.dist-info/RECORD +0 -37
- {cap_sdk_python-2.13.3.dist-info → cap_sdk_python-2.16.1.dist-info}/WHEEL +0 -0
- {cap_sdk_python-2.13.3.dist-info → cap_sdk_python-2.16.1.dist-info}/top_level.txt +0 -0
cap/progress.py
CHANGED
|
@@ -5,12 +5,12 @@ These helpers build and publish progress/cancel BusPacket envelopes.
|
|
|
5
5
|
|
|
6
6
|
from typing import Optional
|
|
7
7
|
|
|
8
|
-
from cryptography.hazmat.primitives import hashes
|
|
9
8
|
from cryptography.hazmat.primitives.asymmetric import ec
|
|
10
9
|
from google.protobuf import timestamp_pb2
|
|
11
10
|
|
|
12
11
|
from cap.client import DEFAULT_PROTOCOL_VERSION
|
|
13
12
|
from cap.pb.cordum.agent.v1 import buspacket_pb2, job_pb2
|
|
13
|
+
from cap.packet_boundary import Publisher, finalize_packet, parse_packet
|
|
14
14
|
from cap.subjects import SUBJECT_CANCEL, SUBJECT_PROGRESS
|
|
15
15
|
|
|
16
16
|
|
|
@@ -20,12 +20,15 @@ def progress_payload(
|
|
|
20
20
|
step_id: str,
|
|
21
21
|
percent: int,
|
|
22
22
|
message: str,
|
|
23
|
+
*,
|
|
24
|
+
session_token: Optional[str] = None,
|
|
23
25
|
) -> bytes:
|
|
24
26
|
"""Build a progress payload wrapped in a BusPacket envelope."""
|
|
25
27
|
ts = timestamp_pb2.Timestamp()
|
|
26
28
|
ts.GetCurrentTime()
|
|
27
29
|
|
|
28
30
|
packet = buspacket_pb2.BusPacket()
|
|
31
|
+
packet.trace_id = job_id
|
|
29
32
|
packet.sender_id = sender_id
|
|
30
33
|
packet.protocol_version = DEFAULT_PROTOCOL_VERSION
|
|
31
34
|
packet.created_at.CopyFrom(ts)
|
|
@@ -37,7 +40,8 @@ def progress_payload(
|
|
|
37
40
|
message=message,
|
|
38
41
|
)
|
|
39
42
|
)
|
|
40
|
-
|
|
43
|
+
outgoing = finalize_packet(packet, session_token=session_token)
|
|
44
|
+
return outgoing.SerializeToString(deterministic=True)
|
|
41
45
|
|
|
42
46
|
|
|
43
47
|
def cancel_payload(
|
|
@@ -45,12 +49,15 @@ def cancel_payload(
|
|
|
45
49
|
job_id: str,
|
|
46
50
|
reason: str,
|
|
47
51
|
requested_by: str,
|
|
52
|
+
*,
|
|
53
|
+
session_token: Optional[str] = None,
|
|
48
54
|
) -> bytes:
|
|
49
55
|
"""Build a cancel payload wrapped in a BusPacket envelope."""
|
|
50
56
|
ts = timestamp_pb2.Timestamp()
|
|
51
57
|
ts.GetCurrentTime()
|
|
52
58
|
|
|
53
59
|
packet = buspacket_pb2.BusPacket()
|
|
60
|
+
packet.trace_id = job_id
|
|
54
61
|
packet.sender_id = sender_id
|
|
55
62
|
packet.protocol_version = DEFAULT_PROTOCOL_VERSION
|
|
56
63
|
packet.created_at.CopyFrom(ts)
|
|
@@ -61,40 +68,35 @@ def cancel_payload(
|
|
|
61
68
|
requested_by=requested_by,
|
|
62
69
|
)
|
|
63
70
|
)
|
|
64
|
-
|
|
71
|
+
outgoing = finalize_packet(packet, session_token=session_token)
|
|
72
|
+
return outgoing.SerializeToString(deterministic=True)
|
|
65
73
|
|
|
66
74
|
|
|
67
75
|
async def emit_progress(
|
|
68
|
-
nc,
|
|
76
|
+
nc: Publisher,
|
|
69
77
|
payload: bytes,
|
|
70
78
|
private_key: Optional[ec.EllipticCurvePrivateKey] = None,
|
|
79
|
+
*,
|
|
80
|
+
session_token: Optional[str] = None,
|
|
71
81
|
) -> None:
|
|
72
82
|
"""Publish one progress packet to the progress subject."""
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
packet.ClearField("signature")
|
|
78
|
-
unsigned_data = packet.SerializeToString(deterministic=True)
|
|
79
|
-
packet.signature = private_key.sign(unsigned_data, ec.ECDSA(hashes.SHA256()))
|
|
80
|
-
data = packet.SerializeToString(deterministic=True)
|
|
81
|
-
|
|
83
|
+
packet = finalize_packet(
|
|
84
|
+
parse_packet(payload), private_key, session_token=session_token
|
|
85
|
+
)
|
|
86
|
+
data = packet.SerializeToString(deterministic=True)
|
|
82
87
|
await nc.publish(SUBJECT_PROGRESS, data)
|
|
83
88
|
|
|
84
89
|
|
|
85
90
|
async def emit_cancel(
|
|
86
|
-
nc,
|
|
91
|
+
nc: Publisher,
|
|
87
92
|
payload: bytes,
|
|
88
93
|
private_key: Optional[ec.EllipticCurvePrivateKey] = None,
|
|
94
|
+
*,
|
|
95
|
+
session_token: Optional[str] = None,
|
|
89
96
|
) -> None:
|
|
90
97
|
"""Publish one cancel packet to the cancel subject."""
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
packet.ClearField("signature")
|
|
96
|
-
unsigned_data = packet.SerializeToString(deterministic=True)
|
|
97
|
-
packet.signature = private_key.sign(unsigned_data, ec.ECDSA(hashes.SHA256()))
|
|
98
|
-
data = packet.SerializeToString(deterministic=True)
|
|
99
|
-
|
|
98
|
+
packet = finalize_packet(
|
|
99
|
+
parse_packet(payload), private_key, session_token=session_token
|
|
100
|
+
)
|
|
101
|
+
data = packet.SerializeToString(deterministic=True)
|
|
100
102
|
await nc.publish(SUBJECT_CANCEL, data)
|
cap/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|