peak-sdk 1.17.0__tar.gz → 1.18.0__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.
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/PKG-INFO +4 -3
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/_version.py +1 -1
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/cli.py +2 -1
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/helpers.py +1 -0
- peak_sdk-1.18.0/peak/cli/resources/cache.py +452 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/resources/__init__.py +2 -1
- peak_sdk-1.18.0/peak/resources/cache.py +650 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/pypi-home.md +2 -2
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/pyproject.toml +3 -2
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/LICENSE +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/_metadata.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/auth.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/base_client.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/callbacks.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/__init_.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/args.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/metrics/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/metrics/metrics.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/press/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/press/apps/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/press/apps/deployments.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/press/apps/specs.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/press/blocks/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/press/blocks/deployments.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/press/blocks/specs.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/press/deployments.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/press/specs.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/alerts/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/alerts/emails.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/artifacts.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/images.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/services.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/tenants.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/users.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/webapps.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/resources/workflows.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/ruff.toml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/cli/version.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/compression.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/config.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/constants.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/exceptions.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/handler.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/helpers.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/logger.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/metrics/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/metrics/metrics.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/output.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/press/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/press/apps.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/press/blocks.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/press/deployments.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/press/specs.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/py.typed +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/resources/alerts.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/resources/artifacts.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/resources/images.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/resources/services.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/resources/tenants.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/resources/users.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/resources/webapps.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/resources/workflows.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/metrics/create_collection.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/metrics/publish.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/metrics/query.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/metrics/update-namespace.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/apps/deployments/create_app_deployment.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/apps/deployments/create_app_deployment_revision.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/apps/deployments/update_app_deployment_metadata.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/apps/specs/create_app_spec.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/apps/specs/create_app_spec_release.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/apps/specs/update_app_spec_metadata.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/deployments/create_block_deployment.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/deployments/create_block_deployment_revision.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/deployments/patch_block_parameters.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/deployments/update_block_deployment_metadata.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/specs/service/api/create_block_spec.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/specs/service/api/create_block_spec_release.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/specs/service/webapp/create_block_spec.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/specs/service/webapp/create_block_spec_release.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/specs/update_block_spec_metadata.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/specs/workflow/create_block_spec.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/blocks/specs/workflow/create_block_spec_release.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/deployments/patch_app_parameters_v2.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/deployments/patch_block_parameters_v2.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/press/patch_parameters.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/artifacts/create_artifact.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/artifacts/create_artifact_version.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/artifacts/update_artifact_metadata.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/emails/send_email.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/dockerfile/create_image.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/dockerfile/create_image_version.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/dockerfile/update_version.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/github/create_image.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/github/create_image_version.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/github/update_version.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/upload/create_image.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/upload/create_image_version.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/upload/create_or_update_image.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/images/upload/update_version.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/services/create_or_update_service.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/services/create_service.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/services/test_service.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/services/update_service.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/webapps/create_or_update_webapp.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/webapps/create_webapp.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/webapps/update_webapp.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/create_or_update_workflow.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/create_workflow.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/execute_partial_workflow.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/execute_workflow.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/patch_workflow.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/update_workflow.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/workflow_auto_retry.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/workflow_execution_parameters.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/workflow_input_parameters.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/workflow_input_parameters_inherit.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/workflow_output_parameters.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/sample_yaml/resources/workflows/workflow_skippable_steps.yaml +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/session.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/telemetry.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/template.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/tools/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/tools/logging/__init__.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/tools/logging/log_handler.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/tools/logging/log_level.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/tools/logging/logger.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/tools/logging/utils.py +0 -0
- {peak_sdk-1.17.0 → peak_sdk-1.18.0}/peak/validators.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: peak-sdk
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.18.0
|
4
4
|
Summary: Python SDK for interacting with the Peak platform
|
5
5
|
Home-page: https://docs.peak.ai/sdk/latest/
|
6
6
|
License: Apache-2.0
|
@@ -31,6 +31,7 @@ Requires-Dist: shellingham (<1.5.4)
|
|
31
31
|
Requires-Dist: structlog (>=24.2.0,<25.0.0)
|
32
32
|
Requires-Dist: typer (>=0.12.4,<0.13.0)
|
33
33
|
Requires-Dist: urllib3 (<2)
|
34
|
+
Requires-Dist: valkey (>=6.0.0,<7.0.0)
|
34
35
|
Project-URL: Documentation, https://docs.peak.ai/sdk/latest/
|
35
36
|
Description-Content-Type: text/markdown
|
36
37
|
|
@@ -106,7 +107,7 @@ Follow these steps to create a virtual environment using Python's built-in `venv
|
|
106
107
|
This should return a response of the following format
|
107
108
|
|
108
109
|
```bash
|
109
|
-
peak-cli==1.
|
110
|
+
peak-cli==1.18.0
|
110
111
|
Python==3.12.3
|
111
112
|
System==Darwin(23.6.0)
|
112
113
|
```
|
@@ -122,7 +123,7 @@ Follow these steps to create a virtual environment using Python's built-in `venv
|
|
122
123
|
This should print the version of the SDK
|
123
124
|
|
124
125
|
```
|
125
|
-
1.
|
126
|
+
1.18.0
|
126
127
|
```
|
127
128
|
|
128
129
|
### Using the SDK and CLI
|
@@ -26,7 +26,7 @@ import typer
|
|
26
26
|
from peak.cli import args, helpers
|
27
27
|
from peak.cli.metrics import metrics
|
28
28
|
from peak.cli.press import apps, blocks, deployments, specs
|
29
|
-
from peak.cli.resources import alerts, artifacts, images, services, tenants, users, webapps, workflows
|
29
|
+
from peak.cli.resources import alerts, artifacts, cache, images, services, tenants, users, webapps, workflows
|
30
30
|
from peak.constants import Sources
|
31
31
|
from peak.output import Writer
|
32
32
|
|
@@ -38,6 +38,7 @@ typer_app.add_typer(images.app, name="images")
|
|
38
38
|
typer_app.add_typer(metrics.app, name="metrics")
|
39
39
|
typer_app.add_typer(alerts.app, name="alerts")
|
40
40
|
typer_app.add_typer(artifacts.app, name="artifacts")
|
41
|
+
typer_app.add_typer(cache.app, name="cache")
|
41
42
|
typer_app.add_typer(workflows.app, name="workflows")
|
42
43
|
typer_app.add_typer(webapps.app, name="webapps")
|
43
44
|
typer_app.add_typer(services.app, name="services")
|
@@ -251,6 +251,7 @@ def get_client(command: str) -> base_client.BaseClient:
|
|
251
251
|
"specs": press.specs,
|
252
252
|
"deployments": press.deployments,
|
253
253
|
"artifacts": resources.artifacts,
|
254
|
+
"cache": resources.cache,
|
254
255
|
"images": resources.images,
|
255
256
|
"workflows": resources.workflows,
|
256
257
|
"services": resources.services,
|
@@ -0,0 +1,452 @@
|
|
1
|
+
#
|
2
|
+
# # Copyright © 2025 Peak AI Limited. or its affiliates. All Rights Reserved.
|
3
|
+
# #
|
4
|
+
# # Licensed under the Apache License, Version 2.0 (the "License"). You
|
5
|
+
# # may not use this file except in compliance with the License. A copy of
|
6
|
+
# # the License is located at:
|
7
|
+
# #
|
8
|
+
# # https://github.com/PeakBI/peak-sdk/blob/main/LICENSE
|
9
|
+
# #
|
10
|
+
# # or in the "license" file accompanying this file. This file is
|
11
|
+
# # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
12
|
+
# # ANY KIND, either express or implied. See the License for the specific
|
13
|
+
# # language governing permissions and limitations under the License.
|
14
|
+
# #
|
15
|
+
# # This file is part of the peak-sdk.
|
16
|
+
# # see (https://github.com/PeakBI/peak-sdk)
|
17
|
+
# #
|
18
|
+
# # You should have received a copy of the APACHE LICENSE, VERSION 2.0
|
19
|
+
# # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
|
20
|
+
#
|
21
|
+
"""Peak Cache commands."""
|
22
|
+
import json
|
23
|
+
from typing import Any, Dict, Optional
|
24
|
+
|
25
|
+
import typer
|
26
|
+
from peak.cli.args import OUTPUT_TYPES, PAGING
|
27
|
+
from peak.constants import OutputTypes, OutputTypesNoTable
|
28
|
+
from peak.output import Writer
|
29
|
+
from peak.resources.cache import CacheClient
|
30
|
+
|
31
|
+
app = typer.Typer(
|
32
|
+
help="Cache operations for storing and retrieving data.",
|
33
|
+
short_help="Manage Cache Operations.",
|
34
|
+
)
|
35
|
+
|
36
|
+
_KEY = typer.Option(..., help="The cache key to operate on.")
|
37
|
+
_VALUE = typer.Option(..., help="The value to store in the cache.")
|
38
|
+
_TTL = typer.Option(None, help="Time to live in seconds for the cache entry.")
|
39
|
+
_DEFAULT = typer.Option(None, help="Default value to return if key doesn't exist.")
|
40
|
+
_KEYS = typer.Option(..., help="Comma-separated list of keys to operate on.")
|
41
|
+
_MAPPING = typer.Option(..., help="JSON mapping of key-value pairs to store.")
|
42
|
+
_PATTERN = typer.Option(..., help="Pattern to match keys for deletion.")
|
43
|
+
_DEBUG = typer.Option(False, help="Enable debug logging.")
|
44
|
+
_PREFIX = typer.Option(None, help="Additional prefix for cache keys.")
|
45
|
+
|
46
|
+
|
47
|
+
def _parse_json_mapping(mapping: str) -> Dict[str, Any]:
|
48
|
+
"""Parse and validate JSON mapping for mset command.
|
49
|
+
|
50
|
+
Args:
|
51
|
+
mapping: JSON string to parse
|
52
|
+
|
53
|
+
Returns:
|
54
|
+
Parsed dictionary
|
55
|
+
|
56
|
+
Raises:
|
57
|
+
typer.BadParameter: If mapping is invalid
|
58
|
+
TypeError: If mapping is not a JSON object
|
59
|
+
"""
|
60
|
+
parsed_mapping = json.loads(mapping)
|
61
|
+
if not isinstance(parsed_mapping, dict):
|
62
|
+
msg = "Mapping must be a JSON object"
|
63
|
+
raise TypeError(msg)
|
64
|
+
return parsed_mapping
|
65
|
+
|
66
|
+
|
67
|
+
@app.command("set", short_help="Store a value in the cache.")
|
68
|
+
def set_value(
|
69
|
+
ctx: typer.Context,
|
70
|
+
key: str = _KEY,
|
71
|
+
value: str = _VALUE,
|
72
|
+
ttl: Optional[int] = _TTL,
|
73
|
+
_debug: bool = _DEBUG,
|
74
|
+
prefix: Optional[str] = _PREFIX,
|
75
|
+
_paging: Optional[bool] = PAGING,
|
76
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
77
|
+
) -> None:
|
78
|
+
"""Store a value in the cache with an optional TTL.
|
79
|
+
|
80
|
+
\b
|
81
|
+
📝 ***Example usage:***
|
82
|
+
```bash
|
83
|
+
peak cache set --key "user:123" --value "John Doe"
|
84
|
+
peak cache set --key "config" --value '{"timeout": 30}' --ttl 3600
|
85
|
+
```
|
86
|
+
|
87
|
+
\b
|
88
|
+
🆗 ***Response:***
|
89
|
+
True if the value was stored successfully, False otherwise.
|
90
|
+
"""
|
91
|
+
client: CacheClient = ctx.obj["client"]
|
92
|
+
writer: Writer = ctx.obj["writer"]
|
93
|
+
|
94
|
+
if prefix:
|
95
|
+
client.set_additional_prefix(prefix)
|
96
|
+
|
97
|
+
try:
|
98
|
+
parsed_value = json.loads(value)
|
99
|
+
except json.JSONDecodeError:
|
100
|
+
parsed_value = value
|
101
|
+
|
102
|
+
with writer.pager():
|
103
|
+
result = client.set(key, parsed_value, ttl=ttl)
|
104
|
+
writer.write(result, output_type=OutputTypes.json)
|
105
|
+
|
106
|
+
|
107
|
+
@app.command(short_help="Retrieve a value from the cache.")
|
108
|
+
def get(
|
109
|
+
ctx: typer.Context,
|
110
|
+
key: str = _KEY,
|
111
|
+
default: Optional[str] = _DEFAULT,
|
112
|
+
_debug: bool = _DEBUG,
|
113
|
+
prefix: Optional[str] = _PREFIX,
|
114
|
+
_paging: Optional[bool] = PAGING,
|
115
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
116
|
+
) -> None:
|
117
|
+
"""Retrieve a value from the cache.
|
118
|
+
|
119
|
+
\b
|
120
|
+
📝 ***Example usage:***
|
121
|
+
```bash
|
122
|
+
peak cache get --key "user:123"
|
123
|
+
peak cache get --key "missing" --default "not found"
|
124
|
+
```
|
125
|
+
|
126
|
+
\b
|
127
|
+
🆗 ***Response:***
|
128
|
+
The cached value or the default value if the key doesn't exist.
|
129
|
+
"""
|
130
|
+
client: CacheClient = ctx.obj["client"]
|
131
|
+
writer: Writer = ctx.obj["writer"]
|
132
|
+
|
133
|
+
if prefix:
|
134
|
+
client.set_additional_prefix(prefix)
|
135
|
+
|
136
|
+
parsed_default = None
|
137
|
+
if default is not None:
|
138
|
+
try:
|
139
|
+
parsed_default = json.loads(default)
|
140
|
+
except json.JSONDecodeError:
|
141
|
+
parsed_default = default
|
142
|
+
|
143
|
+
with writer.pager():
|
144
|
+
result = client.get(key, default=parsed_default)
|
145
|
+
writer.write(result, output_type=OutputTypes.json)
|
146
|
+
|
147
|
+
|
148
|
+
@app.command(short_help="Retrieve multiple values from the cache.")
|
149
|
+
def mget(
|
150
|
+
ctx: typer.Context,
|
151
|
+
keys: str = _KEYS,
|
152
|
+
_debug: bool = _DEBUG,
|
153
|
+
prefix: Optional[str] = _PREFIX,
|
154
|
+
_paging: Optional[bool] = PAGING,
|
155
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
156
|
+
) -> None:
|
157
|
+
"""Retrieve multiple values from the cache.
|
158
|
+
|
159
|
+
\b
|
160
|
+
📝 ***Example usage:***
|
161
|
+
```bash
|
162
|
+
peak cache mget --keys "user:123,user:456,config"
|
163
|
+
peak cache mget --keys "session:abc,session:def"
|
164
|
+
```
|
165
|
+
|
166
|
+
\b
|
167
|
+
🆗 ***Response:***
|
168
|
+
List of values corresponding to the keys (null for non-existent keys).
|
169
|
+
"""
|
170
|
+
client: CacheClient = ctx.obj["client"]
|
171
|
+
writer: Writer = ctx.obj["writer"]
|
172
|
+
|
173
|
+
if prefix:
|
174
|
+
client.set_additional_prefix(prefix)
|
175
|
+
|
176
|
+
key_list = [key.strip() for key in keys.split(",")]
|
177
|
+
|
178
|
+
with writer.pager():
|
179
|
+
result = client.mget(*key_list)
|
180
|
+
writer.write(result, output_type=OutputTypes.json)
|
181
|
+
|
182
|
+
|
183
|
+
@app.command(short_help="Store multiple key-value pairs in the cache.")
|
184
|
+
def mset(
|
185
|
+
ctx: typer.Context,
|
186
|
+
mapping: str = _MAPPING,
|
187
|
+
ttl: Optional[int] = _TTL,
|
188
|
+
_debug: bool = _DEBUG,
|
189
|
+
prefix: Optional[str] = _PREFIX,
|
190
|
+
_paging: Optional[bool] = PAGING,
|
191
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
192
|
+
) -> None:
|
193
|
+
"""Store multiple key-value pairs in the cache.
|
194
|
+
|
195
|
+
\b
|
196
|
+
📝 ***Example usage:***
|
197
|
+
```bash
|
198
|
+
peak cache mset --mapping '{"user:123": "John", "user:456": "Jane"}'
|
199
|
+
peak cache mset --mapping '{"config:timeout": 30, "config:retries": 3}' --ttl 3600
|
200
|
+
```
|
201
|
+
|
202
|
+
\b
|
203
|
+
🆗 ***Response:***
|
204
|
+
True if all values were stored successfully, False otherwise.
|
205
|
+
"""
|
206
|
+
client: CacheClient = ctx.obj["client"]
|
207
|
+
writer: Writer = ctx.obj["writer"]
|
208
|
+
|
209
|
+
if prefix:
|
210
|
+
client.set_additional_prefix(prefix)
|
211
|
+
|
212
|
+
try:
|
213
|
+
parsed_mapping = _parse_json_mapping(mapping)
|
214
|
+
except (json.JSONDecodeError, ValueError, TypeError) as e:
|
215
|
+
msg = f"Invalid JSON mapping: {e}"
|
216
|
+
raise typer.BadParameter(msg) from e
|
217
|
+
|
218
|
+
with writer.pager():
|
219
|
+
result = client.mset(parsed_mapping, ttl=ttl)
|
220
|
+
writer.write(result, output_type=OutputTypes.json)
|
221
|
+
|
222
|
+
|
223
|
+
@app.command(short_help="Delete one or more keys from the cache.")
|
224
|
+
def delete(
|
225
|
+
ctx: typer.Context,
|
226
|
+
keys: str = _KEYS,
|
227
|
+
_debug: bool = _DEBUG,
|
228
|
+
prefix: Optional[str] = _PREFIX,
|
229
|
+
_paging: Optional[bool] = PAGING,
|
230
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
231
|
+
) -> None:
|
232
|
+
"""Delete one or more keys from the cache.
|
233
|
+
|
234
|
+
\b
|
235
|
+
📝 ***Example usage:***
|
236
|
+
```bash
|
237
|
+
peak cache delete --keys "user:123"
|
238
|
+
peak cache delete --keys "user:123,user:456,config"
|
239
|
+
```
|
240
|
+
|
241
|
+
\b
|
242
|
+
🆗 ***Response:***
|
243
|
+
Number of keys that were deleted.
|
244
|
+
"""
|
245
|
+
client: CacheClient = ctx.obj["client"]
|
246
|
+
writer: Writer = ctx.obj["writer"]
|
247
|
+
|
248
|
+
if prefix:
|
249
|
+
client.set_additional_prefix(prefix)
|
250
|
+
|
251
|
+
key_list = [key.strip() for key in keys.split(",")]
|
252
|
+
|
253
|
+
with writer.pager():
|
254
|
+
result = client.delete(*key_list)
|
255
|
+
writer.write(result, output_type=OutputTypes.json)
|
256
|
+
|
257
|
+
|
258
|
+
@app.command(short_help="Check if one or more keys exist in the cache.")
|
259
|
+
def exists(
|
260
|
+
ctx: typer.Context,
|
261
|
+
keys: str = _KEYS,
|
262
|
+
_debug: bool = _DEBUG,
|
263
|
+
prefix: Optional[str] = _PREFIX,
|
264
|
+
_paging: Optional[bool] = PAGING,
|
265
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
266
|
+
) -> None:
|
267
|
+
"""Check if one or more keys exist in the cache.
|
268
|
+
|
269
|
+
\b
|
270
|
+
📝 ***Example usage:***
|
271
|
+
```bash
|
272
|
+
peak cache exists --keys "user:123"
|
273
|
+
peak cache exists --keys "user:123,user:456"
|
274
|
+
```
|
275
|
+
|
276
|
+
\b
|
277
|
+
🆗 ***Response:***
|
278
|
+
Number of keys that exist in the cache.
|
279
|
+
"""
|
280
|
+
client: CacheClient = ctx.obj["client"]
|
281
|
+
writer: Writer = ctx.obj["writer"]
|
282
|
+
|
283
|
+
if prefix:
|
284
|
+
client.set_additional_prefix(prefix)
|
285
|
+
|
286
|
+
key_list = [key.strip() for key in keys.split(",")]
|
287
|
+
|
288
|
+
with writer.pager():
|
289
|
+
result = client.exists(*key_list)
|
290
|
+
writer.write(result, output_type=OutputTypes.json)
|
291
|
+
|
292
|
+
|
293
|
+
@app.command(short_help="Set expiration time for a key.")
|
294
|
+
def expire(
|
295
|
+
ctx: typer.Context,
|
296
|
+
key: str = _KEY,
|
297
|
+
ttl: int = typer.Option(..., help="Time to live in seconds."),
|
298
|
+
_debug: bool = _DEBUG,
|
299
|
+
prefix: Optional[str] = _PREFIX,
|
300
|
+
_paging: Optional[bool] = PAGING,
|
301
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
302
|
+
) -> None:
|
303
|
+
"""Set expiration time for a key.
|
304
|
+
|
305
|
+
\b
|
306
|
+
📝 ***Example usage:***
|
307
|
+
```bash
|
308
|
+
peak cache expire --key "user:123" --ttl 3600
|
309
|
+
peak cache expire --key "session:abc" --ttl 1800
|
310
|
+
```
|
311
|
+
|
312
|
+
\b
|
313
|
+
🆗 ***Response:***
|
314
|
+
True if the expiration was set, False if the key doesn't exist.
|
315
|
+
"""
|
316
|
+
client: CacheClient = ctx.obj["client"]
|
317
|
+
writer: Writer = ctx.obj["writer"]
|
318
|
+
|
319
|
+
if prefix:
|
320
|
+
client.set_additional_prefix(prefix)
|
321
|
+
|
322
|
+
with writer.pager():
|
323
|
+
result = client.expire(key, ttl)
|
324
|
+
writer.write(result, output_type=OutputTypes.json)
|
325
|
+
|
326
|
+
|
327
|
+
@app.command(short_help="Get the remaining time to live for a key.")
|
328
|
+
def ttl(
|
329
|
+
ctx: typer.Context,
|
330
|
+
key: str = _KEY,
|
331
|
+
_debug: bool = _DEBUG,
|
332
|
+
prefix: Optional[str] = _PREFIX,
|
333
|
+
_paging: Optional[bool] = PAGING,
|
334
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
335
|
+
) -> None:
|
336
|
+
"""Get the remaining time to live for a key.
|
337
|
+
|
338
|
+
\b
|
339
|
+
📝 ***Example usage:***
|
340
|
+
```bash
|
341
|
+
peak cache ttl --key "user:123"
|
342
|
+
peak cache ttl --key "session:abc"
|
343
|
+
```
|
344
|
+
|
345
|
+
\b
|
346
|
+
🆗 ***Response:***
|
347
|
+
Remaining TTL in seconds (-1 if no expiration, -2 if key doesn't exist).
|
348
|
+
"""
|
349
|
+
client: CacheClient = ctx.obj["client"]
|
350
|
+
writer: Writer = ctx.obj["writer"]
|
351
|
+
|
352
|
+
if prefix:
|
353
|
+
client.set_additional_prefix(prefix)
|
354
|
+
|
355
|
+
with writer.pager():
|
356
|
+
result = client.ttl(key)
|
357
|
+
writer.write(result, output_type=OutputTypes.json)
|
358
|
+
|
359
|
+
|
360
|
+
@app.command(short_help="Test cache connection.")
|
361
|
+
def ping(
|
362
|
+
ctx: typer.Context,
|
363
|
+
_debug: bool = _DEBUG,
|
364
|
+
prefix: Optional[str] = _PREFIX,
|
365
|
+
_paging: Optional[bool] = PAGING,
|
366
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
367
|
+
) -> None:
|
368
|
+
"""Test cache connection.
|
369
|
+
|
370
|
+
\b
|
371
|
+
📝 ***Example usage:***
|
372
|
+
```bash
|
373
|
+
peak cache ping
|
374
|
+
```
|
375
|
+
|
376
|
+
\b
|
377
|
+
🆗 ***Response:***
|
378
|
+
True if the connection is successful, False otherwise.
|
379
|
+
"""
|
380
|
+
client: CacheClient = ctx.obj["client"]
|
381
|
+
writer: Writer = ctx.obj["writer"]
|
382
|
+
|
383
|
+
if prefix:
|
384
|
+
client.set_additional_prefix(prefix)
|
385
|
+
|
386
|
+
with writer.pager():
|
387
|
+
result = client.ping()
|
388
|
+
writer.write(result, output_type=OutputTypes.json)
|
389
|
+
|
390
|
+
|
391
|
+
@app.command(short_help="Delete all keys matching a pattern.")
|
392
|
+
def flush_pattern(
|
393
|
+
ctx: typer.Context,
|
394
|
+
pattern: str = _PATTERN,
|
395
|
+
_debug: bool = _DEBUG,
|
396
|
+
prefix: Optional[str] = _PREFIX,
|
397
|
+
_paging: Optional[bool] = PAGING,
|
398
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
399
|
+
) -> None:
|
400
|
+
"""Delete all keys matching a pattern within the tenant namespace.
|
401
|
+
|
402
|
+
\b
|
403
|
+
📝 ***Example usage:***
|
404
|
+
```bash
|
405
|
+
peak cache flush-pattern --pattern "user:*"
|
406
|
+
peak cache flush-pattern --pattern "session:*"
|
407
|
+
```
|
408
|
+
|
409
|
+
\b
|
410
|
+
🆗 ***Response:***
|
411
|
+
Number of keys that were deleted.
|
412
|
+
"""
|
413
|
+
client: CacheClient = ctx.obj["client"]
|
414
|
+
writer: Writer = ctx.obj["writer"]
|
415
|
+
|
416
|
+
if prefix:
|
417
|
+
client.set_additional_prefix(prefix)
|
418
|
+
|
419
|
+
with writer.pager():
|
420
|
+
result = client.flush_by_pattern(pattern)
|
421
|
+
writer.write(result, output_type=OutputTypes.json)
|
422
|
+
|
423
|
+
|
424
|
+
@app.command(short_help="Delete all keys for the current tenant.")
|
425
|
+
def flush_tenant(
|
426
|
+
ctx: typer.Context,
|
427
|
+
_debug: bool = _DEBUG,
|
428
|
+
prefix: Optional[str] = _PREFIX,
|
429
|
+
_paging: Optional[bool] = PAGING,
|
430
|
+
_output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES,
|
431
|
+
) -> None:
|
432
|
+
"""Delete all keys for the current tenant.
|
433
|
+
|
434
|
+
\b
|
435
|
+
📝 ***Example usage:***
|
436
|
+
```bash
|
437
|
+
peak cache flush-tenant
|
438
|
+
```
|
439
|
+
|
440
|
+
\b
|
441
|
+
🆗 ***Response:***
|
442
|
+
Number of keys that were deleted.
|
443
|
+
"""
|
444
|
+
client: CacheClient = ctx.obj["client"]
|
445
|
+
writer: Writer = ctx.obj["writer"]
|
446
|
+
|
447
|
+
if prefix:
|
448
|
+
client.set_additional_prefix(prefix)
|
449
|
+
|
450
|
+
with writer.pager():
|
451
|
+
result = client.flush_tenant()
|
452
|
+
writer.write(result, output_type=OutputTypes.json)
|
@@ -24,11 +24,12 @@ from __future__ import annotations
|
|
24
24
|
|
25
25
|
from typing import List
|
26
26
|
|
27
|
-
from peak.resources import alerts, artifacts, images, services, tenants, users, webapps, workflows
|
27
|
+
from peak.resources import alerts, artifacts, cache, images, services, tenants, users, webapps, workflows
|
28
28
|
|
29
29
|
__all__: List[str] = [
|
30
30
|
"alerts",
|
31
31
|
"artifacts",
|
32
|
+
"cache",
|
32
33
|
"images",
|
33
34
|
"services",
|
34
35
|
"tenants",
|