anycubic-cloud-api 0.4.36__tar.gz → 0.4.38__tar.gz
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.
- {anycubic_cloud_api-0.4.36/src/anycubic_cloud_api.egg-info → anycubic_cloud_api-0.4.38}/PKG-INFO +1 -1
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/pyproject.toml +1 -1
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/__init__.py +2 -1
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/api/functions.py +74 -8
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/lan.py +17 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/consumable.py +24 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/orders.py +114 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/printer.py +404 -17
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/project.py +10 -6
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/lan/client.py +51 -3
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/lan/commands.py +27 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/lan/handshake.py +15 -3
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38/src/anycubic_cloud_api.egg-info}/PKG-INFO +1 -1
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api.egg-info/SOURCES.txt +5 -1
- anycubic_cloud_api-0.4.38/tests/test_camera_kvs_0437.py +131 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_filament_change_0435.py +13 -5
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_lan_client.py +95 -5
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_lan_commands.py +194 -1
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_lan_handshake.py +32 -0
- anycubic_cloud_api-0.4.38/tests/test_lan_photon_p1_max.py +361 -0
- anycubic_cloud_api-0.4.38/tests/test_lan_photon_p1_max_print.py +746 -0
- anycubic_cloud_api-0.4.38/tests/test_slice_param_0437.py +98 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/COPYRIGHT +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/LICENSE +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/MANIFEST.in +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/README.md +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/setup.cfg +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/anycubic_api.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/api/base.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/api/mqtt.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/api_endpoints.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/const.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/enums.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/error_codes.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/mqtt.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/regions.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/files.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/gcode_file.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/print_response.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/print_speed_mode.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/printer_properties.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/printing_settings.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/exceptions/error_strings.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/exceptions/exceptions.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/helpers/helpers.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/lan/__init__.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/models/auth.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/models/cloud_upload.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/models/http.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/resources/anycubic_mqqt_tls_ca.crt +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/resources/anycubic_mqqt_tls_client.crt +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/resources/anycubic_mqqt_tls_client.key +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api.egg-info/dependency_links.txt +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api.egg-info/requires.txt +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api.egg-info/top_level.txt +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_auth_mode_fallback.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_axis_position.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_endpoint_urls.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_exchange_rate_limit.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_lan_reports.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_null_tolerant_parsing.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_partial_reports.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_print_reports_0434.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_printer_error_codes.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_printer_slot_0436.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_project_null_status.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_regions.py +0 -0
- {anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/tests/test_secondary_ace.py +0 -0
|
@@ -12,7 +12,7 @@ from .const.enums import (
|
|
|
12
12
|
AnycubicPrinterMaterialType,
|
|
13
13
|
AnycubicPrintStatus,
|
|
14
14
|
)
|
|
15
|
-
from .data_models.orders import AnycubicShengwangCredentials
|
|
15
|
+
from .data_models.orders import AnycubicKvsCredentials, AnycubicShengwangCredentials
|
|
16
16
|
from .data_models.printer import AnycubicPrinter
|
|
17
17
|
from .data_models.printer_properties import AnycubicAxisPosition
|
|
18
18
|
from .data_models.project import AnycubicProject
|
|
@@ -63,6 +63,7 @@ __all__ = [
|
|
|
63
63
|
"AnycubicPrinterMaterialType",
|
|
64
64
|
"AnycubicProject",
|
|
65
65
|
"AnycubicPropertiesNotLoaded",
|
|
66
|
+
"AnycubicKvsCredentials",
|
|
66
67
|
"AnycubicShengwangCredentials",
|
|
67
68
|
"__version__",
|
|
68
69
|
]
|
{anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/api/functions.py
RENAMED
|
@@ -32,6 +32,7 @@ from ..data_models.orders import (
|
|
|
32
32
|
AnycubicPrinterOrderRequest,
|
|
33
33
|
AnycubicPrinterQueryOrderRequest,
|
|
34
34
|
AnycubicProjectOrderRequest,
|
|
35
|
+
AnycubicKvsCredentials,
|
|
35
36
|
AnycubicShengwangCredentials,
|
|
36
37
|
AnycubicStartPrintRequestCloud,
|
|
37
38
|
AnycubicStartPrintRequestLocal,
|
|
@@ -449,6 +450,42 @@ class AnycubicAPIFunctions(AnycubicAPIBase):
|
|
|
449
450
|
|
|
450
451
|
return data
|
|
451
452
|
|
|
453
|
+
@staticmethod
|
|
454
|
+
def _lan_start_ams_settings(
|
|
455
|
+
order_request: AnycubicBaseOrderRequest,
|
|
456
|
+
) -> dict[str, Any] | None:
|
|
457
|
+
"""The filament mapping a local print start carries, or None.
|
|
458
|
+
|
|
459
|
+
Locally the cloud order's ``ams_info`` travels inside ``data`` as
|
|
460
|
+
``ams_settings``, with only the fields the printer was seen to accept.
|
|
461
|
+
"""
|
|
462
|
+
if order_request.order_id != AnycubicOrderID.START_PRINT:
|
|
463
|
+
return None
|
|
464
|
+
|
|
465
|
+
if not isinstance(order_request, AnycubicProjectCtrlOrderRequest):
|
|
466
|
+
return None
|
|
467
|
+
|
|
468
|
+
ams_info = order_request.ams_info
|
|
469
|
+
|
|
470
|
+
if not ams_info or not ams_info.get('ams_box_mapping'):
|
|
471
|
+
return None
|
|
472
|
+
|
|
473
|
+
mapping_keys = (
|
|
474
|
+
'paint_index',
|
|
475
|
+
'ams_index',
|
|
476
|
+
'paint_color',
|
|
477
|
+
'ams_color',
|
|
478
|
+
'material_type',
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
return {
|
|
482
|
+
'use_ams': True,
|
|
483
|
+
'ams_box_mapping': [
|
|
484
|
+
{key: entry.get(key) for key in mapping_keys}
|
|
485
|
+
for entry in ams_info['ams_box_mapping']
|
|
486
|
+
],
|
|
487
|
+
}
|
|
488
|
+
|
|
452
489
|
def _send_anycubic_order_over_lan(
|
|
453
490
|
self,
|
|
454
491
|
order_request: AnycubicBaseOrderRequest,
|
|
@@ -469,6 +506,23 @@ class AnycubicAPIFunctions(AnycubicAPIBase):
|
|
|
469
506
|
|
|
470
507
|
data = order_request.order_data
|
|
471
508
|
|
|
509
|
+
if command.default_data is not None:
|
|
510
|
+
data = {**command.default_data, **(data or {})}
|
|
511
|
+
|
|
512
|
+
ams_settings = self._lan_start_ams_settings(order_request)
|
|
513
|
+
|
|
514
|
+
if ams_settings is not None:
|
|
515
|
+
# A Kobra with an ACE refuses a local start without the order's
|
|
516
|
+
# filament mapping (10115, "The device cannot parse the file"),
|
|
517
|
+
# and starts it once the mapping and project_type 1 are added.
|
|
518
|
+
# Verified on a Kobra S1 with an ACE Pro. An order without a
|
|
519
|
+
# mapping (a resin printer, or no ACE) is sent as it was.
|
|
520
|
+
data = {
|
|
521
|
+
**(data or {}),
|
|
522
|
+
'project_type': 1,
|
|
523
|
+
'ams_settings': ams_settings,
|
|
524
|
+
}
|
|
525
|
+
|
|
472
526
|
if command.needs_taskid:
|
|
473
527
|
project_id = order_request.project_id
|
|
474
528
|
|
|
@@ -1066,8 +1120,13 @@ class AnycubicAPIFunctions(AnycubicAPIBase):
|
|
|
1066
1120
|
self,
|
|
1067
1121
|
printer: AnycubicPrinter,
|
|
1068
1122
|
raw_data: bool = False,
|
|
1069
|
-
) -> AnycubicShengwangCredentials | None | dict[str, Any]:
|
|
1070
|
-
"""Open the cloud camera and return per-session
|
|
1123
|
+
) -> AnycubicShengwangCredentials | AnycubicKvsCredentials | None | dict[str, Any]:
|
|
1124
|
+
"""Open the cloud camera and return per-session credentials.
|
|
1125
|
+
|
|
1126
|
+
Two transports exist. Most accounts get an Agora (``shengwang``)
|
|
1127
|
+
block; some get only ``data.token``, AWS credentials for a Kinesis
|
|
1128
|
+
Video WebRTC channel (#49). Agora wins when both are present, since
|
|
1129
|
+
that is what the slicer uses whenever the printer supports it.
|
|
1071
1130
|
|
|
1072
1131
|
The credentials are short lived and ``client_uid`` is issued fresh on
|
|
1073
1132
|
every call, so request them per viewing session rather than caching.
|
|
@@ -1094,9 +1153,7 @@ class AnycubicAPIFunctions(AnycubicAPIBase):
|
|
|
1094
1153
|
if raw_data:
|
|
1095
1154
|
return resp
|
|
1096
1155
|
|
|
1097
|
-
credentials =
|
|
1098
|
-
resp.get('data') or {}
|
|
1099
|
-
)
|
|
1156
|
+
credentials = _camera_credentials(resp.get('data') or {}, printer)
|
|
1100
1157
|
|
|
1101
1158
|
if credentials is not None:
|
|
1102
1159
|
return credentials
|
|
@@ -1122,9 +1179,7 @@ class AnycubicAPIFunctions(AnycubicAPIBase):
|
|
|
1122
1179
|
params=order_request.order_request_data
|
|
1123
1180
|
)
|
|
1124
1181
|
|
|
1125
|
-
credentials =
|
|
1126
|
-
resp.get('data') or {}
|
|
1127
|
-
)
|
|
1182
|
+
credentials = _camera_credentials(resp.get('data') or {}, printer)
|
|
1128
1183
|
|
|
1129
1184
|
if credentials is None:
|
|
1130
1185
|
# Genuinely nothing to stream: no camera on this printer.
|
|
@@ -2347,3 +2402,14 @@ class AnycubicAPIFunctions(AnycubicAPIBase):
|
|
|
2347
2402
|
light_on=light_on,
|
|
2348
2403
|
brightness=brightness,
|
|
2349
2404
|
)
|
|
2405
|
+
|
|
2406
|
+
|
|
2407
|
+
def _camera_credentials(
|
|
2408
|
+
data: dict[str, Any],
|
|
2409
|
+
printer: AnycubicPrinter,
|
|
2410
|
+
) -> AnycubicShengwangCredentials | AnycubicKvsCredentials | None:
|
|
2411
|
+
"""Whichever camera transport the cloud offered, Agora first."""
|
|
2412
|
+
return (
|
|
2413
|
+
AnycubicShengwangCredentials.from_order_response(data)
|
|
2414
|
+
or AnycubicKvsCredentials.from_order_response(data, printer.key)
|
|
2415
|
+
)
|
|
@@ -32,5 +32,22 @@ LAN_HTTP_TIMEOUT = 10
|
|
|
32
32
|
# see AnycubicLANHandshake for why that is the right trade-off here.
|
|
33
33
|
LAN_MQTT_DEFAULT_PORT = 9883
|
|
34
34
|
|
|
35
|
+
# Where a printer serves its camera once a local capture has been started.
|
|
36
|
+
# The Kobras name this address themselves in their info report; a Photon P1
|
|
37
|
+
# Max sends no info report and leaves the handshake's "rtsp" field empty, but
|
|
38
|
+
# serves the same FLV stream on the same port.
|
|
39
|
+
LAN_CAMERA_STREAM_PORT = 18088
|
|
40
|
+
LAN_CAMERA_STREAM_PATH = "/flv"
|
|
41
|
+
|
|
42
|
+
# How far the camera picture has to be turned, clockwise in degrees, to stand
|
|
43
|
+
# upright. A printer mounts its camera wherever it fits and serves the picture
|
|
44
|
+
# as the sensor sees it; nothing in the stream or in any report says which way
|
|
45
|
+
# is up, so it is recorded here per model as it is found. A Photon P1 Max
|
|
46
|
+
# (132) delivers its picture lying on its side.
|
|
47
|
+
LAN_CAMERA_ROTATION_BY_MODEL: dict[int, int] = {
|
|
48
|
+
132: 270,
|
|
49
|
+
}
|
|
50
|
+
LAN_CAMERA_ROTATIONS = (0, 90, 180, 270)
|
|
51
|
+
|
|
35
52
|
LAN_REQUIRED_INFO_FIELDS = ("token", "ctrlInfoUrl", "modelId")
|
|
36
53
|
LAN_REQUIRED_BROKER_FIELDS = ("broker", "username", "password", "deviceId")
|
|
@@ -114,3 +114,27 @@ class AnycubicConsumableData(UserDict[Any, Any]):
|
|
|
114
114
|
return self[key]
|
|
115
115
|
except KeyError:
|
|
116
116
|
return default
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def plain_data(value: Any) -> Any:
|
|
120
|
+
"""Unwrap AnycubicConsumableData into plain dicts and lists, all the way down.
|
|
121
|
+
|
|
122
|
+
MQTT payloads arrive wrapped, and every nested dict becomes another
|
|
123
|
+
AnycubicConsumableData -- a ``UserDict``, which ``isinstance(x, dict)``
|
|
124
|
+
rejects. Anything stored for later (slice parameters, settings) should be
|
|
125
|
+
unwrapped first. Reading through the wrapper also marks every key as
|
|
126
|
+
handled, so the copy doesn't leave the payload looking unread.
|
|
127
|
+
"""
|
|
128
|
+
if isinstance(value, AnycubicConsumableData):
|
|
129
|
+
unwrapped: dict[Any, Any] = {}
|
|
130
|
+
for key in list(value.data.keys()):
|
|
131
|
+
unwrapped[key] = plain_data(value.get(key))
|
|
132
|
+
# A nested block only counts as read once it is empty and is read
|
|
133
|
+
# again -- the same rule _drain() in printer.py follows.
|
|
134
|
+
value.get(key)
|
|
135
|
+
return unwrapped
|
|
136
|
+
if isinstance(value, dict):
|
|
137
|
+
return {key: plain_data(item) for key, item in value.items()}
|
|
138
|
+
if isinstance(value, list):
|
|
139
|
+
return [plain_data(item) for item in value]
|
|
140
|
+
return value
|
{anycubic_cloud_api-0.4.36 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/orders.py
RENAMED
|
@@ -234,6 +234,10 @@ class AnycubicProjectCtrlOrderRequest(AnycubicProjectOrderRequest):
|
|
|
234
234
|
else:
|
|
235
235
|
self._ams_info = None
|
|
236
236
|
|
|
237
|
+
@property
|
|
238
|
+
def ams_info(self) -> dict[str, Any] | None:
|
|
239
|
+
return self._ams_info
|
|
240
|
+
|
|
237
241
|
@property
|
|
238
242
|
def order_request_data(self) -> dict[str, Any]:
|
|
239
243
|
return {
|
|
@@ -638,3 +642,113 @@ class AnycubicShengwangCredentials:
|
|
|
638
642
|
f"device_uid={self._device_uid}, "
|
|
639
643
|
f"encryption_mode={self._encryption_mode})"
|
|
640
644
|
)
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
class AnycubicKvsCredentials:
|
|
648
|
+
"""Temporary AWS credentials for the camera's Kinesis Video WebRTC channel.
|
|
649
|
+
|
|
650
|
+
The other cloud camera transport. Some accounts get no Agora
|
|
651
|
+
(``shengwang``) block from CAMERA_OPEN at all, only ``data.token`` -- an
|
|
652
|
+
AWS STS triple plus a region (#49). Anycubic Slicer Next views those with
|
|
653
|
+
the Kinesis Video Streams WebRTC SDK as a VIEWER on the signalling channel
|
|
654
|
+
named after the printer's ``key``, so that is what ``channel_name`` holds.
|
|
655
|
+
|
|
656
|
+
Short lived; request per viewing session, never cache.
|
|
657
|
+
"""
|
|
658
|
+
|
|
659
|
+
__slots__ = (
|
|
660
|
+
"_region",
|
|
661
|
+
"_access_key_id",
|
|
662
|
+
"_secret_access_key",
|
|
663
|
+
"_session_token",
|
|
664
|
+
"_expiration",
|
|
665
|
+
"_channel_name",
|
|
666
|
+
"_msg_id",
|
|
667
|
+
)
|
|
668
|
+
|
|
669
|
+
def __init__(
|
|
670
|
+
self,
|
|
671
|
+
region: str,
|
|
672
|
+
access_key_id: str,
|
|
673
|
+
secret_access_key: str,
|
|
674
|
+
session_token: str,
|
|
675
|
+
channel_name: str,
|
|
676
|
+
expiration: int | None = None,
|
|
677
|
+
msg_id: str | None = None,
|
|
678
|
+
) -> None:
|
|
679
|
+
self._region = region
|
|
680
|
+
self._access_key_id = access_key_id
|
|
681
|
+
self._secret_access_key = secret_access_key
|
|
682
|
+
self._session_token = session_token
|
|
683
|
+
self._channel_name = channel_name
|
|
684
|
+
self._expiration = expiration
|
|
685
|
+
self._msg_id = msg_id
|
|
686
|
+
|
|
687
|
+
@classmethod
|
|
688
|
+
def from_order_response(
|
|
689
|
+
cls,
|
|
690
|
+
data: dict[str, Any],
|
|
691
|
+
channel_name: str | None,
|
|
692
|
+
) -> AnycubicKvsCredentials | None:
|
|
693
|
+
block = data.get('token')
|
|
694
|
+
|
|
695
|
+
if not isinstance(block, dict) or not channel_name:
|
|
696
|
+
return None
|
|
697
|
+
|
|
698
|
+
region = block.get('region')
|
|
699
|
+
access_key_id = block.get('tmpSecretId')
|
|
700
|
+
secret_access_key = block.get('tmpSecretKey')
|
|
701
|
+
session_token = block.get('sessionToken')
|
|
702
|
+
|
|
703
|
+
# The slicer refuses an incomplete set too ("AWS令牌信息不完整").
|
|
704
|
+
if not (region and access_key_id and secret_access_key and session_token):
|
|
705
|
+
return None
|
|
706
|
+
|
|
707
|
+
expiration = block.get('expiration')
|
|
708
|
+
|
|
709
|
+
return cls(
|
|
710
|
+
region=str(region),
|
|
711
|
+
access_key_id=str(access_key_id),
|
|
712
|
+
secret_access_key=str(secret_access_key),
|
|
713
|
+
session_token=str(session_token),
|
|
714
|
+
channel_name=str(channel_name),
|
|
715
|
+
expiration=int(expiration) if isinstance(expiration, (int, float)) else None,
|
|
716
|
+
msg_id=data.get('msgid'),
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
@property
|
|
720
|
+
def region(self) -> str:
|
|
721
|
+
return self._region
|
|
722
|
+
|
|
723
|
+
@property
|
|
724
|
+
def access_key_id(self) -> str:
|
|
725
|
+
return self._access_key_id
|
|
726
|
+
|
|
727
|
+
@property
|
|
728
|
+
def secret_access_key(self) -> str:
|
|
729
|
+
return self._secret_access_key
|
|
730
|
+
|
|
731
|
+
@property
|
|
732
|
+
def session_token(self) -> str:
|
|
733
|
+
return self._session_token
|
|
734
|
+
|
|
735
|
+
@property
|
|
736
|
+
def channel_name(self) -> str:
|
|
737
|
+
return self._channel_name
|
|
738
|
+
|
|
739
|
+
@property
|
|
740
|
+
def expiration(self) -> int | None:
|
|
741
|
+
"""As sent; the unit is not documented."""
|
|
742
|
+
return self._expiration
|
|
743
|
+
|
|
744
|
+
@property
|
|
745
|
+
def msg_id(self) -> str | None:
|
|
746
|
+
return self._msg_id
|
|
747
|
+
|
|
748
|
+
def __repr__(self) -> str:
|
|
749
|
+
# Never render any part of the credentials.
|
|
750
|
+
return (
|
|
751
|
+
f"AnycubicKvsCredentials("
|
|
752
|
+
f"region={self._region}, "
|
|
753
|
+
f"channel_name={self._channel_name})"
|
|
754
|
+
)
|