Skip to content

Commit

Permalink
Add example on how to update the nonce for transformations (#1517)
Browse files Browse the repository at this point in the history
Co-authored-by: Håkon V. Treider <[email protected]>
  • Loading branch information
muradsater and haakonvt authored Nov 23, 2023
1 parent ea987c4 commit 4543658
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions cognite/client/_api/transformations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,28 @@ def update(
Perform a partial update on a transformation, updating the query and making it private::
>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import TransformationUpdate
>>> c = CogniteClient()
>>> my_update = TransformationUpdate(id=1).query.set("SELECT * FROM _cdf.assets").is_public.set(False)
>>> res = c.transformations.update(my_update)
"""
Update the session used for reading (source) and writing (destination) when authenticating for all
transformations in a given data set:
>>> from cognite.client.data_classes import NonceCredentials
>>> to_update = c.transformations.list(data_set_external_ids=["foo"])
>>> new_session = c.iam.sessions.create()
>>> new_nonce = NonceCredentials(
... session_id=new_session.id,
... nonce=new_session.nonce,
... cdf_project_name=c.config.project
... )
>>> for tr in to_update:
... tr.source_nonce = new_nonce
... tr.destination_nonce = new_nonce
>>> res = c.transformations.update(to_update)
"""
if isinstance(item, Sequence):
item = list(item).copy()
item = list(item)
sessions: dict[str, NonceCredentials] = {}
for i, t in enumerate(item):
if isinstance(t, Transformation):
Expand All @@ -321,7 +334,7 @@ def update(
item._process_credentials(keep_none=True)
elif not isinstance(item, TransformationUpdate):
raise TypeError(
"item must be Sequence[Transformation], Transformation, Sequence[TransformationUpdate] or TransformationUpdate"
"item must be one of: TransformationUpdate, Transformation, Sequence[TransformationUpdate | Transformation]."
)

return self._update_multiple(
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/data_classes/transformations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class TransformationFilter(CogniteFilter):
has_blocked_error (bool | None): Whether only the blocked transformations should be included in the results.
created_time (dict[str, Any] | TimestampRange | None): Range between two timestamps
last_updated_time (dict[str, Any] | TimestampRange | None): Range between two timestamps
data_set_ids (list[dict[str, Any]] | None): Return only transformations in the specified data sets with these ids.
data_set_ids (list[dict[str, Any]] | None): Return only transformations in the specified data sets with these ids, e.g. [{"id": 1}, {"externalId": "foo"}].
tags (TagsFilter | None): Return only the resource matching the specified tags constraints. It only supports ContainsAny as of now.
"""

Expand Down

0 comments on commit 4543658

Please sign in to comment.