test: integrate reliable event recovery and receiving evidence
This commit is contained in:
@@ -32,10 +32,11 @@ def encoded(value):
|
||||
|
||||
|
||||
class State:
|
||||
def __init__(self, event_type, event_id, loading_plan_id, log_path=None):
|
||||
def __init__(self, event_type, event_id, loading_plan_id, log_path=None, container_booking_id=None):
|
||||
self.event_type = event_type
|
||||
self.selector_id = event_id
|
||||
self.plan_id = loading_plan_id
|
||||
self.booking_id = container_booking_id
|
||||
self.log_path = log_path
|
||||
self.lock = threading.Lock()
|
||||
self.mode = "PASS"
|
||||
@@ -65,9 +66,13 @@ class State:
|
||||
return None, False, None, 0, self.mode
|
||||
identity = {"eventId": event_id, "payloadHash": payload_hash.lower()}
|
||||
payload = event.get("payload")
|
||||
qualifies = event.get("eventType") == self.event_type and (
|
||||
event_id == self.selector_id if self.selector_id else
|
||||
isinstance(payload, dict) and str(payload.get("loadingPlanId")) == self.plan_id)
|
||||
if self.selector_id:
|
||||
selected = event_id == self.selector_id
|
||||
elif self.booking_id:
|
||||
selected = isinstance(payload, dict) and str(payload.get("sourceContainerBookingId")) == self.booking_id
|
||||
else:
|
||||
selected = isinstance(payload, dict) and str(payload.get("loadingPlanId")) == self.plan_id
|
||||
qualifies = event.get("eventType") == self.event_type and selected
|
||||
envelope_hash = hashlib.sha256(json.dumps(event, sort_keys=True, ensure_ascii=False,
|
||||
separators=(",", ":")).encode("utf-8")).hexdigest()
|
||||
with self.lock:
|
||||
@@ -254,6 +259,7 @@ def main():
|
||||
selector = parser.add_mutually_exclusive_group(required=True)
|
||||
selector.add_argument("--event-id")
|
||||
selector.add_argument("--loading-plan-id")
|
||||
selector.add_argument("--container-booking-id")
|
||||
parser.add_argument("--bind", default="127.0.0.1")
|
||||
parser.add_argument("--port", type=int, default=0)
|
||||
parser.add_argument("--control-port", type=int, default=0)
|
||||
@@ -270,9 +276,11 @@ def main():
|
||||
parser.error("event-id must be a UUID or ULID")
|
||||
if args.loading_plan_id and not re.fullmatch(r"[1-9][0-9]{0,19}", args.loading_plan_id):
|
||||
parser.error("loading-plan-id must be a positive decimal identifier")
|
||||
if args.container_booking_id and not re.fullmatch(r"[1-9][0-9]{0,19}", args.container_booking_id):
|
||||
parser.error("container-booking-id must be a positive decimal identifier")
|
||||
if not re.fullmatch(r"[A-Za-z][A-Za-z0-9]{0,79}", args.event_type) or not 0 < args.timeout <= 120:
|
||||
parser.error("invalid event type or timeout")
|
||||
state = State(args.event_type, args.event_id, args.loading_plan_id, args.log)
|
||||
state = State(args.event_type, args.event_id, args.loading_plan_id, args.log, args.container_booking_id)
|
||||
data = ThreadingHTTPServer((args.bind, args.port), data_handler(state, args.upstream, args.timeout))
|
||||
control = ThreadingHTTPServer(("127.0.0.1", args.control_port), control_handler(state, token))
|
||||
for server in (data, control):
|
||||
|
||||
Reference in New Issue
Block a user