|
| 1 | +"""Implementation of AssetManagementClient.""" |
| 2 | + |
| 3 | +from typing import List, Optional |
| 4 | + |
| 5 | +from nisystemlink.clients import core |
| 6 | +from nisystemlink.clients.core._http_configuration import HttpConfiguration |
| 7 | +from nisystemlink.clients.core._uplink._base_client import BaseClient |
| 8 | +from nisystemlink.clients.core._uplink._methods import post |
| 9 | +from uplink import Field, retry |
| 10 | + |
| 11 | +from . import models |
| 12 | + |
| 13 | + |
| 14 | +@retry( |
| 15 | + when=retry.when.status(408, 429, 502, 503, 504), |
| 16 | + stop=retry.stop.after_attempt(5), |
| 17 | + on_exception=retry.CONNECTION_ERROR, |
| 18 | +) |
| 19 | +class AssetManagementClient(BaseClient): |
| 20 | + def __init__(self, configuration: Optional[HttpConfiguration] = None): |
| 21 | + """Initialize an instance. |
| 22 | +
|
| 23 | + Args: |
| 24 | + configuration: Defines the web server to connect to and information about |
| 25 | + how to connect. If not provided, the |
| 26 | + :class:`HttpConfigurationManager <nisystemlink.clients.core.HttpConfigurationManager>` |
| 27 | + is used to obtain the configuration. |
| 28 | +
|
| 29 | + Raises: |
| 30 | + ApiException: If unable to communicate with the asset management Service. |
| 31 | + """ |
| 32 | + if configuration is None: |
| 33 | + configuration = core.HttpConfigurationManager.get_configuration() |
| 34 | + |
| 35 | + super().__init__(configuration, base_path="/niapm/v1/") |
| 36 | + |
| 37 | + @post("assets", args=[Field("assets")]) |
| 38 | + def create_assets( |
| 39 | + self, assets: List[models.CreateAssetRequest] |
| 40 | + ) -> models.CreateAssetsPartialSuccessResponse: |
| 41 | + """Create Assets. |
| 42 | +
|
| 43 | + Args: |
| 44 | + assets: Array of assets that should be created. |
| 45 | +
|
| 46 | + Returns: |
| 47 | + CreateAssetsPartialSuccessResponse: Array of created assets and array of failed. |
| 48 | +
|
| 49 | + Raises: |
| 50 | + ApiException: If unable to communicate with the asset management service or if there are invalid |
| 51 | + arguments. |
| 52 | + """ |
| 53 | + ... |
| 54 | + |
| 55 | + @post("query-assets") |
| 56 | + def __query_assets( |
| 57 | + self, query: models._QueryAssetsRequest |
| 58 | + ) -> models.QueryAssetsResponse: |
| 59 | + """Query Assets. |
| 60 | +
|
| 61 | + Args: |
| 62 | + query: Object containing filters to apply when retrieving assets. |
| 63 | +
|
| 64 | + Returns: |
| 65 | + QueryAssetsResponse: Assets Response containing the assets satisfying the query and |
| 66 | + the total count of matching assets. |
| 67 | +
|
| 68 | + Raises: |
| 69 | + ApiException: If unable to communicate with the asset management service or if there are invalid |
| 70 | + arguments. |
| 71 | + """ |
| 72 | + ... |
| 73 | + |
| 74 | + def query_assets( |
| 75 | + self, query: models.QueryAssetsRequest |
| 76 | + ) -> models.QueryAssetsResponse: |
| 77 | + """Query Assets. |
| 78 | +
|
| 79 | + Args: |
| 80 | + query: Object containing filters to apply when retrieving assets. |
| 81 | +
|
| 82 | + Returns: |
| 83 | + QueryAssetsResponse: Assets Response containing the assets satisfying the query and |
| 84 | + the total count of matching assets. |
| 85 | +
|
| 86 | + Raises: |
| 87 | + ApiException: If unable to communicate with the asset management service or if there are invalid |
| 88 | + arguments. |
| 89 | + """ |
| 90 | + projection_str = ( |
| 91 | + f"new({', '.join(projection.name for projection in query.projection)})" |
| 92 | + if query.projection |
| 93 | + else None |
| 94 | + ) |
| 95 | + query_params = { |
| 96 | + "filter": query.filter, |
| 97 | + "take": query.take, |
| 98 | + "skip": query.skip, |
| 99 | + "return_count": query.return_count, |
| 100 | + "order_by": query.order_by, |
| 101 | + "descending": query.descending, |
| 102 | + "projection": projection_str, |
| 103 | + } |
| 104 | + |
| 105 | + query_params = {k: v for k, v in query_params.items() if v is not None} |
| 106 | + |
| 107 | + query_request = models._QueryAssetsRequest(**query_params) |
| 108 | + |
| 109 | + return self.__query_assets(query=query_request) |
| 110 | + |
| 111 | + @post("delete-assets", args=[Field("ids")]) |
| 112 | + def delete_assets(self, ids: List[str]) -> models.DeleteAssetsResponse: |
| 113 | + """Delete Assets. |
| 114 | +
|
| 115 | + Args: |
| 116 | + ids: List of IDs of the assets to delete. |
| 117 | +
|
| 118 | + Returns: |
| 119 | + DeleteAssetsResponse: Response containing the IDs of the assets that were deleted. |
| 120 | +
|
| 121 | + Raises: |
| 122 | + ApiException: If unable to communicate with the asset management service or if there are invalid arguments. |
| 123 | + """ |
| 124 | + ... |
0 commit comments