From 6c97e7e728c245bb1014d321784fa235ed0142cc Mon Sep 17 00:00:00 2001 From: Anders Albert <60234212+doctrino@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:41:05 +0200 Subject: [PATCH 1/6] Add support for one shot token exchange (#1889) --- CHANGELOG.md | 6 +++ cognite/client/_api/functions.py | 7 ++- cognite/client/_api/iam.py | 51 ++++++++++++++++--- cognite/client/_api/workflows.py | 7 ++- cognite/client/_version.py | 2 +- pyproject.toml | 2 +- .../test_api/test_functions.py | 7 +++ 7 files changed, 72 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41a4b22dd..a56ecbe2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [7.55.0] - 2024-08-23 +### Added +- Support for creating a session using a one-shot token in the `client.iam.session.create` method. +- Parameter `nonce` to the `client.functions.call()` and `client.workflow.executions.run()` methods to allow passing + a custom nonce instead of letting the SDK generate it from your current credentials. + ## [7.54.19] - 2024-08-23 ### Added - [Feature Preview - beta] Support for `client.workflows.triggers`. diff --git a/cognite/client/_api/functions.py b/cognite/client/_api/functions.py index ca0e7ed61..094cb0249 100644 --- a/cognite/client/_api/functions.py +++ b/cognite/client/_api/functions.py @@ -521,6 +521,7 @@ def call( external_id: str | None = None, data: dict | None = None, wait: bool = True, + nonce: str | None = None, ) -> FunctionCall: """`Call a function by its ID or external ID. `_. @@ -529,6 +530,10 @@ def call( external_id (str | None): External ID data (dict | None): Input data to the function (JSON serializable). This data is passed deserialized into the function through one of the arguments called data. **WARNING:** Secrets or other confidential information should not be passed via this argument. There is a dedicated `secrets` argument in FunctionsAPI.create() for this purpose.' wait (bool): Wait until the function call is finished. Defaults to True. + nonce (str | None): Nonce retrieved from sessions API when creating a session. This will be used to bind the session before executing the function. If not provided, a new session will be created based on the client credentials. + + Tip: + You can create a session via the Sessions API, using the client.iam.session.create() method. Returns: FunctionCall: A function call object. @@ -550,7 +555,7 @@ def call( """ identifier = IdentifierSequence.load(ids=id, external_ids=external_id).as_singleton()[0] id = _get_function_internal_id(self._cognite_client, identifier) - nonce = create_session_and_return_nonce(self._cognite_client, api_name="Functions API") + nonce = nonce or create_session_and_return_nonce(self._cognite_client, api_name="Functions API") if data is None: data = {} diff --git a/cognite/client/_api/iam.py b/cognite/client/_api/iam.py index a609a08e2..9eee4608f 100644 --- a/cognite/client/_api/iam.py +++ b/cognite/client/_api/iam.py @@ -3,7 +3,7 @@ import warnings from itertools import groupby from operator import itemgetter -from typing import TYPE_CHECKING, Any, Dict, Iterable, Sequence, Union, overload +from typing import TYPE_CHECKING, Any, Dict, Iterable, Literal, Sequence, Union, overload from typing_extensions import TypeAlias @@ -34,7 +34,13 @@ SpaceIDScope, UnknownAcl, ) -from cognite.client.data_classes.iam import GroupWrite, SecurityCategoryWrite, SessionStatus, TokenInspection +from cognite.client.data_classes.iam import ( + GroupWrite, + SecurityCategoryWrite, + SessionStatus, + SessionType, + TokenInspection, +) from cognite.client.utils._identifier import IdentifierSequence if TYPE_CHECKING: @@ -528,20 +534,53 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client super().__init__(config, api_version, cognite_client) self._LIST_LIMIT = 100 - def create(self, client_credentials: ClientCredentials | None = None) -> CreatedSession: + def create( + self, + client_credentials: ClientCredentials | None = None, + session_type: SessionType | Literal["DEFAULT"] = "DEFAULT", + ) -> CreatedSession: """`Create a session. `_ Args: - client_credentials (ClientCredentials | None): The client credentials to create the session. If set to None, a session will be created using the credentials used to instantiate -this- CogniteClient object. If that was done using a token, a session will be created using token exchange. Similarly, if the credentials were client credentials, a session will be created using client credentials. This method does not work when using client certificates (not supported server-side). + client_credentials (ClientCredentials | None): The client credentials to create the session. This is required + if session_type is set to 'CLIENT_CREDENTIALS'. + session_type (SessionType | Literal['DEFAULT']): The type of session to create. Can be + either 'CLIENT_CREDENTIALS', 'TOKEN_EXCHANGE', 'ONESHOT_TOKEN_EXCHANGE' or 'DEFAULT'. + Defaults to 'DEFAULT' which will use -this- CogniteClient object to create the session. + If this client was created using a token, 'TOKEN_EXCHANGE' will be used, and if + this client was created using client credentials, 'CLIENT_CREDENTIALS' will be used. + + Session Types: + * **client_credentials**: Credentials for a session using client credentials from an identity provider. + * **token_exchange**: Credentials for a session using token exchange to reuse the user's credentials. + * **one_shot_token_exchange**: Credentials for a session using one-shot token exchange to reuse the user's credentials. One-shot sessions are short-lived sessions that are not refreshed and do not require support for token exchange from the identity provider. Returns: CreatedSession: The object with token inspection details. """ - if client_credentials is None and isinstance((creds := self._config.credentials), OAuthClientCredentials): + if client_credentials is None and isinstance(creds := self._config.credentials, OAuthClientCredentials): client_credentials = ClientCredentials(creds.client_id, creds.client_secret) - items = {"tokenExchange": True} if client_credentials is None else client_credentials.dump(camel_case=True) + session_type_up = session_type.upper() + if session_type_up == "DEFAULT": # For backwards compatibility after session_type was introduced + items = {"tokenExchange": True} if client_credentials is None else client_credentials.dump(camel_case=True) + + elif session_type_up == "CLIENT_CREDENTIALS": + if client_credentials is None: + raise ValueError( + "For session_type='CLIENT_CREDENTIALS', either `client_credentials` must be provided OR " + "this client must be using OAuthClientCredentials" + ) + items = client_credentials.dump(camel_case=True) + + elif session_type_up == "TOKEN_EXCHANGE": + items = {"tokenExchange": True} + + elif session_type_up == "ONESHOT_TOKEN_EXCHANGE": + items = {"oneshotTokenExchange": True} + else: + raise ValueError(f"Session type not understood: {session_type}") return CreatedSession.load(self._post(self._RESOURCE_PATH, {"items": [items]}).json()["items"][0]) @overload diff --git a/cognite/client/_api/workflows.py b/cognite/client/_api/workflows.py index 17ac83792..4d02d9788 100644 --- a/cognite/client/_api/workflows.py +++ b/cognite/client/_api/workflows.py @@ -318,6 +318,7 @@ def run( input: dict | None = None, metadata: dict | None = None, client_credentials: ClientCredentials | None = None, + nonce: str | None = None, ) -> WorkflowExecution: """`Run a workflow execution. `_ @@ -327,6 +328,7 @@ def run( input (dict | None): The input to the workflow execution. This will be available for tasks that have specified it as an input with the string "${workflow.input}" See tip below for more information. metadata (dict | None): Application specific metadata. Keys have a maximum length of 32 characters, values a maximum of 255, and there can be a maximum of 10 key-value pairs. client_credentials (ClientCredentials | None): Specific credentials that should be used to trigger the workflow execution. When passed will take precedence over the current credentials. + nonce (str | None): The nonce to use to bind the session. If not provided, a new session will be created using the current credentials. Tip: The workflow input can be available in the workflow tasks. For example, if you have a Task with @@ -339,6 +341,9 @@ def run( ... external_id="cdf_deployed_function:my_function", ... data={"workflow_data": "${workflow.input}",})) + Tip: + You can create a session via the Sessions API, using the client.iam.session.create() method. + Returns: WorkflowExecution: The created workflow execution. @@ -361,7 +366,7 @@ def run( >>> credentials = ClientCredentials("my-client-id", os.environ["MY_CLIENT_SECRET"]) >>> res = client.workflows.executions.run("foo", "1", client_credentials=credentials) """ - nonce = create_session_and_return_nonce( + nonce = nonce or create_session_and_return_nonce( self._cognite_client, api_name="Workflow API", client_credentials=client_credentials ) body = {"authentication": {"nonce": nonce}} diff --git a/cognite/client/_version.py b/cognite/client/_version.py index c0c69ed69..ad6484fa6 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.54.19" +__version__ = "7.55.0" __api_subversion__ = "20230101" diff --git a/pyproject.toml b/pyproject.toml index ef09ab563..eceeffadd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.54.19" +version = "7.55.0" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com" diff --git a/tests/tests_integration/test_api/test_functions.py b/tests/tests_integration/test_api/test_functions.py index 15a511583..d3c456f6d 100644 --- a/tests/tests_integration/test_api/test_functions.py +++ b/tests/tests_integration/test_api/test_functions.py @@ -76,6 +76,13 @@ def test_iterate_chunked_functions(self, cognite_client: CogniteClient) -> None: else: assert False, "Expected at least one function" + def test_call_function_with_oneshot(self, cognite_client: CogniteClient, a_function: Function) -> None: + session = cognite_client.iam.sessions.create(session_type="ONESHOT_TOKEN_EXCHANGE") + + response = cognite_client.functions.call(id=a_function.id, wait=True, nonce=session.nonce) + + assert response.status == "Completed" + class TestFunctionSchedulesAPI: def test_create_retrieve_delete(self, cognite_client: CogniteClient, a_function: Function) -> None: From 83f4aa5f06c448b8072e7102ec0bbe4a801d3ea7 Mon Sep 17 00:00:00 2001 From: Greger Teigre Wedel Date: Wed, 28 Aug 2024 14:50:25 +0200 Subject: [PATCH 2/6] Replace pyproject build system with poetry-core (#1891) --- poetry.lock | 42 +++++++++++++++++++++++------------------- pyproject.toml | 4 ++-- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/poetry.lock b/poetry.lock index 58e8719b8..43f6bc5e2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1672,22 +1672,22 @@ wcwidth = "*" [[package]] name = "protobuf" -version = "5.27.3" +version = "5.27.4" description = "" optional = false python-versions = ">=3.8" files = [ - {file = "protobuf-5.27.3-cp310-abi3-win32.whl", hash = "sha256:dcb307cd4ef8fec0cf52cb9105a03d06fbb5275ce6d84a6ae33bc6cf84e0a07b"}, - {file = "protobuf-5.27.3-cp310-abi3-win_amd64.whl", hash = "sha256:16ddf3f8c6c41e1e803da7abea17b1793a97ef079a912e42351eabb19b2cffe7"}, - {file = "protobuf-5.27.3-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:68248c60d53f6168f565a8c76dc58ba4fa2ade31c2d1ebdae6d80f969cdc2d4f"}, - {file = "protobuf-5.27.3-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:b8a994fb3d1c11156e7d1e427186662b64694a62b55936b2b9348f0a7c6625ce"}, - {file = "protobuf-5.27.3-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:a55c48f2a2092d8e213bd143474df33a6ae751b781dd1d1f4d953c128a415b25"}, - {file = "protobuf-5.27.3-cp38-cp38-win32.whl", hash = "sha256:043853dcb55cc262bf2e116215ad43fa0859caab79bb0b2d31b708f128ece035"}, - {file = "protobuf-5.27.3-cp38-cp38-win_amd64.whl", hash = "sha256:c2a105c24f08b1e53d6c7ffe69cb09d0031512f0b72f812dd4005b8112dbe91e"}, - {file = "protobuf-5.27.3-cp39-cp39-win32.whl", hash = "sha256:c84eee2c71ed83704f1afbf1a85c3171eab0fd1ade3b399b3fad0884cbcca8bf"}, - {file = "protobuf-5.27.3-cp39-cp39-win_amd64.whl", hash = "sha256:af7c0b7cfbbb649ad26132e53faa348580f844d9ca46fd3ec7ca48a1ea5db8a1"}, - {file = "protobuf-5.27.3-py3-none-any.whl", hash = "sha256:8572c6533e544ebf6899c360e91d6bcbbee2549251643d32c52cf8a5de295ba5"}, - {file = "protobuf-5.27.3.tar.gz", hash = "sha256:82460903e640f2b7e34ee81a947fdaad89de796d324bcbc38ff5430bcdead82c"}, + {file = "protobuf-5.27.4-cp310-abi3-win32.whl", hash = "sha256:10319748764b917a9a7cddef1582a0a9cd0f8f6d04e545c6236f7ccaf9b624d9"}, + {file = "protobuf-5.27.4-cp310-abi3-win_amd64.whl", hash = "sha256:f0c24374aaaf103f33662e4de7666a4a4280abebdb8a9f3f0f9b1d71b61174ec"}, + {file = "protobuf-5.27.4-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:e85fed07013e5a0121efbaf1b14355fdc66f6e545f12fc5985b2882370410006"}, + {file = "protobuf-5.27.4-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:d5a0e229061600842e57af4ff6a8522ede5280bcfa4fe7f3a1c20589377859a6"}, + {file = "protobuf-5.27.4-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:25ba1f0633f73c3939f3b84e1636f3eb3bab7196952ebb83906d56945edd6aa8"}, + {file = "protobuf-5.27.4-cp38-cp38-win32.whl", hash = "sha256:565b051249a2f8270af04206dd4f3b73a02343e7d9e072aed57441b369b3467d"}, + {file = "protobuf-5.27.4-cp38-cp38-win_amd64.whl", hash = "sha256:e673f173cbac4e59c7817ed358e471e4c77aa9166986edf3e731156379a556c7"}, + {file = "protobuf-5.27.4-cp39-cp39-win32.whl", hash = "sha256:25169c7624d5a9e669fa6faff5a6e818f854346d51ee347b2284676beb9e85dd"}, + {file = "protobuf-5.27.4-cp39-cp39-win_amd64.whl", hash = "sha256:1fe7735902e84ce35c4152cf07981c176713935a8efad78cea547aae5f4f75cb"}, + {file = "protobuf-5.27.4-py3-none-any.whl", hash = "sha256:b97259641e8d38738eef34a173e51d2d53a453baab01a32477a64752d9ce59a3"}, + {file = "protobuf-5.27.4.tar.gz", hash = "sha256:eaa1016e353d8fc5bf08c8087e96eed15f5297aa52bb7ee1f533278bb3f3aad7"}, ] [[package]] @@ -2253,13 +2253,13 @@ idna2008 = ["idna"] [[package]] name = "rich" -version = "13.7.1" +version = "13.8.0" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" optional = false python-versions = ">=3.7.0" files = [ - {file = "rich-13.7.1-py3-none-any.whl", hash = "sha256:4edbae314f59eb482f54e9e30bf00d33350aaa94f4bfcd4e9e3110e64d0d7222"}, - {file = "rich-13.7.1.tar.gz", hash = "sha256:9be308cb1fe2f1f57d67ce99e95af38a1e2bc71ad9813b0e247cf7ffbcc3a432"}, + {file = "rich-13.8.0-py3-none-any.whl", hash = "sha256:2e85306a063b9492dffc86278197a60cbece75bcb766022f3436f567cae11bdc"}, + {file = "rich-13.8.0.tar.gz", hash = "sha256:a5ac1f1cd448ade0d59cc3356f7db7a7ccda2c8cbae9c7a90c28ff463d3e91f4"}, ] [package.dependencies] @@ -2747,18 +2747,22 @@ files = [ [[package]] name = "zipp" -version = "3.20.0" +version = "3.20.1" description = "Backport of pathlib-compatible object wrapper for zip files" optional = false python-versions = ">=3.8" files = [ - {file = "zipp-3.20.0-py3-none-any.whl", hash = "sha256:58da6168be89f0be59beb194da1250516fdaa062ccebd30127ac65d30045e10d"}, - {file = "zipp-3.20.0.tar.gz", hash = "sha256:0145e43d89664cfe1a2e533adc75adafed82fe2da404b4bbb6b026c0157bdb31"}, + {file = "zipp-3.20.1-py3-none-any.whl", hash = "sha256:9960cd8967c8f85a56f920d5d507274e74f9ff813a0ab8889a5b5be2daf44064"}, + {file = "zipp-3.20.1.tar.gz", hash = "sha256:c22b14cc4763c5a5b04134207736c107db42e9d3ef2d9779d465f5f1bcba572b"}, ] [package.extras] +check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)"] +cover = ["pytest-cov"] doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] -test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ignore-flaky", "pytest-mypy", "pytest-ruff (>=0.2.1)"] +enabler = ["pytest-enabler (>=2.2)"] +test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-ignore-flaky"] +type = ["pytest-mypy"] [extras] all = ["PyYAML", "geopandas", "geopandas", "numpy", "numpy", "numpy", "pandas", "pandas", "pip", "shapely", "sympy"] diff --git a/pyproject.toml b/pyproject.toml index eceeffadd..d6fdc82f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,5 +89,5 @@ PyYAML = "^6.0" pytest-icdiff = "*" # Used for better diffs in pytest [build-system] -requires = ["poetry>=1.0"] -build-backend = "poetry.masonry.api" +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" From b201be95cac4c91a52372e7a77d883c33d8c5328 Mon Sep 17 00:00:00 2001 From: Vincent <48801276+vincent-cognite@users.noreply.github.com> Date: Thu, 29 Aug 2024 11:29:05 +0200 Subject: [PATCH 3/6] CDF-22143: fix missing exports for workflow triggers (#1894) --- CHANGELOG.md | 4 ++++ cognite/client/_version.py | 2 +- cognite/client/data_classes/__init__.py | 11 +++++++++++ pyproject.toml | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a56ecbe2a..eb0d1dc04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [7.55.1] - 2024-08-29 +### Fixed +- Missing exports for workflow triggers + ## [7.55.0] - 2024-08-23 ### Added - Support for creating a session using a one-shot token in the `client.iam.session.create` method. diff --git a/cognite/client/_version.py b/cognite/client/_version.py index ad6484fa6..edd6657ff 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.55.0" +__version__ = "7.55.1" __api_subversion__ = "20230101" diff --git a/cognite/client/data_classes/__init__.py b/cognite/client/data_classes/__init__.py index 1eb05c917..5fee33dc0 100644 --- a/cognite/client/data_classes/__init__.py +++ b/cognite/client/data_classes/__init__.py @@ -303,6 +303,11 @@ WorkflowList, WorkflowTask, WorkflowTaskExecution, + WorkflowTrigger, + WorkflowTriggerCreate, + WorkflowTriggerList, + WorkflowTriggerRun, + WorkflowTriggerRunList, WorkflowUpsert, WorkflowUpsertList, WorkflowVersion, @@ -569,6 +574,12 @@ "WorkflowTask", "WorkflowUpsertList", "WorkflowVersionUpsertList", + "WorkflowVersionUpsertList", + "WorkflowTrigger", + "WorkflowTriggerCreate", + "WorkflowTriggerList", + "WorkflowTriggerRun", + "WorkflowTriggerRunList", "HasName", "HasExternalId", "HasInternalId", diff --git a/pyproject.toml b/pyproject.toml index d6fdc82f7..a3566ee1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.55.0" +version = "7.55.1" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com" From f01dbc0cbc04c317b2341ad7afe57a191a8d6dd2 Mon Sep 17 00:00:00 2001 From: Vincent <48801276+vincent-cognite@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:48:57 +0200 Subject: [PATCH 4/6] workflow_orchestration is now data_workflows rst and add trigger doc (#1895) --- CHANGELOG.md | 4 +++ cognite/client/_version.py | 2 +- cognite/client/data_classes/workflows.py | 29 ++++++++++++++----- ...w_orchestration.rst => data_workflows.rst} | 17 +++++++++++ docs/source/index.rst | 2 +- pyproject.toml | 2 +- .../test_api/test_data_workflows.py | 4 +-- 7 files changed, 47 insertions(+), 13 deletions(-) rename docs/source/{workflow_orchestration.rst => data_workflows.rst} (76%) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb0d1dc04..1340b161b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [7.55.2] - 2024-08-29 +### Fixed +- Turn workflow_orchestration into data_workflows and add trigger doc, fix attribute names in data classes + ## [7.55.1] - 2024-08-29 ### Fixed - Missing exports for workflow triggers diff --git a/cognite/client/_version.py b/cognite/client/_version.py index edd6657ff..a2f3828ca 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.55.1" +__version__ = "7.55.2" __api_subversion__ = "20230101" diff --git a/cognite/client/data_classes/workflows.py b/cognite/client/data_classes/workflows.py index 90410888f..26f13eb6e 100644 --- a/cognite/client/data_classes/workflows.py +++ b/cognite/client/data_classes/workflows.py @@ -1381,23 +1381,33 @@ class WorkflowTriggerRun(CogniteResource): def __init__( self, - trigger_external_id: str, - trigger_fire_time: int, + external_id: str, + fire_time: int, workflow_external_id: str, workflow_version: str, + workflow_execution_id: str, + status: Literal["success", "failed"], + reason_for_failure: str | None = None, ) -> None: - self.trigger_external_id = trigger_external_id - self.trigger_fire_time = trigger_fire_time + self.external_id = external_id + self.fire_time = fire_time self.workflow_external_id = workflow_external_id self.workflow_version = workflow_version + self.workflow_execution_id = workflow_execution_id + self.status = status + self.reason_for_failure = reason_for_failure def dump(self, camel_case: bool = True) -> dict[str, Any]: item = { - "trigger_external_id": self.trigger_external_id, - "trigger_fire_time": self.trigger_fire_time, + "external_id": self.external_id, + "fire_time": self.fire_time, "workflow_external_id": self.workflow_external_id, "workflow_version": self.workflow_version, + "workflow_execution_id": self.workflow_execution_id, + "status": self.status, } + if self.reason_for_failure: + item["reason_for_failure"] = self.reason_for_failure if camel_case: return convert_all_keys_to_camel_case(item) return item @@ -1405,10 +1415,13 @@ def dump(self, camel_case: bool = True) -> dict[str, Any]: @classmethod def _load(cls, resource: dict, cognite_client: CogniteClient | None = None) -> WorkflowTriggerRun: return cls( - trigger_external_id=resource["triggerExternalId"], - trigger_fire_time=resource["triggerFireTime"], + external_id=resource["externalId"], + fire_time=resource["fireTime"], workflow_external_id=resource["workflowExternalId"], workflow_version=resource["workflowVersion"], + workflow_execution_id=resource["workflowExecutionId"], + status=resource["status"], + reason_for_failure=resource.get("reasonForFailure"), ) diff --git a/docs/source/workflow_orchestration.rst b/docs/source/data_workflows.rst similarity index 76% rename from docs/source/workflow_orchestration.rst rename to docs/source/data_workflows.rst index 002395270..81bcc3a3e 100644 --- a/docs/source/workflow_orchestration.rst +++ b/docs/source/data_workflows.rst @@ -71,6 +71,23 @@ Update Status of Async Task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. automethod:: cognite.client._api.workflows.WorkflowTaskAPI.update +Workflow Triggers +------------------- +Create triggers for workflow executions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. automethod:: cognite.client._api.workflows.WorkflowTriggerAPI.create + +Delete triggers for workflow executions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. automethod:: cognite.client._api.workflows.WorkflowTriggerAPI.delete + +Get triggers for workflow executions +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. automethod:: cognite.client._api.workflows.WorkflowTriggerAPI.get_triggers + +Get trigger run history for a workflow trigger +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. automethod:: cognite.client._api.workflows.WorkflowTriggerAPI.get_trigger_run_history Data Workflows data classes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/source/index.rst b/docs/source/index.rst index 2c6883410..f8d2044fc 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -53,7 +53,7 @@ Contents data_organization transformations functions - workflow_orchestration + data_workflows unit_catalog filters deprecated diff --git a/pyproject.toml b/pyproject.toml index a3566ee1b..f2c757338 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.55.1" +version = "7.55.2" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com" diff --git a/tests/tests_integration/test_api/test_data_workflows.py b/tests/tests_integration/test_api/test_data_workflows.py index 9a3c0f30b..7b87f44a7 100644 --- a/tests/tests_integration/test_api/test_data_workflows.py +++ b/tests/tests_integration/test_api/test_data_workflows.py @@ -253,7 +253,7 @@ def workflow_scheduled_trigger(cognite_client: CogniteClient, add_multiply_workf trigger = cognite_client.workflows.triggers.create( WorkflowTriggerCreate( external_id="integration_test-workflow-scheduled-trigger", - trigger_rule=WorkflowScheduledTriggerRule(cron_expression="0 0 * * *"), + trigger_rule=WorkflowScheduledTriggerRule(cron_expression="* * * * *"), workflow_external_id="integration_test-workflow-add_multiply", workflow_version="1", input={"a": 1, "b": 2}, @@ -490,7 +490,7 @@ def test_create_delete( ) -> None: assert workflow_scheduled_trigger is not None assert workflow_scheduled_trigger.external_id == "integration_test-workflow-scheduled-trigger" - assert workflow_scheduled_trigger.trigger_rule == WorkflowScheduledTriggerRule(cron_expression="0 0 * * *") + assert workflow_scheduled_trigger.trigger_rule == WorkflowScheduledTriggerRule(cron_expression="* * * * *") assert workflow_scheduled_trigger.workflow_external_id == "integration_test-workflow-add_multiply" assert workflow_scheduled_trigger.workflow_version == "1" assert workflow_scheduled_trigger.input == {"a": 1, "b": 2} From 7e3c677bb653c35c84daea3fd771cd1d6ad4b4e7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 07:53:45 +0200 Subject: [PATCH 5/6] chore(deps): lock file maintenance (#1901) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- poetry.lock | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/poetry.lock b/poetry.lock index 43f6bc5e2..24b9b0b2c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -132,13 +132,13 @@ tzdata = ["tzdata"] [[package]] name = "certifi" -version = "2024.7.4" +version = "2024.8.30" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = ">=3.6" files = [ - {file = "certifi-2024.7.4-py3-none-any.whl", hash = "sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90"}, - {file = "certifi-2024.7.4.tar.gz", hash = "sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b"}, + {file = "certifi-2024.8.30-py3-none-any.whl", hash = "sha256:922820b53db7a7257ffbda3f597266d435245903d80737e34f8a45ff3e3230d8"}, + {file = "certifi-2024.8.30.tar.gz", hash = "sha256:bec941d2aa8195e248a60b31ff9f0558284cf01a52591ceda73ea9afffd69fd9"}, ] [[package]] @@ -589,13 +589,13 @@ testing = ["hatch", "pre-commit", "pytest", "tox"] [[package]] name = "executing" -version = "2.0.1" +version = "2.1.0" description = "Get the currently executing AST node of a frame, and other information" optional = false -python-versions = ">=3.5" +python-versions = ">=3.8" files = [ - {file = "executing-2.0.1-py2.py3-none-any.whl", hash = "sha256:eac49ca94516ccc753f9fb5ce82603156e590b27525a8bc32cce8ae302eb61bc"}, - {file = "executing-2.0.1.tar.gz", hash = "sha256:35afe2ce3affba8ee97f2d69927fa823b08b472b7b994e36a52a964b93d16147"}, + {file = "executing-2.1.0-py2.py3-none-any.whl", hash = "sha256:8d63781349375b5ebccc3142f4b30350c0cd9c79f921cde38be2be4637e98eaf"}, + {file = "executing-2.1.0.tar.gz", hash = "sha256:8ea27ddd260da8150fa5a708269c4a10e76161e2496ec3e587da9e3c0fe4b9ab"}, ] [package.extras] @@ -1672,22 +1672,22 @@ wcwidth = "*" [[package]] name = "protobuf" -version = "5.27.4" +version = "5.28.0" description = "" optional = false python-versions = ">=3.8" files = [ - {file = "protobuf-5.27.4-cp310-abi3-win32.whl", hash = "sha256:10319748764b917a9a7cddef1582a0a9cd0f8f6d04e545c6236f7ccaf9b624d9"}, - {file = "protobuf-5.27.4-cp310-abi3-win_amd64.whl", hash = "sha256:f0c24374aaaf103f33662e4de7666a4a4280abebdb8a9f3f0f9b1d71b61174ec"}, - {file = "protobuf-5.27.4-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:e85fed07013e5a0121efbaf1b14355fdc66f6e545f12fc5985b2882370410006"}, - {file = "protobuf-5.27.4-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:d5a0e229061600842e57af4ff6a8522ede5280bcfa4fe7f3a1c20589377859a6"}, - {file = "protobuf-5.27.4-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:25ba1f0633f73c3939f3b84e1636f3eb3bab7196952ebb83906d56945edd6aa8"}, - {file = "protobuf-5.27.4-cp38-cp38-win32.whl", hash = "sha256:565b051249a2f8270af04206dd4f3b73a02343e7d9e072aed57441b369b3467d"}, - {file = "protobuf-5.27.4-cp38-cp38-win_amd64.whl", hash = "sha256:e673f173cbac4e59c7817ed358e471e4c77aa9166986edf3e731156379a556c7"}, - {file = "protobuf-5.27.4-cp39-cp39-win32.whl", hash = "sha256:25169c7624d5a9e669fa6faff5a6e818f854346d51ee347b2284676beb9e85dd"}, - {file = "protobuf-5.27.4-cp39-cp39-win_amd64.whl", hash = "sha256:1fe7735902e84ce35c4152cf07981c176713935a8efad78cea547aae5f4f75cb"}, - {file = "protobuf-5.27.4-py3-none-any.whl", hash = "sha256:b97259641e8d38738eef34a173e51d2d53a453baab01a32477a64752d9ce59a3"}, - {file = "protobuf-5.27.4.tar.gz", hash = "sha256:eaa1016e353d8fc5bf08c8087e96eed15f5297aa52bb7ee1f533278bb3f3aad7"}, + {file = "protobuf-5.28.0-cp310-abi3-win32.whl", hash = "sha256:66c3edeedb774a3508ae70d87b3a19786445fe9a068dd3585e0cefa8a77b83d0"}, + {file = "protobuf-5.28.0-cp310-abi3-win_amd64.whl", hash = "sha256:6d7cc9e60f976cf3e873acb9a40fed04afb5d224608ed5c1a105db4a3f09c5b6"}, + {file = "protobuf-5.28.0-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:532627e8fdd825cf8767a2d2b94d77e874d5ddb0adefb04b237f7cc296748681"}, + {file = "protobuf-5.28.0-cp38-abi3-manylinux2014_aarch64.whl", hash = "sha256:018db9056b9d75eb93d12a9d35120f97a84d9a919bcab11ed56ad2d399d6e8dd"}, + {file = "protobuf-5.28.0-cp38-abi3-manylinux2014_x86_64.whl", hash = "sha256:6206afcb2d90181ae8722798dcb56dc76675ab67458ac24c0dd7d75d632ac9bd"}, + {file = "protobuf-5.28.0-cp38-cp38-win32.whl", hash = "sha256:eef7a8a2f4318e2cb2dee8666d26e58eaf437c14788f3a2911d0c3da40405ae8"}, + {file = "protobuf-5.28.0-cp38-cp38-win_amd64.whl", hash = "sha256:d001a73c8bc2bf5b5c1360d59dd7573744e163b3607fa92788b7f3d5fefbd9a5"}, + {file = "protobuf-5.28.0-cp39-cp39-win32.whl", hash = "sha256:dde9fcaa24e7a9654f4baf2a55250b13a5ea701493d904c54069776b99a8216b"}, + {file = "protobuf-5.28.0-cp39-cp39-win_amd64.whl", hash = "sha256:853db610214e77ee817ecf0514e0d1d052dff7f63a0c157aa6eabae98db8a8de"}, + {file = "protobuf-5.28.0-py3-none-any.whl", hash = "sha256:510ed78cd0980f6d3218099e874714cdf0d8a95582e7b059b06cabad855ed0a0"}, + {file = "protobuf-5.28.0.tar.gz", hash = "sha256:dde74af0fa774fa98892209992295adbfb91da3fa98c8f67a88afe8f5a349add"}, ] [[package]] From 95178fdbeb8011ce8cb8eb640613939782aeaf17 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 06:14:22 +0000 Subject: [PATCH 6/6] chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.6.3 (#1900) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f39b5f2c5..e3667cdec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.2 + rev: v0.6.3 hooks: - id: ruff args: