| 1 |
|
| 2 |
|
| 3 |
import typing |
| 4 |
from json.decoder import JSONDecodeError |
| 5 |
|
| 6 |
from ...core.api_error import ApiError |
| 7 |
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 8 |
from ...core.jsonable_encoder import encode_path_param |
| 9 |
from ...core.pagination import AsyncPager, SyncPager |
| 10 |
from ...core.parse_error import ParsingError |
| 11 |
from ...core.pydantic_utilities import parse_obj_as |
| 12 |
from ...core.request_options import RequestOptions |
| 13 |
from ...errors.bad_request_error import BadRequestError |
| 14 |
from ...errors.forbidden_error import ForbiddenError |
| 15 |
from ...errors.not_found_error import NotFoundError |
| 16 |
from ...errors.too_many_requests_error import TooManyRequestsError |
| 17 |
from ...errors.unauthorized_error import UnauthorizedError |
| 18 |
from ...types.connection_for_list import ConnectionForList |
| 19 |
from ...types.connection_strategy_enum import ConnectionStrategyEnum |
| 20 |
from ...types.list_client_connections_response_content import ListClientConnectionsResponseContent |
| 21 |
from pydantic import ValidationError |
| 22 |
|
| 23 |
|
| 24 |
class RawConnectionsClient: |
| 25 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 26 |
self._client_wrapper = client_wrapper |
| 27 |
|
| 28 |
def get( |
| 29 |
self, |
| 30 |
id: str, |
| 31 |
*, |
| 32 |
strategy: typing.Optional[typing.Union[ConnectionStrategyEnum, typing.Sequence[ConnectionStrategyEnum]]] = None, |
| 33 |
from_: typing.Optional[str] = None, |
| 34 |
take: typing.Optional[int] = 50, |
| 35 |
fields: typing.Optional[str] = None, |
| 36 |
include_fields: typing.Optional[bool] = None, |
| 37 |
request_options: typing.Optional[RequestOptions] = None, |
| 38 |
) -> SyncPager[ConnectionForList, ListClientConnectionsResponseContent]: |
| 39 |
""" |
| 40 |
Retrieve all connections that are enabled for the specified [Application](https://www.auth0.com/docs/get-started/applications), using checkpoint pagination. A list of fields to include or exclude for each connection may also be specified. |
| 41 |
|
| 42 |
- This endpoint requires the `read:connections` scope and any one of `read:clients` or `read:client_summary`. |
| 43 |
- **Note**: The first time you call this endpoint, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no further results are remaining. |
| 44 |
|
| 45 |
Parameters |
| 46 |
---------- |
| 47 |
id : str |
| 48 |
ID of the client for which to retrieve enabled connections. |
| 49 |
|
| 50 |
strategy : typing.Optional[typing.Union[ConnectionStrategyEnum, typing.Sequence[ConnectionStrategyEnum]]] |
| 51 |
Provide strategies to only retrieve connections with such strategies |
| 52 |
|
| 53 |
from_ : typing.Optional[str] |
| 54 |
Optional Id from which to start selection. |
| 55 |
|
| 56 |
take : typing.Optional[int] |
| 57 |
Number of results per page. Defaults to 50. |
| 58 |
|
| 59 |
fields : typing.Optional[str] |
| 60 |
A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields |
| 61 |
|
| 62 |
include_fields : typing.Optional[bool] |
| 63 |
<code>true</code> if the fields specified are to be included in the result, <code>false</code> otherwise (defaults to <code>true</code>) |
| 64 |
|
| 65 |
request_options : typing.Optional[RequestOptions] |
| 66 |
Request-specific configuration. |
| 67 |
|
| 68 |
Returns |
| 69 |
------- |
| 70 |
SyncPager[ConnectionForList, ListClientConnectionsResponseContent] |
| 71 |
Success |
| 72 |
""" |
| 73 |
_response = self._client_wrapper.httpx_client.request( |
| 74 |
f"clients/{encode_path_param(id)}/connections", |
| 75 |
method="GET", |
| 76 |
params={ |
| 77 |
"strategy": strategy, |
| 78 |
"from": from_, |
| 79 |
"take": take, |
| 80 |
"fields": fields, |
| 81 |
"include_fields": include_fields, |
| 82 |
}, |
| 83 |
request_options=request_options, |
| 84 |
) |
| 85 |
try: |
| 86 |
if 200 <= _response.status_code < 300: |
| 87 |
_parsed_response = typing.cast( |
| 88 |
ListClientConnectionsResponseContent, |
| 89 |
parse_obj_as( |
| 90 |
type_=ListClientConnectionsResponseContent, |
| 91 |
object_=_response.json(), |
| 92 |
), |
| 93 |
) |
| 94 |
_items = _parsed_response.connections |
| 95 |
_parsed_next = _parsed_response.next |
| 96 |
_has_next = _parsed_next is not None and _parsed_next != "" |
| 97 |
_get_next = lambda: self.get( |
| 98 |
id, |
| 99 |
strategy=strategy, |
| 100 |
from_=_parsed_next, |
| 101 |
take=take, |
| 102 |
fields=fields, |
| 103 |
include_fields=include_fields, |
| 104 |
request_options=request_options, |
| 105 |
) |
| 106 |
return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 107 |
if _response.status_code == 400: |
| 108 |
raise BadRequestError( |
| 109 |
headers=dict(_response.headers), |
| 110 |
body=typing.cast( |
| 111 |
typing.Any, |
| 112 |
parse_obj_as( |
| 113 |
type_=typing.Any, |
| 114 |
object_=_response.json(), |
| 115 |
), |
| 116 |
), |
| 117 |
) |
| 118 |
if _response.status_code == 401: |
| 119 |
raise UnauthorizedError( |
| 120 |
headers=dict(_response.headers), |
| 121 |
body=typing.cast( |
| 122 |
typing.Any, |
| 123 |
parse_obj_as( |
| 124 |
type_=typing.Any, |
| 125 |
object_=_response.json(), |
| 126 |
), |
| 127 |
), |
| 128 |
) |
| 129 |
if _response.status_code == 403: |
| 130 |
raise ForbiddenError( |
| 131 |
headers=dict(_response.headers), |
| 132 |
body=typing.cast( |
| 133 |
typing.Any, |
| 134 |
parse_obj_as( |
| 135 |
type_=typing.Any, |
| 136 |
object_=_response.json(), |
| 137 |
), |
| 138 |
), |
| 139 |
) |
| 140 |
if _response.status_code == 404: |
| 141 |
raise NotFoundError( |
| 142 |
headers=dict(_response.headers), |
| 143 |
body=typing.cast( |
| 144 |
typing.Any, |
| 145 |
parse_obj_as( |
| 146 |
type_=typing.Any, |
| 147 |
object_=_response.json(), |
| 148 |
), |
| 149 |
), |
| 150 |
) |
| 151 |
if _response.status_code == 429: |
| 152 |
raise TooManyRequestsError( |
| 153 |
headers=dict(_response.headers), |
| 154 |
body=typing.cast( |
| 155 |
typing.Any, |
| 156 |
parse_obj_as( |
| 157 |
type_=typing.Any, |
| 158 |
object_=_response.json(), |
| 159 |
), |
| 160 |
), |
| 161 |
) |
| 162 |
_response_json = _response.json() |
| 163 |
except JSONDecodeError: |
| 164 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 165 |
except ValidationError as e: |
| 166 |
raise ParsingError( |
| 167 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 168 |
) |
| 169 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 170 |
|
| 171 |
|
| 172 |
class AsyncRawConnectionsClient: |
| 173 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 174 |
self._client_wrapper = client_wrapper |
| 175 |
|
| 176 |
async def get( |
| 177 |
self, |
| 178 |
id: str, |
| 179 |
*, |
| 180 |
strategy: typing.Optional[typing.Union[ConnectionStrategyEnum, typing.Sequence[ConnectionStrategyEnum]]] = None, |
| 181 |
from_: typing.Optional[str] = None, |
| 182 |
take: typing.Optional[int] = 50, |
| 183 |
fields: typing.Optional[str] = None, |
| 184 |
include_fields: typing.Optional[bool] = None, |
| 185 |
request_options: typing.Optional[RequestOptions] = None, |
| 186 |
) -> AsyncPager[ConnectionForList, ListClientConnectionsResponseContent]: |
| 187 |
""" |
| 188 |
Retrieve all connections that are enabled for the specified [Application](https://www.auth0.com/docs/get-started/applications), using checkpoint pagination. A list of fields to include or exclude for each connection may also be specified. |
| 189 |
|
| 190 |
- This endpoint requires the `read:connections` scope and any one of `read:clients` or `read:client_summary`. |
| 191 |
- **Note**: The first time you call this endpoint, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no further results are remaining. |
| 192 |
|
| 193 |
Parameters |
| 194 |
---------- |
| 195 |
id : str |
| 196 |
ID of the client for which to retrieve enabled connections. |
| 197 |
|
| 198 |
strategy : typing.Optional[typing.Union[ConnectionStrategyEnum, typing.Sequence[ConnectionStrategyEnum]]] |
| 199 |
Provide strategies to only retrieve connections with such strategies |
| 200 |
|
| 201 |
from_ : typing.Optional[str] |
| 202 |
Optional Id from which to start selection. |
| 203 |
|
| 204 |
take : typing.Optional[int] |
| 205 |
Number of results per page. Defaults to 50. |
| 206 |
|
| 207 |
fields : typing.Optional[str] |
| 208 |
A comma separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields |
| 209 |
|
| 210 |
include_fields : typing.Optional[bool] |
| 211 |
<code>true</code> if the fields specified are to be included in the result, <code>false</code> otherwise (defaults to <code>true</code>) |
| 212 |
|
| 213 |
request_options : typing.Optional[RequestOptions] |
| 214 |
Request-specific configuration. |
| 215 |
|
| 216 |
Returns |
| 217 |
------- |
| 218 |
AsyncPager[ConnectionForList, ListClientConnectionsResponseContent] |
| 219 |
Success |
| 220 |
""" |
| 221 |
_response = await self._client_wrapper.httpx_client.request( |
| 222 |
f"clients/{encode_path_param(id)}/connections", |
| 223 |
method="GET", |
| 224 |
params={ |
| 225 |
"strategy": strategy, |
| 226 |
"from": from_, |
| 227 |
"take": take, |
| 228 |
"fields": fields, |
| 229 |
"include_fields": include_fields, |
| 230 |
}, |
| 231 |
request_options=request_options, |
| 232 |
) |
| 233 |
try: |
| 234 |
if 200 <= _response.status_code < 300: |
| 235 |
_parsed_response = typing.cast( |
| 236 |
ListClientConnectionsResponseContent, |
| 237 |
parse_obj_as( |
| 238 |
type_=ListClientConnectionsResponseContent, |
| 239 |
object_=_response.json(), |
| 240 |
), |
| 241 |
) |
| 242 |
_items = _parsed_response.connections |
| 243 |
_parsed_next = _parsed_response.next |
| 244 |
_has_next = _parsed_next is not None and _parsed_next != "" |
| 245 |
|
| 246 |
async def _get_next(): |
| 247 |
return await self.get( |
| 248 |
id, |
| 249 |
strategy=strategy, |
| 250 |
from_=_parsed_next, |
| 251 |
take=take, |
| 252 |
fields=fields, |
| 253 |
include_fields=include_fields, |
| 254 |
request_options=request_options, |
| 255 |
) |
| 256 |
|
| 257 |
return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) |
| 258 |
if _response.status_code == 400: |
| 259 |
raise BadRequestError( |
| 260 |
headers=dict(_response.headers), |
| 261 |
body=typing.cast( |
| 262 |
typing.Any, |
| 263 |
parse_obj_as( |
| 264 |
type_=typing.Any, |
| 265 |
object_=_response.json(), |
| 266 |
), |
| 267 |
), |
| 268 |
) |
| 269 |
if _response.status_code == 401: |
| 270 |
raise UnauthorizedError( |
| 271 |
headers=dict(_response.headers), |
| 272 |
body=typing.cast( |
| 273 |
typing.Any, |
| 274 |
parse_obj_as( |
| 275 |
type_=typing.Any, |
| 276 |
object_=_response.json(), |
| 277 |
), |
| 278 |
), |
| 279 |
) |
| 280 |
if _response.status_code == 403: |
| 281 |
raise ForbiddenError( |
| 282 |
headers=dict(_response.headers), |
| 283 |
body=typing.cast( |
| 284 |
typing.Any, |
| 285 |
parse_obj_as( |
| 286 |
type_=typing.Any, |
| 287 |
object_=_response.json(), |
| 288 |
), |
| 289 |
), |
| 290 |
) |
| 291 |
if _response.status_code == 404: |
| 292 |
raise NotFoundError( |
| 293 |
headers=dict(_response.headers), |
| 294 |
body=typing.cast( |
| 295 |
typing.Any, |
| 296 |
parse_obj_as( |
| 297 |
type_=typing.Any, |
| 298 |
object_=_response.json(), |
| 299 |
), |
| 300 |
), |
| 301 |
) |
| 302 |
if _response.status_code == 429: |
| 303 |
raise TooManyRequestsError( |
| 304 |
headers=dict(_response.headers), |
| 305 |
body=typing.cast( |
| 306 |
typing.Any, |
| 307 |
parse_obj_as( |
| 308 |
type_=typing.Any, |
| 309 |
object_=_response.json(), |
| 310 |
), |
| 311 |
), |
| 312 |
) |
| 313 |
_response_json = _response.json() |
| 314 |
except JSONDecodeError: |
| 315 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 316 |
except ValidationError as e: |
| 317 |
raise ParsingError( |
| 318 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 319 |
) |
| 320 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |