Source code for pydelfini.delfini_core.api.cde.cdes_update_cdeset

"""Update a CDE set's metadata"""

from http import HTTPStatus
from typing import Any
from typing import cast
from typing import Dict
from typing import Union

import httpx

from ... import errors
from ...client import AuthenticatedClient
from ...client import Client
from ...models.cdes_update_cdeset_body import CdesUpdateCdesetBody
from ...models.server_error import ServerError
from ...types import Response


def _get_kwargs(
    cdeset_name: str,
    *,
    body: CdesUpdateCdesetBody,
) -> Dict[str, Any]:
    headers: Dict[str, Any] = {}

    _kwargs: Dict[str, Any] = {
        "method": "put",
        "url": "/cde/{cdeset_name}".format(
            cdeset_name=cdeset_name,
        ),
    }

    _body = body.to_dict()

    _kwargs["json"] = _body
    headers["Content-Type"] = "application/json"

    _kwargs["headers"] = headers
    return _kwargs


def _parse_response(
    *, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Union[Any, ServerError]:
    if response.status_code == HTTPStatus.NO_CONTENT:
        response_204 = cast(Any, {"attribute": "None", "return_type": "None"})
        return response_204
    if response.status_code == HTTPStatus.UNAUTHORIZED:
        response_401 = ServerError.from_dict(response.json())

        return response_401
    if response.status_code == HTTPStatus.FORBIDDEN:
        response_403 = ServerError.from_dict(response.json())

        return response_403
    if response.status_code == HTTPStatus.NOT_FOUND:
        response_404 = ServerError.from_dict(response.json())

        return response_404
    if response.status_code == HTTPStatus.UNSUPPORTED_MEDIA_TYPE:
        response_415 = ServerError.from_dict(response.json())

        return response_415
    if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
        response_500 = ServerError.from_dict(response.json())

        return response_500

    raise errors.UnexpectedStatus(response.status_code, response.content)


def _build_response(
    *, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[Union[Any, ServerError]]:
    return Response(
        status_code=HTTPStatus(response.status_code),
        content=response.content,
        headers=response.headers,
        parsed=_parse_response(client=client, response=response),
    )


[docs] def sync_detailed( cdeset_name: str, *, client: AuthenticatedClient, body: CdesUpdateCdesetBody, ) -> Response[Union[Any, ServerError]]: """Update a CDE set's metadata Update the description, display name, state and/or default flag of a CDE set. Fields that are omitted are left unchanged. The set's data elements are not affected; use the dictionary `copy-to-cde` operation to add elements. Admin access is required. Args: cdeset_name (str): body (CdesUpdateCdesetBody): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Response[Union[Any, ServerError]] """ kwargs = _get_kwargs( cdeset_name=cdeset_name, body=body, ) response = client.get_httpx_client().request( **kwargs, ) return _build_response(client=client, response=response)
[docs] def sync( cdeset_name: str, *, client: AuthenticatedClient, body: CdesUpdateCdesetBody, ) -> Union[Any]: """Update a CDE set's metadata Update the description, display name, state and/or default flag of a CDE set. Fields that are omitted are left unchanged. The set's data elements are not affected; use the dictionary `copy-to-cde` operation to add elements. Admin access is required. Args: cdeset_name (str): body (CdesUpdateCdesetBody): Raises: errors.UnexpectedStatus: If the server returns a status code greater than or equal to 300. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Union[Any] """ response = sync_detailed( cdeset_name=cdeset_name, client=client, body=body, ) if isinstance(response.parsed, ServerError): raise errors.UnexpectedStatus(response.status_code, response.content) return response.parsed
[docs] async def asyncio_detailed( cdeset_name: str, *, client: AuthenticatedClient, body: CdesUpdateCdesetBody, ) -> Response[Union[Any, ServerError]]: """Update a CDE set's metadata Update the description, display name, state and/or default flag of a CDE set. Fields that are omitted are left unchanged. The set's data elements are not affected; use the dictionary `copy-to-cde` operation to add elements. Admin access is required. Args: cdeset_name (str): body (CdesUpdateCdesetBody): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Response[Union[Any, ServerError]] """ kwargs = _get_kwargs( cdeset_name=cdeset_name, body=body, ) response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response)
[docs] async def asyncio( cdeset_name: str, *, client: AuthenticatedClient, body: CdesUpdateCdesetBody, ) -> Union[Any]: """Update a CDE set's metadata Update the description, display name, state and/or default flag of a CDE set. Fields that are omitted are left unchanged. The set's data elements are not affected; use the dictionary `copy-to-cde` operation to add elements. Admin access is required. Args: cdeset_name (str): body (CdesUpdateCdesetBody): Raises: errors.UnexpectedStatus: If the server returns a status code greater than or equal to 300. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Union[Any] """ response = await asyncio_detailed( cdeset_name=cdeset_name, client=client, body=body, ) if isinstance(response.parsed, ServerError): raise errors.UnexpectedStatus(response.status_code, response.content) return response.parsed