uns-kit 0.2.5__tar.gz → 0.2.6__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.
Files changed (66) hide show
  1. {uns_kit-0.2.5 → uns_kit-0.2.6}/PKG-INFO +1 -1
  2. {uns_kit-0.2.5 → uns_kit-0.2.6}/pyproject.toml +1 -1
  3. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/cli.py +29 -26
  4. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/proxy.py +12 -0
  5. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/uns_mqtt_proxy.py +48 -0
  6. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/default/README.md +19 -9
  7. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/default/package.json +1 -1
  8. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/vscode/settings.json +2 -1
  9. {uns_kit-0.2.5 → uns_kit-0.2.6}/README.md +0 -0
  10. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/__init__.py +0 -0
  11. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/api/__init__.py +0 -0
  12. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/api/data_catalog.py +0 -0
  13. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/api/event_routing.py +0 -0
  14. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/api/interfaces.py +0 -0
  15. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/api/proxy.py +0 -0
  16. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/__init__.py +0 -0
  17. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/auth_client.py +0 -0
  18. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/client.py +0 -0
  19. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/config_file.py +0 -0
  20. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/config_schema.py +0 -0
  21. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/datahub_client.py +0 -0
  22. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/events.py +0 -0
  23. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/logger.py +0 -0
  24. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/packet.py +0 -0
  25. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/proxy_process.py +0 -0
  26. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/proxy_process_sync.py +0 -0
  27. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/runtime_metadata.py +0 -0
  28. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/runtime_service_registration.py +0 -0
  29. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/secret_resolver.py +0 -0
  30. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/secure_store.py +0 -0
  31. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/service_token_provider.py +0 -0
  32. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/state.py +0 -0
  33. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/status_monitor.py +0 -0
  34. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/topic_builder.py +0 -0
  35. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/topic_matcher.py +0 -0
  36. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/core/uns_path.py +0 -0
  37. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/cron/__init__.py +0 -0
  38. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/cron/proxy.py +0 -0
  39. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/database/__init__.py +0 -0
  40. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/database/client.py +0 -0
  41. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/database/params.py +0 -0
  42. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/database/schema.py +0 -0
  43. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/database/sql.py +0 -0
  44. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/database/types.py +0 -0
  45. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/service_bundle.py +0 -0
  46. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/api/src/api_routes.py +0 -0
  47. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/api/src/main.py +0 -0
  48. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/azure-pipelines.yml +0 -0
  49. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/cron/src/cron_example.py +0 -0
  50. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/data-offer/src/api_routes.py +0 -0
  51. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/data-offer/src/data_offers/__init__.py +0 -0
  52. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/data-offer/src/data_offers/demo_coils.py +0 -0
  53. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/data-offer/src/data_offers/demo_export.py +0 -0
  54. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/data-offer/src/data_offers/sql/demo_coils.sql +0 -0
  55. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/data-offer/src/data_offers/sql/demo_export.sql +0 -0
  56. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/data-offer/src/main.py +0 -0
  57. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/default/.gitignore +0 -0
  58. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/default/pyproject.toml +0 -0
  59. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/default/runtime.json +0 -0
  60. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/default/src/config/project_config_extension.example.py +0 -0
  61. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/default/src/config/project_config_extension.py +0 -0
  62. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/default/src/main.py +0 -0
  63. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/vscode/extensions.json +0 -0
  64. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/vscode/launch.json +0 -0
  65. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/templates/workspace/workspace.json +0 -0
  66. {uns_kit-0.2.5 → uns_kit-0.2.6}/src/uns_kit/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: uns-kit
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: Lightweight Python UNS MQTT client (pub/sub + infra topics)
5
5
  License: MIT
6
6
  Author: Aljoša Vister
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "uns-kit"
3
- version = "0.2.5"
3
+ version = "0.2.6"
4
4
  description = "Lightweight Python UNS MQTT client (pub/sub + infra topics)"
5
5
  authors = ["Aljoša Vister <aljosa.vister@gmail.com>"]
6
6
  license = "MIT"
@@ -32,7 +32,7 @@ CLI_PROG_NAME = "uns-kit-py"
32
32
  DEFAULT_UNS_DATAHUB_ADDON_METADATA = {
33
33
  "schemaVersion": 1,
34
34
  "kind": "addon",
35
- "controllerCompatibility": ">=7.1 <8",
35
+ "controllerCompatibility": ">=2 <3",
36
36
  }
37
37
 
38
38
 
@@ -216,6 +216,7 @@ def _scaffold_python_project(target_path: Path, project_name: str, *, allow_exis
216
216
 
217
217
  config_path = target_path / "config.json"
218
218
  _write_config_file(config_path, project_name)
219
+ _write_runtime_profiles(target_path, project_name)
219
220
  generate_config_schema(target_path)
220
221
 
221
222
  if pyproject_path.exists():
@@ -319,14 +320,14 @@ def _print_python_create_success(target_path: Path, initialized_git: bool) -> No
319
320
  click.echo(f" 1) cd {target_path}")
320
321
  click.echo(" 2) poetry install")
321
322
  click.echo(" 3) poetry run python src/main.py")
322
- click.echo(" 4) Edit config.json with your MQTT host/credentials")
323
+ click.echo(" 4) Copy a tracked config-development profile to config.json and set local secrets outside Git")
323
324
  if initialized_git:
324
325
  click.echo(" 5) git status # verify the new repository")
325
326
  return
326
327
 
327
328
  click.echo(" 1) poetry install")
328
329
  click.echo(" 2) poetry run python src/main.py")
329
- click.echo(" 3) Edit config.json with your MQTT host/credentials")
330
+ click.echo(" 3) Copy a tracked config-development profile to config.json and set local secrets outside Git")
330
331
  if initialized_git:
331
332
  click.echo(" 4) git status # verify the new repository")
332
333
 
@@ -454,38 +455,30 @@ def _log_python_devops_result(result: Dict[str, Any], *, include_remote_details:
454
455
  click.echo(" 2) Set AZURE_PAT in your CI or local env for pipeline access")
455
456
 
456
457
 
457
- def _write_config_file(path: Path, project_name: Optional[str] = None) -> None:
458
- project_name = project_name or path.resolve().parent.name
458
+ def _runtime_profile(project_name: str, profile: str) -> Dict[str, Any]:
459
459
  sanitized = TopicBuilder.sanitize_topic_part(project_name)
460
- data = {
460
+ is_host_development = profile == "development-host"
461
+ is_production = profile == "production"
462
+ return {
461
463
  "$schema": "./config.schema.json",
462
464
  "infra": {
463
- "host": "localhost",
465
+ "host": "localhost" if is_host_development else "mosquitto",
464
466
  "port": 1883,
465
- "username": "",
466
- "password": "",
467
467
  "tls": False,
468
468
  "clientId": sanitized,
469
469
  "mqttSubToTopics": [],
470
470
  "keepalive": 60,
471
471
  "clean": True,
472
472
  },
473
- "output": {
474
- "host": "localhost",
475
- },
476
- "input": {
477
- "host": "localhost",
478
- },
479
473
  "uns": {
480
474
  "graphql": "http://localhost:3200/graphql",
481
475
  "rest": "http://localhost:3200/api",
482
- "email": "admin@example.com",
483
- "password": "123",
484
476
  "processName": sanitized,
485
- "instanceMode": "force",
486
- "handover": False,
477
+ "instanceMode": "wait",
478
+ "handover": True,
487
479
  "jwksWellKnownUrl": "http://localhost:3200/api/.well-known/jwks.json",
488
480
  "kidWellKnownUrl": "http://localhost:3200/api/.well-known/kid",
481
+ "env": "prod" if is_production else "dev",
489
482
  "supervisor": {
490
483
  "enabled": False,
491
484
  "restartOnExit": False,
@@ -495,13 +488,23 @@ def _write_config_file(path: Path, project_name: Optional[str] = None) -> None:
495
488
  "restartCooldownMs": 300000,
496
489
  },
497
490
  },
498
- "devops": {
499
- "provider": "azure-devops",
500
- "organization": "example-org",
501
- "project": "example-project",
502
- },
503
491
  }
504
- path.write_text(json.dumps(data, indent=2) + "\n")
492
+
493
+
494
+ def _write_config_file(path: Path, project_name: Optional[str] = None) -> None:
495
+ project_name = project_name or path.resolve().parent.name
496
+ path.write_text(json.dumps(_runtime_profile(project_name, "development-host"), indent=2) + "\n")
497
+
498
+
499
+ def _write_runtime_profiles(target_path: Path, project_name: str) -> None:
500
+ profiles = {
501
+ "config-development-host.json": "development-host",
502
+ "config-development-podman.json": "development-podman",
503
+ "config-production.json": "production",
504
+ }
505
+ for filename, profile in profiles.items():
506
+ path = target_path / filename
507
+ path.write_text(json.dumps(_runtime_profile(project_name, profile), indent=2) + "\n")
505
508
 
506
509
 
507
510
  @cli.command("generate-config-schema", help="Generate config.schema.json from the core schema and project extension.")
@@ -675,7 +678,7 @@ def _merge_vscode_schema_mapping(settings_path: Path) -> None:
675
678
  raise click.ClickException(f"Expected json.schemas to be an array in {settings_path}.")
676
679
 
677
680
  mapping = {
678
- "fileMatch": ["config.json"],
681
+ "fileMatch": ["config.json", "config-*.json"],
679
682
  "url": "./config.schema.json",
680
683
  }
681
684
  if mapping not in schemas:
@@ -80,6 +80,18 @@ class UnsProxy:
80
80
  topic_object.setdefault("timestamp", isoformat(datetime.now(timezone.utc)))
81
81
  self._produced_topics[full_topic] = topic_object
82
82
  await self._emit_produced_topics()
83
+ return
84
+
85
+ existing = self._produced_topics[full_topic]
86
+ identity_keys = ("assetStableEntityId", "assetDisplayName", "assetIdentityProof")
87
+ identity_changed = any(existing.get(key) != topic_object.get(key) for key in identity_keys)
88
+ for key in identity_keys:
89
+ if key in topic_object:
90
+ existing[key] = topic_object[key]
91
+ else:
92
+ existing.pop(key, None)
93
+ if identity_changed:
94
+ await self._emit_produced_topics()
83
95
 
84
96
  async def _emit_produced_api_endpoints(self) -> None:
85
97
  await self.event.emit(
@@ -148,6 +148,28 @@ class UnsMqttProxy(UnsProxy):
148
148
  base_topic = mqtt_message.get("topic", "")
149
149
  asset = mqtt_message.get("asset")
150
150
  asset_description = mqtt_message.get("assetDescription")
151
+ asset_stable_entity_id = mqtt_message.get("assetStableEntityId")
152
+ asset_display_name = mqtt_message.get("assetDisplayName")
153
+ asset_identity_proof = mqtt_message.get("assetIdentityProof")
154
+ has_asset_identity_metadata = any(
155
+ value is not None
156
+ for value in (asset_stable_entity_id, asset_display_name, asset_identity_proof)
157
+ )
158
+ if has_asset_identity_metadata:
159
+ if (
160
+ not isinstance(asset_stable_entity_id, str)
161
+ or not asset_stable_entity_id.strip()
162
+ or not isinstance(asset_identity_proof, str)
163
+ or not asset_identity_proof.strip()
164
+ or (
165
+ asset_display_name is not None
166
+ and (not isinstance(asset_display_name, str) or not asset_display_name.strip())
167
+ )
168
+ ):
169
+ raise ValueError(
170
+ "Asset identity metadata requires assetStableEntityId and assetIdentityProof; "
171
+ "assetDisplayName must be non-empty when supplied."
172
+ )
151
173
  object_type = mqtt_message.get("objectType")
152
174
  object_type_description = mqtt_message.get("objectTypeDescription")
153
175
  object_id = mqtt_message.get("objectId")
@@ -193,6 +215,19 @@ class UnsMqttProxy(UnsProxy):
193
215
  "topic": base_topic,
194
216
  "asset": asset,
195
217
  "assetDescription": asset_description,
218
+ **(
219
+ {
220
+ "assetStableEntityId": asset_stable_entity_id.strip().lower(),
221
+ **(
222
+ {"assetDisplayName": asset_display_name.strip()}
223
+ if asset_display_name is not None
224
+ else {}
225
+ ),
226
+ "assetIdentityProof": asset_identity_proof.strip(),
227
+ }
228
+ if has_asset_identity_metadata
229
+ else {}
230
+ ),
196
231
  "objectType": object_type,
197
232
  "objectTypeDescription": object_type_description,
198
233
  "objectId": object_id,
@@ -348,6 +383,19 @@ class UnsMqttProxy(UnsProxy):
348
383
  "topic": base_topic,
349
384
  "asset": msg.get("asset"),
350
385
  "assetDescription": msg.get("assetDescription"),
386
+ **(
387
+ {
388
+ "assetStableEntityId": msg["assetStableEntityId"],
389
+ **(
390
+ {"assetDisplayName": msg["assetDisplayName"]}
391
+ if msg.get("assetDisplayName") is not None
392
+ else {}
393
+ ),
394
+ "assetIdentityProof": msg["assetIdentityProof"],
395
+ }
396
+ if msg.get("assetStableEntityId") is not None
397
+ else {}
398
+ ),
351
399
  "objectType": msg.get("objectType"),
352
400
  "objectTypeDescription": msg.get("objectTypeDescription"),
353
401
  "objectId": msg.get("objectId"),
@@ -63,18 +63,15 @@ These CLI helpers are useful for diagnostics and low-level checks. For applicati
63
63
 
64
64
  ## Datahub client (last value)
65
65
 
66
- `UnsClient` provides a minimal REST client for the UNS OpenHub API, including the batch last-value endpoint. For service-to-service access, prefer passing a long-lived service token directly. Use `AuthClient` only when you need user login/refresh behavior.
66
+ `UnsClient` provides a minimal REST client for the UNS OpenHub API, including the batch last-value endpoint. For service-to-service access, prefer the controller-managed token file or a development machine token. Use `AuthClient` only when you need user login/refresh behavior.
67
67
 
68
68
  ```python
69
69
  from pathlib import Path
70
- from uns_kit.core import ConfigFile, UnsClient
70
+ from uns_kit.core import ConfigFile, ServiceTokenProvider, UnsClient
71
71
 
72
72
  cfg = ConfigFile.load_config(Path("config.json"))
73
- client = UnsClient(
74
- cfg["uns"]["rest"],
75
- api_base_path="/api",
76
- token=cfg["uns"].get("token"),
77
- )
73
+ token_provider = ServiceTokenProvider(config_token=cfg["uns"].get("token"))
74
+ client = UnsClient(cfg["uns"]["rest"], api_base_path="/api", token_provider=token_provider)
78
75
 
79
76
  values = client.last_value([
80
77
  "raw/data/line-1/motor/main/temperature",
@@ -86,8 +83,21 @@ print(values)
86
83
  ## Status topics
87
84
  The default `src/main.py` starts an `UnsProxyProcess`, creates an output proxy, and publishes a sample UNS topic through that proxy.
88
85
 
89
- ## Config
90
- Edit `config.json` with your MQTT host/auth (TS-style nested infra/uns structure).
86
+ ## Configuration
87
+
88
+ The generated project contains three committed, credential-free runtime
89
+ profiles. Copy the appropriate profile to untracked `config.json` before
90
+ starting the process:
91
+
92
+ | Profile | Use it when | MQTT | Service credential |
93
+ |---|---|---|---|
94
+ | `config-development-host.json` | Running directly on the host | `localhost` | `UNS_SERVICE_TOKEN` in the process environment |
95
+ | `config-development-podman.json` | Deploying through a local Podman controller | `mosquitto` | Controller-managed `UNS_SERVICE_TOKEN_FILE` |
96
+ | `config-production.json` | Creating a production controller instance | `mosquitto` | Controller-managed token file or approved secret provider |
97
+
98
+ Do not put a service token, user email, password, MQTT password, or customer
99
+ endpoint into a committed profile. A controller-managed token file is read on
100
+ every request by `ServiceTokenProvider`, so rotations do not require a restart.
91
101
 
92
102
  ## Extend the config schema
93
103
  Edit `src/config/project_config_extension.py` and run:
@@ -6,7 +6,7 @@
6
6
  "unsDatahub": {
7
7
  "schemaVersion": 1,
8
8
  "kind": "addon",
9
- "controllerCompatibility": ">=7.1 <8"
9
+ "controllerCompatibility": ">=2 <3"
10
10
  },
11
11
  "scripts": {
12
12
  "generate-config-schema": "poetry run uns-kit-py generate-config-schema"
@@ -9,7 +9,8 @@
9
9
  "json.schemas": [
10
10
  {
11
11
  "fileMatch": [
12
- "config.json"
12
+ "config.json",
13
+ "config-*.json"
13
14
  ],
14
15
  "url": "./config.schema.json"
15
16
  }
File without changes
File without changes
File without changes