# This file was auto-generated by Fern from our API Definition.
import typing
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.http_response import AsyncHttpResponse, HttpResponse
from ...core.jsonable_encoder import encode_path_param
from ...core.pagination import AsyncPager, SyncPager
from ...core.parse_error import ParsingError
from ...core.pydantic_utilities import parse_obj_as
from ...core.request_options import RequestOptions
from ...core.serialization import convert_and_respect_annotation_metadata
from ...errors.bad_request_error import BadRequestError
from ...errors.conflict_error import ConflictError
from ...errors.forbidden_error import ForbiddenError
from ...errors.not_found_error import NotFoundError
from ...errors.too_many_requests_error import TooManyRequestsError
from ...errors.unauthorized_error import UnauthorizedError
from ...types.create_directory_provisioning_request_content import CreateDirectoryProvisioningRequestContent
from ...types.create_directory_provisioning_response_content import CreateDirectoryProvisioningResponseContent
from ...types.directory_provisioning import DirectoryProvisioning
from ...types.get_directory_provisioning_default_mapping_response_content import (
GetDirectoryProvisioningDefaultMappingResponseContent,
)
from ...types.get_directory_provisioning_response_content import GetDirectoryProvisioningResponseContent
from ...types.list_directory_provisionings_response_content import ListDirectoryProvisioningsResponseContent
from ...types.list_synchronized_groups_response_content import ListSynchronizedGroupsResponseContent
from ...types.synchronized_group_payload import SynchronizedGroupPayload
from ...types.update_directory_provisioning_request_content import UpdateDirectoryProvisioningRequestContent
from ...types.update_directory_provisioning_response_content import UpdateDirectoryProvisioningResponseContent
from pydantic import ValidationError
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class RawDirectoryProvisioningClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._client_wrapper = client_wrapper
def list(
self,
*,
from_: typing.Optional[str] = None,
take: typing.Optional[int] = 50,
request_options: typing.Optional[RequestOptions] = None,
) -> SyncPager[DirectoryProvisioning, ListDirectoryProvisioningsResponseContent]:
"""
Retrieve a list of directory provisioning configurations of a tenant.
Parameters
----------
from_ : typing.Optional[str]
Optional Id from which to start selection.
take : typing.Optional[int]
Number of results per page. Defaults to 50.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SyncPager[DirectoryProvisioning, ListDirectoryProvisioningsResponseContent]
The tenant's directory provisioning configuration. See Response Schemas for schema.
"""
_response = self._client_wrapper.httpx_client.request(
"connections-directory-provisionings",
method="GET",
params={
"from": from_,
"take": take,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_parsed_response = typing.cast(
ListDirectoryProvisioningsResponseContent,
parse_obj_as(
type_=ListDirectoryProvisioningsResponseContent, # type: ignore
object_=_response.json(),
),
)
_items = _parsed_response.directory_provisionings
_parsed_next = _parsed_response.next
_has_next = _parsed_next is not None and _parsed_next != ""
_get_next = lambda: self.list(
from_=_parsed_next,
take=take,
request_options=request_options,
)
return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def get(
self, id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> HttpResponse[GetDirectoryProvisioningResponseContent]:
"""
Retrieve the directory provisioning configuration of a connection.
Parameters
----------
id : str
The id of the connection to retrieve its directory provisioning configuration
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[GetDirectoryProvisioningResponseContent]
The connection's directory provisioning configuration. See Response Schemas for schema.
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
GetDirectoryProvisioningResponseContent,
parse_obj_as(
type_=GetDirectoryProvisioningResponseContent, # type: ignore
object_=_response.json(),
),
)
return HttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def create(
self,
id: str,
*,
request: typing.Optional[CreateDirectoryProvisioningRequestContent] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[CreateDirectoryProvisioningResponseContent]:
"""
Create a directory provisioning configuration for a connection.
Parameters
----------
id : str
The id of the connection to create its directory provisioning configuration
request : typing.Optional[CreateDirectoryProvisioningRequestContent]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[CreateDirectoryProvisioningResponseContent]
The connection's directory provisioning configuration was created. See Response Schemas for schema.
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning",
method="POST",
json=convert_and_respect_annotation_metadata(
object_=request,
annotation=typing.Optional[CreateDirectoryProvisioningRequestContent],
direction="write",
),
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
CreateDirectoryProvisioningResponseContent,
parse_obj_as(
type_=CreateDirectoryProvisioningResponseContent, # type: ignore
object_=_response.json(),
),
)
return HttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 409:
raise ConflictError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
"""
Delete the directory provisioning configuration of a connection.
Parameters
----------
id : str
The id of the connection to delete its directory provisioning configuration
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[None]
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning",
method="DELETE",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return HttpResponse(response=_response, data=None)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def update(
self,
id: str,
*,
request: typing.Optional[UpdateDirectoryProvisioningRequestContent] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[UpdateDirectoryProvisioningResponseContent]:
"""
Update the directory provisioning configuration of a connection.
Parameters
----------
id : str
The id of the connection to create its directory provisioning configuration
request : typing.Optional[UpdateDirectoryProvisioningRequestContent]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[UpdateDirectoryProvisioningResponseContent]
The connection's directory provisioning configuration was updated. See Response Schemas for schema.
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning",
method="PATCH",
json=convert_and_respect_annotation_metadata(
object_=request,
annotation=typing.Optional[UpdateDirectoryProvisioningRequestContent],
direction="write",
),
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
UpdateDirectoryProvisioningResponseContent,
parse_obj_as(
type_=UpdateDirectoryProvisioningResponseContent, # type: ignore
object_=_response.json(),
),
)
return HttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def get_default_mapping(
self, id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> HttpResponse[GetDirectoryProvisioningDefaultMappingResponseContent]:
"""
Retrieve the directory provisioning default attribute mapping of a connection.
Parameters
----------
id : str
The id of the connection to retrieve its directory provisioning configuration
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[GetDirectoryProvisioningDefaultMappingResponseContent]
The connection's directory provisioning default mapping. See Response Schemas for schema.
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning/default-mapping",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
GetDirectoryProvisioningDefaultMappingResponseContent,
parse_obj_as(
type_=GetDirectoryProvisioningDefaultMappingResponseContent, # type: ignore
object_=_response.json(),
),
)
return HttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def list_synchronized_groups(
self,
id: str,
*,
from_: typing.Optional[str] = None,
take: typing.Optional[int] = 50,
request_options: typing.Optional[RequestOptions] = None,
) -> SyncPager[SynchronizedGroupPayload, ListSynchronizedGroupsResponseContent]:
"""
Retrieve the configured synchronized groups for a connection directory provisioning configuration.
Parameters
----------
id : str
The id of the connection to list synchronized groups for.
from_ : typing.Optional[str]
Optional Id from which to start selection.
take : typing.Optional[int]
Number of results per page. Defaults to 50.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SyncPager[SynchronizedGroupPayload, ListSynchronizedGroupsResponseContent]
The connection's synchronized groups. See Response Schemas for schema.
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning/synchronized-groups",
method="GET",
params={
"from": from_,
"take": take,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_parsed_response = typing.cast(
ListSynchronizedGroupsResponseContent,
parse_obj_as(
type_=ListSynchronizedGroupsResponseContent, # type: ignore
object_=_response.json(),
),
)
_items = _parsed_response.groups
_parsed_next = _parsed_response.next
_has_next = _parsed_next is not None and _parsed_next != ""
_get_next = lambda: self.list_synchronized_groups(
id,
from_=_parsed_next,
take=take,
request_options=request_options,
)
return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
def set(
self,
id: str,
*,
groups: typing.Sequence[SynchronizedGroupPayload],
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[None]:
"""
Create or replace the selected groups for a connection directory provisioning configuration.
Parameters
----------
id : str
The id of the connection to create or replace synchronized groups for
groups : typing.Sequence[SynchronizedGroupPayload]
Array of Google Workspace Directory group objects to synchronize.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
HttpResponse[None]
"""
_response = self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning/synchronized-groups",
method="PUT",
json={
"groups": convert_and_respect_annotation_metadata(
object_=groups, annotation=typing.Sequence[SynchronizedGroupPayload], direction="write"
),
},
headers={
"content-type": "application/json",
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return HttpResponse(response=_response, data=None)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 409:
raise ConflictError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
class AsyncRawDirectoryProvisioningClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._client_wrapper = client_wrapper
async def list(
self,
*,
from_: typing.Optional[str] = None,
take: typing.Optional[int] = 50,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncPager[DirectoryProvisioning, ListDirectoryProvisioningsResponseContent]:
"""
Retrieve a list of directory provisioning configurations of a tenant.
Parameters
----------
from_ : typing.Optional[str]
Optional Id from which to start selection.
take : typing.Optional[int]
Number of results per page. Defaults to 50.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncPager[DirectoryProvisioning, ListDirectoryProvisioningsResponseContent]
The tenant's directory provisioning configuration. See Response Schemas for schema.
"""
_response = await self._client_wrapper.httpx_client.request(
"connections-directory-provisionings",
method="GET",
params={
"from": from_,
"take": take,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_parsed_response = typing.cast(
ListDirectoryProvisioningsResponseContent,
parse_obj_as(
type_=ListDirectoryProvisioningsResponseContent, # type: ignore
object_=_response.json(),
),
)
_items = _parsed_response.directory_provisionings
_parsed_next = _parsed_response.next
_has_next = _parsed_next is not None and _parsed_next != ""
async def _get_next():
return await self.list(
from_=_parsed_next,
take=take,
request_options=request_options,
)
return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def get(
self, id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> AsyncHttpResponse[GetDirectoryProvisioningResponseContent]:
"""
Retrieve the directory provisioning configuration of a connection.
Parameters
----------
id : str
The id of the connection to retrieve its directory provisioning configuration
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[GetDirectoryProvisioningResponseContent]
The connection's directory provisioning configuration. See Response Schemas for schema.
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
GetDirectoryProvisioningResponseContent,
parse_obj_as(
type_=GetDirectoryProvisioningResponseContent, # type: ignore
object_=_response.json(),
),
)
return AsyncHttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def create(
self,
id: str,
*,
request: typing.Optional[CreateDirectoryProvisioningRequestContent] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[CreateDirectoryProvisioningResponseContent]:
"""
Create a directory provisioning configuration for a connection.
Parameters
----------
id : str
The id of the connection to create its directory provisioning configuration
request : typing.Optional[CreateDirectoryProvisioningRequestContent]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[CreateDirectoryProvisioningResponseContent]
The connection's directory provisioning configuration was created. See Response Schemas for schema.
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning",
method="POST",
json=convert_and_respect_annotation_metadata(
object_=request,
annotation=typing.Optional[CreateDirectoryProvisioningRequestContent],
direction="write",
),
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
CreateDirectoryProvisioningResponseContent,
parse_obj_as(
type_=CreateDirectoryProvisioningResponseContent, # type: ignore
object_=_response.json(),
),
)
return AsyncHttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 409:
raise ConflictError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def delete(
self, id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> AsyncHttpResponse[None]:
"""
Delete the directory provisioning configuration of a connection.
Parameters
----------
id : str
The id of the connection to delete its directory provisioning configuration
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[None]
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning",
method="DELETE",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return AsyncHttpResponse(response=_response, data=None)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def update(
self,
id: str,
*,
request: typing.Optional[UpdateDirectoryProvisioningRequestContent] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[UpdateDirectoryProvisioningResponseContent]:
"""
Update the directory provisioning configuration of a connection.
Parameters
----------
id : str
The id of the connection to create its directory provisioning configuration
request : typing.Optional[UpdateDirectoryProvisioningRequestContent]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[UpdateDirectoryProvisioningResponseContent]
The connection's directory provisioning configuration was updated. See Response Schemas for schema.
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning",
method="PATCH",
json=convert_and_respect_annotation_metadata(
object_=request,
annotation=typing.Optional[UpdateDirectoryProvisioningRequestContent],
direction="write",
),
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
UpdateDirectoryProvisioningResponseContent,
parse_obj_as(
type_=UpdateDirectoryProvisioningResponseContent, # type: ignore
object_=_response.json(),
),
)
return AsyncHttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def get_default_mapping(
self, id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> AsyncHttpResponse[GetDirectoryProvisioningDefaultMappingResponseContent]:
"""
Retrieve the directory provisioning default attribute mapping of a connection.
Parameters
----------
id : str
The id of the connection to retrieve its directory provisioning configuration
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[GetDirectoryProvisioningDefaultMappingResponseContent]
The connection's directory provisioning default mapping. See Response Schemas for schema.
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning/default-mapping",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_data = typing.cast(
GetDirectoryProvisioningDefaultMappingResponseContent,
parse_obj_as(
type_=GetDirectoryProvisioningDefaultMappingResponseContent, # type: ignore
object_=_response.json(),
),
)
return AsyncHttpResponse(response=_response, data=_data)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def list_synchronized_groups(
self,
id: str,
*,
from_: typing.Optional[str] = None,
take: typing.Optional[int] = 50,
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncPager[SynchronizedGroupPayload, ListSynchronizedGroupsResponseContent]:
"""
Retrieve the configured synchronized groups for a connection directory provisioning configuration.
Parameters
----------
id : str
The id of the connection to list synchronized groups for.
from_ : typing.Optional[str]
Optional Id from which to start selection.
take : typing.Optional[int]
Number of results per page. Defaults to 50.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncPager[SynchronizedGroupPayload, ListSynchronizedGroupsResponseContent]
The connection's synchronized groups. See Response Schemas for schema.
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning/synchronized-groups",
method="GET",
params={
"from": from_,
"take": take,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
_parsed_response = typing.cast(
ListSynchronizedGroupsResponseContent,
parse_obj_as(
type_=ListSynchronizedGroupsResponseContent, # type: ignore
object_=_response.json(),
),
)
_items = _parsed_response.groups
_parsed_next = _parsed_response.next
_has_next = _parsed_next is not None and _parsed_next != ""
async def _get_next():
return await self.list_synchronized_groups(
id,
from_=_parsed_next,
take=take,
request_options=request_options,
)
return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
async def set(
self,
id: str,
*,
groups: typing.Sequence[SynchronizedGroupPayload],
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[None]:
"""
Create or replace the selected groups for a connection directory provisioning configuration.
Parameters
----------
id : str
The id of the connection to create or replace synchronized groups for
groups : typing.Sequence[SynchronizedGroupPayload]
Array of Google Workspace Directory group objects to synchronize.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AsyncHttpResponse[None]
"""
_response = await self._client_wrapper.httpx_client.request(
f"connections/{encode_path_param(id)}/directory-provisioning/synchronized-groups",
method="PUT",
json={
"groups": convert_and_respect_annotation_metadata(
object_=groups, annotation=typing.Sequence[SynchronizedGroupPayload], direction="write"
),
},
headers={
"content-type": "application/json",
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return AsyncHttpResponse(response=_response, data=None)
if _response.status_code == 400:
raise BadRequestError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 401:
raise UnauthorizedError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 403:
raise ForbiddenError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 404:
raise NotFoundError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 409:
raise ConflictError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
if _response.status_code == 429:
raise TooManyRequestsError(
headers=dict(_response.headers),
body=typing.cast(
typing.Any,
parse_obj_as(
type_=typing.Any, # type: ignore
object_=_response.json(),
),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
except ValidationError as e:
raise ParsingError(
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)