From 1de9d9583ff1bce021e7b8c253ebe3662cbea5bb Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Fri, 21 Jun 2024 18:47:28 +0530 Subject: [PATCH 01/14] chore: oauth sdk implementation --- twilio/http/BaseHttpClient.py | 0 twilio/http/bearer_token_http_client.py | 0 twilio/http/no_auth_http_client.py | 0 twilio/rest/__init__.py | 14 + twilio/rest/preview_iam/PreviewIamBase.py | 29 + twilio/rest/preview_iam/__init__.py | 0 .../organizations_openapi/account.py | 826 ++++++++++++++++++ .../organizations_openapi/authorize.py | 121 +++ .../organizations_openapi/__init__.py | 51 ++ .../organizations_openapi/resource_type.py | 290 ++++++ .../organizations_openapi/role_assignment.py | 698 +++++++++++++++ .../organizations_openapi/token.py | 331 +++++++ twilio/twilio_bearer_token_auth.py | 56 ++ twilio/twilio_no_auth.py | 33 + 14 files changed, 2449 insertions(+) create mode 100644 twilio/http/BaseHttpClient.py create mode 100644 twilio/http/bearer_token_http_client.py create mode 100644 twilio/http/no_auth_http_client.py create mode 100644 twilio/rest/preview_iam/PreviewIamBase.py create mode 100644 twilio/rest/preview_iam/__init__.py create mode 100644 twilio/rest/preview_iam/organizations_openapi/account.py create mode 100644 twilio/rest/preview_iam/organizations_openapi/authorize.py create mode 100644 twilio/rest/preview_iam/organizations_openapi/organizations_openapi/__init__.py create mode 100644 twilio/rest/preview_iam/organizations_openapi/resource_type.py create mode 100644 twilio/rest/preview_iam/organizations_openapi/role_assignment.py create mode 100644 twilio/rest/preview_iam/organizations_openapi/token.py create mode 100644 twilio/twilio_bearer_token_auth.py create mode 100644 twilio/twilio_no_auth.py diff --git a/twilio/http/BaseHttpClient.py b/twilio/http/BaseHttpClient.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/twilio/http/bearer_token_http_client.py b/twilio/http/bearer_token_http_client.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/twilio/http/no_auth_http_client.py b/twilio/http/no_auth_http_client.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/twilio/rest/__init__.py b/twilio/rest/__init__.py index 2dc0a4930f..e6e57bafd1 100644 --- a/twilio/rest/__init__.py +++ b/twilio/rest/__init__.py @@ -143,6 +143,7 @@ def __init__( self._numbers: Optional["Numbers"] = None self._oauth: Optional["Oauth"] = None self._preview: Optional["Preview"] = None + self._preview_iam: Optional["PreviewIam"] = None self._pricing: Optional["Pricing"] = None self._proxy: Optional["Proxy"] = None self._routes: Optional["Routes"] = None @@ -431,6 +432,19 @@ def preview(self) -> "Preview": self._preview = Preview(self) return self._preview + @property + def preview_iam(self) -> "PreviewIam": + """ + Access the Preview Twilio Domain + + :returns: Preview Twilio Domain + """ + if self._preview_iam is None: + from twilio.rest.preview_iam import PreviewIam + + self._preview = PreviewIam(self) + return self._preview_iam + @property def pricing(self) -> "Pricing": """ diff --git a/twilio/rest/preview_iam/PreviewIamBase.py b/twilio/rest/preview_iam/PreviewIamBase.py new file mode 100644 index 0000000000..9cf1f3bac3 --- /dev/null +++ b/twilio/rest/preview_iam/PreviewIamBase.py @@ -0,0 +1,29 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" +from twilio.base.domain import Domain +from twilio.rest import Client +from twilio.rest.preview_iam.organizations_openapi.token import Token +from twilio.rest.preview_iam.organizations_openapi.account import Account +from twilio.rest.preview_iam.organizations_openapi.authorize import AuthorizeList +from twilio.rest.preview_iam.organizations_openapi.resource_type import ResourceTypeList +from twilio.rest.preview_iam.organizations_openapi.role_assignment import RoleAssignmentList + +class PreviewIamBase(Domain): + def __init__(self, twilio: Client): + """ + Initialize the PreviewIam Domain + + :returns: Domain for PreviewIam + """ + super().__init__(twilio, "https://preview.twilio.com/iam") + self._token: Optional[TokenList] = None + self._service_accounts: Optional[ServiceAccounts] = None + self._service_roles: Optional[ServiceRoles] = None \ No newline at end of file diff --git a/twilio/rest/preview_iam/__init__.py b/twilio/rest/preview_iam/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/twilio/rest/preview_iam/organizations_openapi/account.py b/twilio/rest/preview_iam/organizations_openapi/account.py new file mode 100644 index 0000000000..085dcc62f2 --- /dev/null +++ b/twilio/rest/preview_iam/organizations_openapi/account.py @@ -0,0 +1,826 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" +import os +from datetime import date, datetime +from decimal import Decimal +from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator +from twilio.base import deserialize, serialize, values +from twilio.base.instance_context import InstanceContext +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version +from twilio.base.page import Page +from twilio.rest.preview_iam.organizations_openapi.token import TokenList +from twilio.twilio_bearer_token_auth import TwilioBearerTokenAuth + + +class AccountInstance(InstanceResource): + + """ + :ivar account_sid: Twilio account sid + :ivar friendly_name: Account friendly name + :ivar status: Account status + :ivar owner_sid: Twilio account sid + :ivar date_created: The date and time when the account was created in the system + """ + + def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: Optional[str] = None, account_sid: Optional[str] = None): + super().__init__(version) + + + self.account_sid: Optional[str] = payload.get("account_sid") + self.friendly_name: Optional[str] = payload.get("friendly_name") + self.status: Optional[str] = payload.get("status") + self.owner_sid: Optional[str] = payload.get("owner_sid") + self.date_created: Optional[datetime] = deserialize.iso8601_datetime(payload.get("date_created")) + + + self._solution = { + "organization_sid": organization_sid or self.organization_sid, + "account_sid": account_sid or self.account_sid, + } + self._context: Optional[AccountContext] = None + + @property + def _proxy(self) -> "AccountContext": + """ + Generate an instance context for the instance, the context is capable of + performing various actions. All instance actions are proxied to the context + + :returns: AccountContext for this AccountInstance + """ + if self._context is None: + self._context = AccountContext(self._version, organization_sid=self._solution['organization_sid'], account_sid=self._solution['account_sid'],) + return self._context + + + def fetch(self) -> "AccountInstance": + """ + Fetch the AccountInstance + + + :returns: The fetched AccountInstance + """ + return self._proxy.fetch() + + async def fetch_async(self) -> "AccountInstance": + """ + Asynchronous coroutine to fetch the AccountInstance + + + :returns: The fetched AccountInstance + """ + return await self._proxy.fetch_async() + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) + return ''.format(context) + +class AccountContext(InstanceContext): + + def __init__(self, version: Version, organization_sid: str, account_sid: str): + """ + Initialize the AccountContext + + :param version: Version that contains the resource + :param organization_sid: + :param account_sid: + """ + super().__init__(version) + + + # Path Solution + self._solution = { + 'organization_sid': organization_sid, + 'account_sid': account_sid, + } + self._uri = '/{organization_sid}/Accounts/{account_sid}'.format(**self._solution) + + + def fetch(self) -> AccountInstance: + """ + Fetch the AccountInstance + + + :returns: The fetched AccountInstance + """ + headers = {} + if True: + if TwilioBearerTokenAuth.get_access_token() is None: + accessToken = TokenList('v1').create(grant_type='client_credentials', + client_id=os.environ('CLIENT_ID'), + client_secret=os.environ('CLIENT_SECRET'), + username='',password='') + TwilioBearerTokenAuth.init(accessToken) + else: + accessToken = TwilioBearerTokenAuth.get_access_token() + headers = {'Authorization': 'Bearer '+accessToken} + + payload = self._version.fetch(method='GET', uri=self._uri, headers=headers) + + return AccountInstance( + self._version, + payload, + organization_sid=self._solution['organization_sid'], + account_sid=self._solution['account_sid'], + + ) + + async def fetch_async(self) -> AccountInstance: + """ + Asynchronous coroutine to fetch the AccountInstance + + + :returns: The fetched AccountInstance + """ + + payload = await self._version.fetch_async(method='GET', uri=self._uri, ) + + return AccountInstance( + self._version, + payload, + organization_sid=self._solution['organization_sid'], + account_sid=self._solution['account_sid'], + + ) + + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) + return ''.format(context) + + + + + +class AccountPage(Page): + + def get_instance(self, payload: Dict[str, Any]) -> AccountInstance: + """ + Build an instance of AccountInstance + + :param payload: Payload response from the API + """ + return AccountInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" + + + + +class AccountPage(Page): + + def get_instance(self, payload: Dict[str, Any]) -> AccountInstance: + """ + Build an instance of AccountInstance + + :param payload: Payload response from the API + """ + return AccountInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" + + + + +class AccountPage(Page): + + def get_instance(self, payload: Dict[str, Any]) -> AccountInstance: + """ + Build an instance of AccountInstance + + :param payload: Payload response from the API + """ + return AccountInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" + + + + + +class AccountList(ListResource): + + def __init__(self, version: Version, organization_sid: str): + """ + Initialize the AccountList + + :param version: Version that contains the resource + :param organization_sid: + + """ + super().__init__(version) + + + # Path Solution + self._solution = { 'organization_sid': organization_sid, } + self._uri = '/{organization_sid}/Accounts'.format(**self._solution) + + + + + def stream(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> Iterator[AccountInstance]: + """ + Streams AccountInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = self.page( + page_size=limits['page_size'] + ) + + return self._version.stream(page, limits['limit']) + + async def stream_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> AsyncIterator[AccountInstance]: + """ + Asynchronously streams AccountInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = await self.page_async( + page_size=limits['page_size'] + ) + + return self._version.stream_async(page, limits['limit']) + + def list(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[AccountInstance]: + """ + Lists AccountInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return list(self.stream( + limit=limit, + page_size=page_size, + )) + + async def list_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[AccountInstance]: + """ + Asynchronously lists AccountInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return [record async for record in await self.stream_async( + limit=limit, + page_size=page_size, + )] + + def page(self, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> AccountPage: + """ + Retrieve a single page of AccountInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of AccountInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = self._version.page(method='GET', uri=self._uri, params=data) + return AccountPage(self._version, response, self._solution) + + async def page_async(self, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> AccountPage: + """ + Asynchronously retrieve a single page of AccountInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of AccountInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = await self._version.page_async(method='GET', uri=self._uri, params=data) + return AccountPage(self._version, response, self._solution) + + def get_page(self, target_url: str) -> AccountPage: + """ + Retrieve a specific page of AccountInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of AccountInstance + """ + response = self._version.domain.twilio.request( + 'GET', + target_url + ) + return AccountPage(self._version, response, self._solution) + + async def get_page_async(self, target_url: str) -> AccountPage: + """ + Asynchronously retrieve a specific page of AccountInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of AccountInstance + """ + response = await self._version.domain.twilio.request_async( + 'GET', + target_url + ) + return AccountPage(self._version, response, self._solution) + + + def stream(self, + + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> Iterator[AccountInstance]: + """ + Streams AccountInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = self.page( + page_size=limits['page_size'] + ) + + return self._version.stream(page, limits['limit']) + + async def stream_async(self, + + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> AsyncIterator[AccountInstance]: + """ + Asynchronously streams AccountInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = await self.page_async( + page_size=limits['page_size'] + ) + + return self._version.stream_async(page, limits['limit']) + + def list(self, + + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[AccountInstance]: + """ + Lists AccountInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return list(self.stream( + limit=limit, + page_size=page_size, + )) + + async def list_async(self, + + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[AccountInstance]: + """ + Asynchronously lists AccountInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return [record async for record in await self.stream_async( + limit=limit, + page_size=page_size, + )] + + def page(self, + + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> AccountPage: + """ + Retrieve a single page of AccountInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of AccountInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = self._version.page(method='GET', uri=self._uri, params=data) + return AccountPage(self._version, response, self._solution) + + async def page_async(self, + + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> AccountPage: + """ + Asynchronously retrieve a single page of AccountInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of AccountInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = await self._version.page_async(method='GET', uri=self._uri, params=data) + return AccountPage(self._version, response, self._solution) + + def get_page(self, target_url: str) -> AccountPage: + """ + Retrieve a specific page of AccountInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of AccountInstance + """ + response = self._version.domain.twilio.request( + 'GET', + target_url + ) + return AccountPage(self._version, response, self._solution) + + async def get_page_async(self, target_url: str) -> AccountPage: + """ + Asynchronously retrieve a specific page of AccountInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of AccountInstance + """ + response = await self._version.domain.twilio.request_async( + 'GET', + target_url + ) + return AccountPage(self._version, response, self._solution) + + + def stream(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> Iterator[AccountInstance]: + """ + Streams AccountInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = self.page( + page_size=limits['page_size'] + ) + + return self._version.stream(page, limits['limit']) + + async def stream_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> AsyncIterator[AccountInstance]: + """ + Asynchronously streams AccountInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = await self.page_async( + page_size=limits['page_size'] + ) + + return self._version.stream_async(page, limits['limit']) + + def list(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[AccountInstance]: + """ + Lists AccountInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return list(self.stream( + limit=limit, + page_size=page_size, + )) + + async def list_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[AccountInstance]: + """ + Asynchronously lists AccountInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return [record async for record in await self.stream_async( + limit=limit, + page_size=page_size, + )] + + def page(self, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> AccountPage: + """ + Retrieve a single page of AccountInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of AccountInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = self._version.page(method='GET', uri=self._uri, params=data) + return AccountPage(self._version, response, self._solution) + + async def page_async(self, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> AccountPage: + """ + Asynchronously retrieve a single page of AccountInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of AccountInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = await self._version.page_async(method='GET', uri=self._uri, params=data) + return AccountPage(self._version, response, self._solution) + + def get_page(self, target_url: str) -> AccountPage: + """ + Retrieve a specific page of AccountInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of AccountInstance + """ + response = self._version.domain.twilio.request( + 'GET', + target_url + ) + return AccountPage(self._version, response, self._solution) + + async def get_page_async(self, target_url: str) -> AccountPage: + """ + Asynchronously retrieve a specific page of AccountInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of AccountInstance + """ + response = await self._version.domain.twilio.request_async( + 'GET', + target_url + ) + return AccountPage(self._version, response, self._solution) + + + + def get(self, organization_sid: str, account_sid: str) -> AccountContext: + """ + Constructs a AccountContext + + :param organization_sid: + :param account_sid: + """ + return AccountContext(self._version, organization_sid=organization_sid, account_sid=account_sid) + + def __call__(self, organization_sid: str, account_sid: str) -> AccountContext: + """ + Constructs a AccountContext + + :param organization_sid: + :param account_sid: + """ + return AccountContext(self._version, organization_sid=organization_sid, account_sid=account_sid) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return '' + diff --git a/twilio/rest/preview_iam/organizations_openapi/authorize.py b/twilio/rest/preview_iam/organizations_openapi/authorize.py new file mode 100644 index 0000000000..8a0a0975ab --- /dev/null +++ b/twilio/rest/preview_iam/organizations_openapi/authorize.py @@ -0,0 +1,121 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + + +from datetime import date, datetime +from decimal import Decimal +from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator +from twilio.base import deserialize, serialize, values + +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version + + + +class AuthorizeInstance(InstanceResource): + + """ + :ivar redirect_to: The callback URL + """ + + def __init__(self, version: Version, payload: Dict[str, Any]): + super().__init__(version) + + + self.redirect_to: Optional[str] = payload.get("redirect_to") + + + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + + return '' + + + + +class AuthorizeList(ListResource): + + def __init__(self, version: Version): + """ + Initialize the AuthorizeList + + :param version: Version that contains the resource + + """ + super().__init__(version) + + + self._uri = '/authorize' + + + + def fetch(self, response_type: Union[str, object]=values.unset, client_id: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, scope: Union[str, object]=values.unset, state: Union[str, object]=values.unset) -> AuthorizeInstance: + """ + Asynchronously fetch the AuthorizeInstance + + :param response_type: Response Type:param client_id: The Client Identifier:param redirect_uri: The url to which response will be redirected to:param scope: The scope of the access request:param state: An opaque value which can be used to maintain state between the request and callback + :returns: The fetched AuthorizeInstance + """ + + params = values.of({ + 'response_type': response_type, + 'client_id': client_id, + 'redirect_uri': redirect_uri, + 'scope': scope, + 'state': state, + + }) + + payload = self._version.fetch(method='GET', uri=self._uri, params=params) + + return AuthorizeInstance(self._version, payload) + + async def fetch_async(self, response_type: Union[str, object]=values.unset, client_id: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, scope: Union[str, object]=values.unset, state: Union[str, object]=values.unset) -> AuthorizeInstance: + """ + Asynchronously fetch the AuthorizeInstance + + :param response_type: Response Type:param client_id: The Client Identifier:param redirect_uri: The url to which response will be redirected to:param scope: The scope of the access request:param state: An opaque value which can be used to maintain state between the request and callback + :returns: The fetched AuthorizeInstance + """ + + params = values.of({ + 'response_type': response_type, + 'client_id': client_id, + 'redirect_uri': redirect_uri, + 'scope': scope, + 'state': state, + + }) + + payload = await self._version.fetch_async(method='GET', uri=self._uri, params=params) + + return AuthorizeInstance(self._version, payload) + + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return '' + diff --git a/twilio/rest/preview_iam/organizations_openapi/organizations_openapi/__init__.py b/twilio/rest/preview_iam/organizations_openapi/organizations_openapi/__init__.py new file mode 100644 index 0000000000..4051361aed --- /dev/null +++ b/twilio/rest/preview_iam/organizations_openapi/organizations_openapi/__init__.py @@ -0,0 +1,51 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + +from typing import Optional +from twilio.base.version import Version +from twilio.base.domain import Domain +from twilio.rest.preview_iam.organizations_openapi.authorize import AuthorizeList +from twilio.rest.preview_iam.organizations_openapi.token import TokenList + + +class Organizations_openapi(Version): + + def __init__(self, domain: Domain): + """ + Initialize the Organizations_openapi version of PreviewIam + + :param domain: The Twilio.preview_iam domain + """ + super().__init__(domain, "v1") + self._authorize: Optional[AuthorizeList] = None + self._token: Optional[TokenList] = None + + @property + def authorize(self) -> AuthorizeList: + if self._authorize is None: + self._authorize = AuthorizeList(self) + return self._authorize + + @property + def token(self) -> TokenList: + if self._token is None: + self._token = TokenList(self) + return self._token + + def __repr__(self) -> str: + """ + Provide a friendly representation + :returns: Machine friendly representation + """ + return "" diff --git a/twilio/rest/preview_iam/organizations_openapi/resource_type.py b/twilio/rest/preview_iam/organizations_openapi/resource_type.py new file mode 100644 index 0000000000..70305c99f1 --- /dev/null +++ b/twilio/rest/preview_iam/organizations_openapi/resource_type.py @@ -0,0 +1,290 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + + +from datetime import date, datetime +from decimal import Decimal +from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator +from twilio.base import deserialize, serialize, values + +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version +from twilio.base.page import Page + + +class ResourceTypeInstance(InstanceResource): + + """ + :ivar name: Name of the resource type + :ivar description: Description of the resource type + :ivar endpoint: HTTP-addressable endpoint relative to the Base URL of the service provider + :ivar schema: Primary/base schema URI + """ + + def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: Optional[str] = None): + super().__init__(version) + + + self.name: Optional[str] = payload.get("name") + self.description: Optional[str] = payload.get("description") + self.endpoint: Optional[str] = payload.get("endpoint") + self.schema: Optional[str] = payload.get("schema") + + + self._solution = { + "organization_sid": organization_sid or self.organization_sid, + } + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) + return ''.format(context) + + + + +class ResourceTypePage(Page): + + def get_instance(self, payload: Dict[str, Any]) -> ResourceTypeInstance: + """ + Build an instance of ResourceTypeInstance + + :param payload: Payload response from the API + """ + return ResourceTypeInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" + + + + + +class ResourceTypeList(ListResource): + + def __init__(self, version: Version, organization_sid: str): + """ + Initialize the ResourceTypeList + + :param version: Version that contains the resource + :param organization_sid: + + """ + super().__init__(version) + + + # Path Solution + self._solution = { 'organization_sid': organization_sid, } + self._uri = '/{organization_sid}/scim/ResourceTypes'.format(**self._solution) + + + + def stream(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> Iterator[ResourceTypeInstance]: + """ + Streams ResourceTypeInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = self.page( + page_size=limits['page_size'] + ) + + return self._version.stream(page, limits['limit']) + + async def stream_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> AsyncIterator[ResourceTypeInstance]: + """ + Asynchronously streams ResourceTypeInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = await self.page_async( + page_size=limits['page_size'] + ) + + return self._version.stream_async(page, limits['limit']) + + def list(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[ResourceTypeInstance]: + """ + Lists ResourceTypeInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return list(self.stream( + limit=limit, + page_size=page_size, + )) + + async def list_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[ResourceTypeInstance]: + """ + Asynchronously lists ResourceTypeInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return [record async for record in await self.stream_async( + limit=limit, + page_size=page_size, + )] + + def page(self, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> ResourceTypePage: + """ + Retrieve a single page of ResourceTypeInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of ResourceTypeInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = self._version.page(method='GET', uri=self._uri, params=data) + return ResourceTypePage(self._version, response, self._solution) + + async def page_async(self, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> ResourceTypePage: + """ + Asynchronously retrieve a single page of ResourceTypeInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of ResourceTypeInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = await self._version.page_async(method='GET', uri=self._uri, params=data) + return ResourceTypePage(self._version, response, self._solution) + + def get_page(self, target_url: str) -> ResourceTypePage: + """ + Retrieve a specific page of ResourceTypeInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of ResourceTypeInstance + """ + response = self._version.domain.twilio.request( + 'GET', + target_url + ) + return ResourceTypePage(self._version, response, self._solution) + + async def get_page_async(self, target_url: str) -> ResourceTypePage: + """ + Asynchronously retrieve a specific page of ResourceTypeInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of ResourceTypeInstance + """ + response = await self._version.domain.twilio.request_async( + 'GET', + target_url + ) + return ResourceTypePage(self._version, response, self._solution) + + + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return '' + diff --git a/twilio/rest/preview_iam/organizations_openapi/role_assignment.py b/twilio/rest/preview_iam/organizations_openapi/role_assignment.py new file mode 100644 index 0000000000..664e10bc36 --- /dev/null +++ b/twilio/rest/preview_iam/organizations_openapi/role_assignment.py @@ -0,0 +1,698 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + + +from datetime import date, datetime +from decimal import Decimal +from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator +from twilio.base import deserialize, serialize, values +from twilio.base.instance_context import InstanceContext +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version +from twilio.base.page import Page + + +class RoleAssignmentInstance(InstanceResource): + + """ + :ivar sid: Twilio Role Assignment Sid representing this role assignment + :ivar role_sid: Twilio Role Sid representing assigned role + :ivar scope: Twilio Sid representing identity of this assignment + :ivar identity: Twilio Sid representing scope of this assignment + :ivar code: Twilio-specific error code + :ivar message: Error message + :ivar more_info: Link to Error Code References + :ivar status: HTTP response status code + """ + + def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: Optional[str] = None, role_assignment_sid: Optional[str] = None): + super().__init__(version) + + + self.sid: Optional[str] = payload.get("sid") + self.role_sid: Optional[str] = payload.get("role_sid") + self.scope: Optional[str] = payload.get("scope") + self.identity: Optional[str] = payload.get("identity") + self.code: Optional[int] = payload.get("code") + self.message: Optional[str] = payload.get("message") + self.more_info: Optional[str] = payload.get("moreInfo") + self.status: Optional[int] = payload.get("status") + + + self._solution = { + "organization_sid": organization_sid or self.organization_sid, + "role_assignment_sid": role_assignment_sid or self.role_assignment_sid, + } + self._context: Optional[RoleAssignmentContext] = None + + @property + def _proxy(self) -> "RoleAssignmentContext": + """ + Generate an instance context for the instance, the context is capable of + performing various actions. All instance actions are proxied to the context + + :returns: RoleAssignmentContext for this RoleAssignmentInstance + """ + if self._context is None: + self._context = RoleAssignmentContext(self._version, organization_sid=self._solution['organization_sid'], role_assignment_sid=self._solution['role_assignment_sid'],) + return self._context + + + def delete(self) -> bool: + """ + Deletes the RoleAssignmentInstance + + + :returns: True if delete succeeds, False otherwise + """ + return self._proxy.delete() + async def delete_async(self) -> bool: + """ + Asynchronous coroutine that deletes the RoleAssignmentInstance + + + :returns: True if delete succeeds, False otherwise + """ + return await self._proxy.delete_async() + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) + return ''.format(context) + +class RoleAssignmentContext(InstanceContext): + + def __init__(self, version: Version, organization_sid: str, role_assignment_sid: str): + """ + Initialize the RoleAssignmentContext + + :param version: Version that contains the resource + :param organization_sid: + :param role_assignment_sid: + """ + super().__init__(version) + + + # Path Solution + self._solution = { + 'organization_sid': organization_sid, + 'role_assignment_sid': role_assignment_sid, + } + self._uri = '/{organization_sid}/RoleAssignments/{role_assignment_sid}'.format(**self._solution) + + + + def delete(self) -> bool: + """ + Deletes the RoleAssignmentInstance + + + :returns: True if delete succeeds, False otherwise + """ + return self._version.delete(method='DELETE', uri=self._uri,) + + async def delete_async(self) -> bool: + """ + Asynchronous coroutine that deletes the RoleAssignmentInstance + + + :returns: True if delete succeeds, False otherwise + """ + return await self._version.delete_async(method='DELETE', uri=self._uri,) + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) + return ''.format(context) + + + + + + + +class RoleAssignmentPage(Page): + + def get_instance(self, payload: Dict[str, Any]) -> RoleAssignmentInstance: + """ + Build an instance of RoleAssignmentInstance + + :param payload: Payload response from the API + """ + return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" + + + + +class RoleAssignmentPage(Page): + + def get_instance(self, payload: Dict[str, Any]) -> RoleAssignmentInstance: + """ + Build an instance of RoleAssignmentInstance + + :param payload: Payload response from the API + """ + return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" + + + + + +class RoleAssignmentList(ListResource): + + class PublicApiCreateRoleAssignmentRequest(object): + """ + :ivar role_sid: Twilio Role Sid representing assigned role + :ivar scope: Twilio Sid representing scope of this assignment + :ivar identity: Twilio Sid representing identity of this assignment + """ + + def __init__(self, payload: Dict[str, Any], organization_sid: Optional[str] = None, role_assignment_sid: Optional[str] = None): + + + self.role_sid: Optional[str] = payload.get("role_sid") + self.scope: Optional[str] = payload.get("scope") + self.identity: Optional[str] = payload.get("identity") + + def to_dict(self): + return { + + "role_sid": self.role_sid, + "scope": self.scope, + "identity": self.identity, + } + + + def __init__(self, version: Version, organization_sid: str): + """ + Initialize the RoleAssignmentList + + :param version: Version that contains the resource + :param organization_sid: + + """ + super().__init__(version) + + + # Path Solution + self._solution = { 'organization_sid': organization_sid, } + self._uri = '/{organization_sid}/RoleAssignments'.format(**self._solution) + + + + + def create(self, public_api_create_role_assignment_request: PublicApiCreateRoleAssignmentRequest) -> RoleAssignmentInstance: + """ + Create the RoleAssignmentInstance + + :param public_api_create_role_assignment_request: + + :returns: The created RoleAssignmentInstance + """ + data = public_api_create_role_assignment_request.to_dict() + + + headers = {'Content-Type': 'application/json'} + + payload = self._version.create(method='POST', uri=self._uri, data=data, headers=headers) + + return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution['organization_sid']) + + async def create_async(self, public_api_create_role_assignment_request: PublicApiCreateRoleAssignmentRequest) -> RoleAssignmentInstance: + """ + Asynchronously create the RoleAssignmentInstance + + :param public_api_create_role_assignment_request: + + :returns: The created RoleAssignmentInstance + """ + data = public_api_create_role_assignment_request.to_dict() + + + headers = {'Content-Type': 'application/json'} + + payload = await self._version.create_async(method='POST', uri=self._uri, data=data, headers=headers) + + return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution['organization_sid']) + + + def stream(self, + + identity: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> Iterator[RoleAssignmentInstance]: + """ + Streams RoleAssignmentInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param str identity: + :param str scope: + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = self.page( + identity=identity, + scope=scope, + page_size=limits['page_size'] + ) + + return self._version.stream(page, limits['limit']) + + async def stream_async(self, + + identity: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> AsyncIterator[RoleAssignmentInstance]: + """ + Asynchronously streams RoleAssignmentInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param str identity: + :param str scope: + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = await self.page_async( + identity=identity, + scope=scope, + page_size=limits['page_size'] + ) + + return self._version.stream_async(page, limits['limit']) + + def list(self, + + identity: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[RoleAssignmentInstance]: + """ + Lists RoleAssignmentInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param str identity: + :param str scope: + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return list(self.stream( + identity=identity, + scope=scope, + limit=limit, + page_size=page_size, + )) + + async def list_async(self, + + identity: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[RoleAssignmentInstance]: + """ + Asynchronously lists RoleAssignmentInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param str identity: + :param str scope: + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return [record async for record in await self.stream_async( + identity=identity, + scope=scope, + limit=limit, + page_size=page_size, + )] + + def page(self, + + identity: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> RoleAssignmentPage: + """ + Retrieve a single page of RoleAssignmentInstance records from the API. + Request is executed immediately + + :param identity: + :param scope: + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of RoleAssignmentInstance + """ + data = values.of({ + 'Identity': identity, + 'Scope': scope, + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = self._version.page(method='GET', uri=self._uri, params=data) + return RoleAssignmentPage(self._version, response, self._solution) + + async def page_async(self, + + identity: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> RoleAssignmentPage: + """ + Asynchronously retrieve a single page of RoleAssignmentInstance records from the API. + Request is executed immediately + + :param identity: + :param scope: + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of RoleAssignmentInstance + """ + data = values.of({ + 'Identity': identity, + 'Scope': scope, + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = await self._version.page_async(method='GET', uri=self._uri, params=data) + return RoleAssignmentPage(self._version, response, self._solution) + + def get_page(self, target_url: str) -> RoleAssignmentPage: + """ + Retrieve a specific page of RoleAssignmentInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of RoleAssignmentInstance + """ + response = self._version.domain.twilio.request( + 'GET', + target_url + ) + return RoleAssignmentPage(self._version, response, self._solution) + + async def get_page_async(self, target_url: str) -> RoleAssignmentPage: + """ + Asynchronously retrieve a specific page of RoleAssignmentInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of RoleAssignmentInstance + """ + response = await self._version.domain.twilio.request_async( + 'GET', + target_url + ) + return RoleAssignmentPage(self._version, response, self._solution) + + + def stream(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> Iterator[RoleAssignmentInstance]: + """ + Streams RoleAssignmentInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = self.page( + page_size=limits['page_size'] + ) + + return self._version.stream(page, limits['limit']) + + async def stream_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> AsyncIterator[RoleAssignmentInstance]: + """ + Asynchronously streams RoleAssignmentInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = await self.page_async( + page_size=limits['page_size'] + ) + + return self._version.stream_async(page, limits['limit']) + + def list(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[RoleAssignmentInstance]: + """ + Lists RoleAssignmentInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return list(self.stream( + limit=limit, + page_size=page_size, + )) + + async def list_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[RoleAssignmentInstance]: + """ + Asynchronously lists RoleAssignmentInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return [record async for record in await self.stream_async( + limit=limit, + page_size=page_size, + )] + + def page(self, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> RoleAssignmentPage: + """ + Retrieve a single page of RoleAssignmentInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of RoleAssignmentInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = self._version.page(method='GET', uri=self._uri, params=data) + return RoleAssignmentPage(self._version, response, self._solution) + + async def page_async(self, + page_token: Union[str, object] = values.unset, + page_number: Union[int, object] = values.unset, + page_size: Union[int, object] = values.unset, + ) -> RoleAssignmentPage: + """ + Asynchronously retrieve a single page of RoleAssignmentInstance records from the API. + Request is executed immediately + + :param page_token: PageToken provided by the API + :param page_number: Page Number, this value is simply for client state + :param page_size: Number of records to return, defaults to 50 + + :returns: Page of RoleAssignmentInstance + """ + data = values.of({ + 'PageToken': page_token, + 'Page': page_number, + 'PageSize': page_size, + }) + + response = await self._version.page_async(method='GET', uri=self._uri, params=data) + return RoleAssignmentPage(self._version, response, self._solution) + + def get_page(self, target_url: str) -> RoleAssignmentPage: + """ + Retrieve a specific page of RoleAssignmentInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of RoleAssignmentInstance + """ + response = self._version.domain.twilio.request( + 'GET', + target_url + ) + return RoleAssignmentPage(self._version, response, self._solution) + + async def get_page_async(self, target_url: str) -> RoleAssignmentPage: + """ + Asynchronously retrieve a specific page of RoleAssignmentInstance records from the API. + Request is executed immediately + + :param target_url: API-generated URL for the requested results page + + :returns: Page of RoleAssignmentInstance + """ + response = await self._version.domain.twilio.request_async( + 'GET', + target_url + ) + return RoleAssignmentPage(self._version, response, self._solution) + + + + def get(self, organization_sid: str, role_assignment_sid: str) -> RoleAssignmentContext: + """ + Constructs a RoleAssignmentContext + + :param organization_sid: + :param role_assignment_sid: + """ + return RoleAssignmentContext(self._version, organization_sid=organization_sid, role_assignment_sid=role_assignment_sid) + + def __call__(self, organization_sid: str, role_assignment_sid: str) -> RoleAssignmentContext: + """ + Constructs a RoleAssignmentContext + + :param organization_sid: + :param role_assignment_sid: + """ + return RoleAssignmentContext(self._version, organization_sid=organization_sid, role_assignment_sid=role_assignment_sid) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return '' + diff --git a/twilio/rest/preview_iam/organizations_openapi/token.py b/twilio/rest/preview_iam/organizations_openapi/token.py new file mode 100644 index 0000000000..a05fd9858b --- /dev/null +++ b/twilio/rest/preview_iam/organizations_openapi/token.py @@ -0,0 +1,331 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + + +from datetime import date, datetime +from decimal import Decimal +from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator +from twilio.base import deserialize, serialize, values + +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version + + + +class TokenInstance(InstanceResource): + + """ + :ivar access_token: Token which carries the necessary information to access a Twilio resource directly. + :ivar refresh_token: Token which carries the information necessary to get a new access token. + :ivar id_token: Token which carries the information necessary of user profile. + :ivar token_type: Token type + :ivar expires_in: + """ + + def __init__(self, version: Version, payload: Dict[str, Any]): + super().__init__(version) + + + self.access_token: Optional[str] = payload.get("access_token") + self.refresh_token: Optional[str] = payload.get("refresh_token") + self.id_token: Optional[str] = payload.get("id_token") + self.token_type: Optional[str] = payload.get("token_type") + self.expires_in: Optional[int] = payload.get("expires_in") + + + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + + return '' + + + + +class TokenList(ListResource): + + def __init__(self, version: Version): + """ + Initialize the TokenList + + :param version: Version that contains the resource + + """ + super().__init__(version) + + + self._uri = '/token' + + + + def create(self, grant_type: str, client_id: str, client_secret: Union[str, object]=values.unset, code: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, audience: Union[str, object]=values.unset, refresh_token: Union[str, object]=values.unset, scope: Union[str, object]=values.unset) -> TokenInstance: + """ + Create the TokenInstance + + :param grant_type: Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + :param client_id: A 34 character string that uniquely identifies this OAuth App. + :param client_secret: The credential for confidential OAuth App. + :param code: JWT token related to the authorization code grant type. + :param redirect_uri: The redirect uri + :param audience: The targeted audience uri + :param refresh_token: JWT token related to refresh access token. + :param scope: The scope of token + + :returns: The created TokenInstance + """ + + data = values.of({ + 'grant_type': grant_type, + 'client_id': client_id, + 'client_secret': client_secret, + 'code': code, + 'redirect_uri': redirect_uri, + 'audience': audience, + 'refresh_token': refresh_token, + 'scope': scope, + }) + + + + payload = self._version.create(method='POST', uri=self._uri, data=data,) + + return TokenInstance(self._version, payload) + + async def create_async(self, grant_type: str, client_id: str, client_secret: Union[str, object]=values.unset, code: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, audience: Union[str, object]=values.unset, refresh_token: Union[str, object]=values.unset, scope: Union[str, object]=values.unset) -> TokenInstance: + """ + Asynchronously create the TokenInstance + + :param grant_type: Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + :param client_id: A 34 character string that uniquely identifies this OAuth App. + :param client_secret: The credential for confidential OAuth App. + :param code: JWT token related to the authorization code grant type. + :param redirect_uri: The redirect uri + :param audience: The targeted audience uri + :param refresh_token: JWT token related to refresh access token. + :param scope: The scope of token + + :returns: The created TokenInstance + """ + + data = values.of({ + 'grant_type': grant_type, + 'client_id': client_id, + 'client_secret': client_secret, + 'code': code, + 'redirect_uri': redirect_uri, + 'audience': audience, + 'refresh_token': refresh_token, + 'scope': scope, + }) + + + + payload = await self._version.create_async(method='POST', uri=self._uri, data=data,) + + return TokenInstance(self._version, payload) + + + def stream(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> Iterator[TokenInstance]: + """ + Streams TokenInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = self.page( + page_size=limits['page_size'] + ) + + return self._version.stream(page, limits['limit']) + + async def stream_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> AsyncIterator[TokenInstance]: + """ + Asynchronously streams TokenInstance records from the API as a generator stream. + This operation lazily loads records as efficiently as possible until the limit + is reached. + The results are returned as a generator, so this operation is memory efficient. + + :param limit: Upper limit for the number of records to return. stream() + guarantees to never return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, stream() will attempt to read the + limit with the most efficient page size, i.e. min(limit, 1000) + + :returns: Generator that will yield up to limit results + """ + limits = self._version.read_limits(limit, page_size) + page = await self.page_async( + page_size=limits['page_size'] + ) + + return self._version.stream_async(page, limits['limit']) + + def list(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[TokenInstance]: + """ + Lists TokenInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return list(self.stream( + limit=limit, + page_size=page_size, + )) + + async def list_async(self, + limit: Optional[int] = None, + page_size: Optional[int] = None, + ) -> List[TokenInstance]: + """ + Asynchronously lists TokenInstance records from the API as a list. + Unlike stream(), this operation is eager and will load `limit` records into + memory before returning. + + :param limit: Upper limit for the number of records to return. list() guarantees + never to return more than limit. Default is no limit + :param page_size: Number of records to fetch per request, when not set will use + the default value of 50 records. If no page_size is defined + but a limit is defined, list() will attempt to read the limit + with the most efficient page size, i.e. min(limit, 1000) + + :returns: list that will contain up to limit results + """ + return [record async for record in await self.stream_async( + limit=limit, + page_size=page_size, + )] + + # def page(self, + # page_token: Union[str, object] = values.unset, + # page_number: Union[int, object] = values.unset, + # page_size: Union[int, object] = values.unset, + # ) -> TokenPage: + # """ + # Retrieve a single page of TokenInstance records from the API. + # Request is executed immediately + # + # :param page_token: PageToken provided by the API + # :param page_number: Page Number, this value is simply for client state + # :param page_size: Number of records to return, defaults to 50 + # + # :returns: Page of TokenInstance + # """ + # data = values.of({ + # 'PageToken': page_token, + # 'Page': page_number, + # 'PageSize': page_size, + # }) + # + # response = self._version.page(method='GET', uri=self._uri, params=data) + # return TokenPage(self._version, response) + + # async def page_async(self, + # page_token: Union[str, object] = values.unset, + # page_number: Union[int, object] = values.unset, + # page_size: Union[int, object] = values.unset, + # ) -> TokenPage: + # """ + # Asynchronously retrieve a single page of TokenInstance records from the API. + # Request is executed immediately + # + # :param page_token: PageToken provided by the API + # :param page_number: Page Number, this value is simply for client state + # :param page_size: Number of records to return, defaults to 50 + # + # :returns: Page of TokenInstance + # """ + # data = values.of({ + # 'PageToken': page_token, + # 'Page': page_number, + # 'PageSize': page_size, + # }) + # + # response = await self._version.page_async(method='GET', uri=self._uri, params=data) + # return TokenPage(self._version, response) + + # def get_page(self, target_url: str) -> TokenPage: + # """ + # Retrieve a specific page of TokenInstance records from the API. + # Request is executed immediately + # + # :param target_url: API-generated URL for the requested results page + # + # :returns: Page of TokenInstance + # """ + # response = self._version.domain.twilio.request( + # 'GET', + # target_url + # ) + # return TokenPage(self._version, response) + + # async def get_page_async(self, target_url: str) -> TokenPage: + # """ + # Asynchronously retrieve a specific page of TokenInstance records from the API. + # Request is executed immediately + # + # :param target_url: API-generated URL for the requested results page + # + # :returns: Page of TokenInstance + # """ + # response = await self._version.domain.twilio.request_async( + # 'GET', + # target_url + # ) + # return TokenPage(self._version, response) + + + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return '' + diff --git a/twilio/twilio_bearer_token_auth.py b/twilio/twilio_bearer_token_auth.py new file mode 100644 index 0000000000..f396e86f5b --- /dev/null +++ b/twilio/twilio_bearer_token_auth.py @@ -0,0 +1,56 @@ +from threading import Lock +from concurrent.futures import ThreadPoolExecutor + + +class BearerTokenTwilioRestClient: + pass + + +class TwilioBearerTokenAuth: + _lock = Lock() + access_token = None + rest_client = None + executor_service = None + user_agent_extensions = None + region = None + edge = None + + @classmethod + def init(cls, access_token): + with cls._lock: + if not access_token: + raise ValueError("Access Token cannot be null or Empty") + if access_token != cls.access_token: + cls.invalidate() + cls.access_token = access_token + + @classmethod + def get_access_token(cls): + with cls._lock: + return cls.access_token + + @classmethod + def get_rest_client(cls): + with cls._lock: + if cls.rest_client is None: + cls.rest_client = cls.build_oauth_rest_client() + return cls.rest_client + + @classmethod + def get_executor_service(cls): + with cls._lock: + if cls.executor_service is None: + cls.executor_service = ThreadPoolExecutor(max_workers=None) + return cls.executor_service + + @classmethod + def build_oauth_rest_client(cls): + builder = BearerTokenTwilioRestClient.Builder(cls.access_token) + + if cls.user_agent_extensions is not None: + builder.user_agent_extensions(cls.user_agent_extensions) + + builder.region(cls.region) + builder.edge(cls.edge) + + return builder.build() \ No newline at end of file diff --git a/twilio/twilio_no_auth.py b/twilio/twilio_no_auth.py new file mode 100644 index 0000000000..92ab2c5094 --- /dev/null +++ b/twilio/twilio_no_auth.py @@ -0,0 +1,33 @@ +import os +from threading import Lock + + +class NoAuthTwilioRestClient: + pass + + +class TwilioNoAuth: + _lock = Lock() + no_auth_twilio_rest_client = None + user_agent_extensions = None + region = os.getenv("TWILIO_REGION") + edge = os.getenv("TWILIO_EDGE") + + @classmethod + def get_rest_client(cls): + with cls._lock: + if cls.no_auth_twilio_rest_client is None: + cls.no_auth_twilio_rest_client = cls.build_oauth_rest_client() + return cls.no_auth_twilio_rest_client + + @classmethod + def build_oauth_rest_client(cls): + builder = NoAuthTwilioRestClient.Builder() + + if cls.user_agent_extensions is not None: + builder.user_agent_extensions(cls.user_agent_extensions) + + builder.region(cls.region) + builder.edge(cls.edge) + + return builder.build() \ No newline at end of file From 451ff0a6137fc00ecbdb2b3a50c9f3a1a787d630 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Fri, 21 Jun 2024 18:54:28 +0530 Subject: [PATCH 02/14] chore: oauth sdk implementation --- twilio/rest/preview_iam/PreviewIamBase.py | 29 - twilio/rest/preview_iam/__init__.py | 0 .../organizations_openapi/account.py | 826 ------------------ .../organizations_openapi/authorize.py | 121 --- .../organizations_openapi/__init__.py | 51 -- .../organizations_openapi/resource_type.py | 290 ------ .../organizations_openapi/role_assignment.py | 698 --------------- .../organizations_openapi/token.py | 331 ------- 8 files changed, 2346 deletions(-) delete mode 100644 twilio/rest/preview_iam/PreviewIamBase.py delete mode 100644 twilio/rest/preview_iam/__init__.py delete mode 100644 twilio/rest/preview_iam/organizations_openapi/account.py delete mode 100644 twilio/rest/preview_iam/organizations_openapi/authorize.py delete mode 100644 twilio/rest/preview_iam/organizations_openapi/organizations_openapi/__init__.py delete mode 100644 twilio/rest/preview_iam/organizations_openapi/resource_type.py delete mode 100644 twilio/rest/preview_iam/organizations_openapi/role_assignment.py delete mode 100644 twilio/rest/preview_iam/organizations_openapi/token.py diff --git a/twilio/rest/preview_iam/PreviewIamBase.py b/twilio/rest/preview_iam/PreviewIamBase.py deleted file mode 100644 index 9cf1f3bac3..0000000000 --- a/twilio/rest/preview_iam/PreviewIamBase.py +++ /dev/null @@ -1,29 +0,0 @@ -r""" - This code was generated by - ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - - NOTE: This class is auto generated by OpenAPI Generator. - https://openapi-generator.tech - Do not edit the class manually. -""" -from twilio.base.domain import Domain -from twilio.rest import Client -from twilio.rest.preview_iam.organizations_openapi.token import Token -from twilio.rest.preview_iam.organizations_openapi.account import Account -from twilio.rest.preview_iam.organizations_openapi.authorize import AuthorizeList -from twilio.rest.preview_iam.organizations_openapi.resource_type import ResourceTypeList -from twilio.rest.preview_iam.organizations_openapi.role_assignment import RoleAssignmentList - -class PreviewIamBase(Domain): - def __init__(self, twilio: Client): - """ - Initialize the PreviewIam Domain - - :returns: Domain for PreviewIam - """ - super().__init__(twilio, "https://preview.twilio.com/iam") - self._token: Optional[TokenList] = None - self._service_accounts: Optional[ServiceAccounts] = None - self._service_roles: Optional[ServiceRoles] = None \ No newline at end of file diff --git a/twilio/rest/preview_iam/__init__.py b/twilio/rest/preview_iam/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/twilio/rest/preview_iam/organizations_openapi/account.py b/twilio/rest/preview_iam/organizations_openapi/account.py deleted file mode 100644 index 085dcc62f2..0000000000 --- a/twilio/rest/preview_iam/organizations_openapi/account.py +++ /dev/null @@ -1,826 +0,0 @@ -r""" - This code was generated by - ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - - Organization Public API - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - NOTE: This class is auto generated by OpenAPI Generator. - https://openapi-generator.tech - Do not edit the class manually. -""" -import os -from datetime import date, datetime -from decimal import Decimal -from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values -from twilio.base.instance_context import InstanceContext -from twilio.base.instance_resource import InstanceResource -from twilio.base.list_resource import ListResource -from twilio.base.version import Version -from twilio.base.page import Page -from twilio.rest.preview_iam.organizations_openapi.token import TokenList -from twilio.twilio_bearer_token_auth import TwilioBearerTokenAuth - - -class AccountInstance(InstanceResource): - - """ - :ivar account_sid: Twilio account sid - :ivar friendly_name: Account friendly name - :ivar status: Account status - :ivar owner_sid: Twilio account sid - :ivar date_created: The date and time when the account was created in the system - """ - - def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: Optional[str] = None, account_sid: Optional[str] = None): - super().__init__(version) - - - self.account_sid: Optional[str] = payload.get("account_sid") - self.friendly_name: Optional[str] = payload.get("friendly_name") - self.status: Optional[str] = payload.get("status") - self.owner_sid: Optional[str] = payload.get("owner_sid") - self.date_created: Optional[datetime] = deserialize.iso8601_datetime(payload.get("date_created")) - - - self._solution = { - "organization_sid": organization_sid or self.organization_sid, - "account_sid": account_sid or self.account_sid, - } - self._context: Optional[AccountContext] = None - - @property - def _proxy(self) -> "AccountContext": - """ - Generate an instance context for the instance, the context is capable of - performing various actions. All instance actions are proxied to the context - - :returns: AccountContext for this AccountInstance - """ - if self._context is None: - self._context = AccountContext(self._version, organization_sid=self._solution['organization_sid'], account_sid=self._solution['account_sid'],) - return self._context - - - def fetch(self) -> "AccountInstance": - """ - Fetch the AccountInstance - - - :returns: The fetched AccountInstance - """ - return self._proxy.fetch() - - async def fetch_async(self) -> "AccountInstance": - """ - Asynchronous coroutine to fetch the AccountInstance - - - :returns: The fetched AccountInstance - """ - return await self._proxy.fetch_async() - - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) - -class AccountContext(InstanceContext): - - def __init__(self, version: Version, organization_sid: str, account_sid: str): - """ - Initialize the AccountContext - - :param version: Version that contains the resource - :param organization_sid: - :param account_sid: - """ - super().__init__(version) - - - # Path Solution - self._solution = { - 'organization_sid': organization_sid, - 'account_sid': account_sid, - } - self._uri = '/{organization_sid}/Accounts/{account_sid}'.format(**self._solution) - - - def fetch(self) -> AccountInstance: - """ - Fetch the AccountInstance - - - :returns: The fetched AccountInstance - """ - headers = {} - if True: - if TwilioBearerTokenAuth.get_access_token() is None: - accessToken = TokenList('v1').create(grant_type='client_credentials', - client_id=os.environ('CLIENT_ID'), - client_secret=os.environ('CLIENT_SECRET'), - username='',password='') - TwilioBearerTokenAuth.init(accessToken) - else: - accessToken = TwilioBearerTokenAuth.get_access_token() - headers = {'Authorization': 'Bearer '+accessToken} - - payload = self._version.fetch(method='GET', uri=self._uri, headers=headers) - - return AccountInstance( - self._version, - payload, - organization_sid=self._solution['organization_sid'], - account_sid=self._solution['account_sid'], - - ) - - async def fetch_async(self) -> AccountInstance: - """ - Asynchronous coroutine to fetch the AccountInstance - - - :returns: The fetched AccountInstance - """ - - payload = await self._version.fetch_async(method='GET', uri=self._uri, ) - - return AccountInstance( - self._version, - payload, - organization_sid=self._solution['organization_sid'], - account_sid=self._solution['account_sid'], - - ) - - - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) - - - - - -class AccountPage(Page): - - def get_instance(self, payload: Dict[str, Any]) -> AccountInstance: - """ - Build an instance of AccountInstance - - :param payload: Payload response from the API - """ - return AccountInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return "" - - - - -class AccountPage(Page): - - def get_instance(self, payload: Dict[str, Any]) -> AccountInstance: - """ - Build an instance of AccountInstance - - :param payload: Payload response from the API - """ - return AccountInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return "" - - - - -class AccountPage(Page): - - def get_instance(self, payload: Dict[str, Any]) -> AccountInstance: - """ - Build an instance of AccountInstance - - :param payload: Payload response from the API - """ - return AccountInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return "" - - - - - -class AccountList(ListResource): - - def __init__(self, version: Version, organization_sid: str): - """ - Initialize the AccountList - - :param version: Version that contains the resource - :param organization_sid: - - """ - super().__init__(version) - - - # Path Solution - self._solution = { 'organization_sid': organization_sid, } - self._uri = '/{organization_sid}/Accounts'.format(**self._solution) - - - - - def stream(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> Iterator[AccountInstance]: - """ - Streams AccountInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = self.page( - page_size=limits['page_size'] - ) - - return self._version.stream(page, limits['limit']) - - async def stream_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> AsyncIterator[AccountInstance]: - """ - Asynchronously streams AccountInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = await self.page_async( - page_size=limits['page_size'] - ) - - return self._version.stream_async(page, limits['limit']) - - def list(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[AccountInstance]: - """ - Lists AccountInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return list(self.stream( - limit=limit, - page_size=page_size, - )) - - async def list_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[AccountInstance]: - """ - Asynchronously lists AccountInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return [record async for record in await self.stream_async( - limit=limit, - page_size=page_size, - )] - - def page(self, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> AccountPage: - """ - Retrieve a single page of AccountInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of AccountInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = self._version.page(method='GET', uri=self._uri, params=data) - return AccountPage(self._version, response, self._solution) - - async def page_async(self, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> AccountPage: - """ - Asynchronously retrieve a single page of AccountInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of AccountInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = await self._version.page_async(method='GET', uri=self._uri, params=data) - return AccountPage(self._version, response, self._solution) - - def get_page(self, target_url: str) -> AccountPage: - """ - Retrieve a specific page of AccountInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of AccountInstance - """ - response = self._version.domain.twilio.request( - 'GET', - target_url - ) - return AccountPage(self._version, response, self._solution) - - async def get_page_async(self, target_url: str) -> AccountPage: - """ - Asynchronously retrieve a specific page of AccountInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of AccountInstance - """ - response = await self._version.domain.twilio.request_async( - 'GET', - target_url - ) - return AccountPage(self._version, response, self._solution) - - - def stream(self, - - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> Iterator[AccountInstance]: - """ - Streams AccountInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = self.page( - page_size=limits['page_size'] - ) - - return self._version.stream(page, limits['limit']) - - async def stream_async(self, - - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> AsyncIterator[AccountInstance]: - """ - Asynchronously streams AccountInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = await self.page_async( - page_size=limits['page_size'] - ) - - return self._version.stream_async(page, limits['limit']) - - def list(self, - - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[AccountInstance]: - """ - Lists AccountInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return list(self.stream( - limit=limit, - page_size=page_size, - )) - - async def list_async(self, - - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[AccountInstance]: - """ - Asynchronously lists AccountInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return [record async for record in await self.stream_async( - limit=limit, - page_size=page_size, - )] - - def page(self, - - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> AccountPage: - """ - Retrieve a single page of AccountInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of AccountInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = self._version.page(method='GET', uri=self._uri, params=data) - return AccountPage(self._version, response, self._solution) - - async def page_async(self, - - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> AccountPage: - """ - Asynchronously retrieve a single page of AccountInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of AccountInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = await self._version.page_async(method='GET', uri=self._uri, params=data) - return AccountPage(self._version, response, self._solution) - - def get_page(self, target_url: str) -> AccountPage: - """ - Retrieve a specific page of AccountInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of AccountInstance - """ - response = self._version.domain.twilio.request( - 'GET', - target_url - ) - return AccountPage(self._version, response, self._solution) - - async def get_page_async(self, target_url: str) -> AccountPage: - """ - Asynchronously retrieve a specific page of AccountInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of AccountInstance - """ - response = await self._version.domain.twilio.request_async( - 'GET', - target_url - ) - return AccountPage(self._version, response, self._solution) - - - def stream(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> Iterator[AccountInstance]: - """ - Streams AccountInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = self.page( - page_size=limits['page_size'] - ) - - return self._version.stream(page, limits['limit']) - - async def stream_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> AsyncIterator[AccountInstance]: - """ - Asynchronously streams AccountInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = await self.page_async( - page_size=limits['page_size'] - ) - - return self._version.stream_async(page, limits['limit']) - - def list(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[AccountInstance]: - """ - Lists AccountInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return list(self.stream( - limit=limit, - page_size=page_size, - )) - - async def list_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[AccountInstance]: - """ - Asynchronously lists AccountInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return [record async for record in await self.stream_async( - limit=limit, - page_size=page_size, - )] - - def page(self, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> AccountPage: - """ - Retrieve a single page of AccountInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of AccountInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = self._version.page(method='GET', uri=self._uri, params=data) - return AccountPage(self._version, response, self._solution) - - async def page_async(self, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> AccountPage: - """ - Asynchronously retrieve a single page of AccountInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of AccountInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = await self._version.page_async(method='GET', uri=self._uri, params=data) - return AccountPage(self._version, response, self._solution) - - def get_page(self, target_url: str) -> AccountPage: - """ - Retrieve a specific page of AccountInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of AccountInstance - """ - response = self._version.domain.twilio.request( - 'GET', - target_url - ) - return AccountPage(self._version, response, self._solution) - - async def get_page_async(self, target_url: str) -> AccountPage: - """ - Asynchronously retrieve a specific page of AccountInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of AccountInstance - """ - response = await self._version.domain.twilio.request_async( - 'GET', - target_url - ) - return AccountPage(self._version, response, self._solution) - - - - def get(self, organization_sid: str, account_sid: str) -> AccountContext: - """ - Constructs a AccountContext - - :param organization_sid: - :param account_sid: - """ - return AccountContext(self._version, organization_sid=organization_sid, account_sid=account_sid) - - def __call__(self, organization_sid: str, account_sid: str) -> AccountContext: - """ - Constructs a AccountContext - - :param organization_sid: - :param account_sid: - """ - return AccountContext(self._version, organization_sid=organization_sid, account_sid=account_sid) - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return '' - diff --git a/twilio/rest/preview_iam/organizations_openapi/authorize.py b/twilio/rest/preview_iam/organizations_openapi/authorize.py deleted file mode 100644 index 8a0a0975ab..0000000000 --- a/twilio/rest/preview_iam/organizations_openapi/authorize.py +++ /dev/null @@ -1,121 +0,0 @@ -r""" - This code was generated by - ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - - Organization Public API - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - NOTE: This class is auto generated by OpenAPI Generator. - https://openapi-generator.tech - Do not edit the class manually. -""" - - -from datetime import date, datetime -from decimal import Decimal -from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values - -from twilio.base.instance_resource import InstanceResource -from twilio.base.list_resource import ListResource -from twilio.base.version import Version - - - -class AuthorizeInstance(InstanceResource): - - """ - :ivar redirect_to: The callback URL - """ - - def __init__(self, version: Version, payload: Dict[str, Any]): - super().__init__(version) - - - self.redirect_to: Optional[str] = payload.get("redirect_to") - - - - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - - return '' - - - - -class AuthorizeList(ListResource): - - def __init__(self, version: Version): - """ - Initialize the AuthorizeList - - :param version: Version that contains the resource - - """ - super().__init__(version) - - - self._uri = '/authorize' - - - - def fetch(self, response_type: Union[str, object]=values.unset, client_id: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, scope: Union[str, object]=values.unset, state: Union[str, object]=values.unset) -> AuthorizeInstance: - """ - Asynchronously fetch the AuthorizeInstance - - :param response_type: Response Type:param client_id: The Client Identifier:param redirect_uri: The url to which response will be redirected to:param scope: The scope of the access request:param state: An opaque value which can be used to maintain state between the request and callback - :returns: The fetched AuthorizeInstance - """ - - params = values.of({ - 'response_type': response_type, - 'client_id': client_id, - 'redirect_uri': redirect_uri, - 'scope': scope, - 'state': state, - - }) - - payload = self._version.fetch(method='GET', uri=self._uri, params=params) - - return AuthorizeInstance(self._version, payload) - - async def fetch_async(self, response_type: Union[str, object]=values.unset, client_id: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, scope: Union[str, object]=values.unset, state: Union[str, object]=values.unset) -> AuthorizeInstance: - """ - Asynchronously fetch the AuthorizeInstance - - :param response_type: Response Type:param client_id: The Client Identifier:param redirect_uri: The url to which response will be redirected to:param scope: The scope of the access request:param state: An opaque value which can be used to maintain state between the request and callback - :returns: The fetched AuthorizeInstance - """ - - params = values.of({ - 'response_type': response_type, - 'client_id': client_id, - 'redirect_uri': redirect_uri, - 'scope': scope, - 'state': state, - - }) - - payload = await self._version.fetch_async(method='GET', uri=self._uri, params=params) - - return AuthorizeInstance(self._version, payload) - - - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return '' - diff --git a/twilio/rest/preview_iam/organizations_openapi/organizations_openapi/__init__.py b/twilio/rest/preview_iam/organizations_openapi/organizations_openapi/__init__.py deleted file mode 100644 index 4051361aed..0000000000 --- a/twilio/rest/preview_iam/organizations_openapi/organizations_openapi/__init__.py +++ /dev/null @@ -1,51 +0,0 @@ -r""" - This code was generated by - ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - - Organization Public API - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - NOTE: This class is auto generated by OpenAPI Generator. - https://openapi-generator.tech - Do not edit the class manually. -""" - -from typing import Optional -from twilio.base.version import Version -from twilio.base.domain import Domain -from twilio.rest.preview_iam.organizations_openapi.authorize import AuthorizeList -from twilio.rest.preview_iam.organizations_openapi.token import TokenList - - -class Organizations_openapi(Version): - - def __init__(self, domain: Domain): - """ - Initialize the Organizations_openapi version of PreviewIam - - :param domain: The Twilio.preview_iam domain - """ - super().__init__(domain, "v1") - self._authorize: Optional[AuthorizeList] = None - self._token: Optional[TokenList] = None - - @property - def authorize(self) -> AuthorizeList: - if self._authorize is None: - self._authorize = AuthorizeList(self) - return self._authorize - - @property - def token(self) -> TokenList: - if self._token is None: - self._token = TokenList(self) - return self._token - - def __repr__(self) -> str: - """ - Provide a friendly representation - :returns: Machine friendly representation - """ - return "" diff --git a/twilio/rest/preview_iam/organizations_openapi/resource_type.py b/twilio/rest/preview_iam/organizations_openapi/resource_type.py deleted file mode 100644 index 70305c99f1..0000000000 --- a/twilio/rest/preview_iam/organizations_openapi/resource_type.py +++ /dev/null @@ -1,290 +0,0 @@ -r""" - This code was generated by - ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - - Organization Public API - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - NOTE: This class is auto generated by OpenAPI Generator. - https://openapi-generator.tech - Do not edit the class manually. -""" - - -from datetime import date, datetime -from decimal import Decimal -from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values - -from twilio.base.instance_resource import InstanceResource -from twilio.base.list_resource import ListResource -from twilio.base.version import Version -from twilio.base.page import Page - - -class ResourceTypeInstance(InstanceResource): - - """ - :ivar name: Name of the resource type - :ivar description: Description of the resource type - :ivar endpoint: HTTP-addressable endpoint relative to the Base URL of the service provider - :ivar schema: Primary/base schema URI - """ - - def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: Optional[str] = None): - super().__init__(version) - - - self.name: Optional[str] = payload.get("name") - self.description: Optional[str] = payload.get("description") - self.endpoint: Optional[str] = payload.get("endpoint") - self.schema: Optional[str] = payload.get("schema") - - - self._solution = { - "organization_sid": organization_sid or self.organization_sid, - } - - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) - - - - -class ResourceTypePage(Page): - - def get_instance(self, payload: Dict[str, Any]) -> ResourceTypeInstance: - """ - Build an instance of ResourceTypeInstance - - :param payload: Payload response from the API - """ - return ResourceTypeInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return "" - - - - - -class ResourceTypeList(ListResource): - - def __init__(self, version: Version, organization_sid: str): - """ - Initialize the ResourceTypeList - - :param version: Version that contains the resource - :param organization_sid: - - """ - super().__init__(version) - - - # Path Solution - self._solution = { 'organization_sid': organization_sid, } - self._uri = '/{organization_sid}/scim/ResourceTypes'.format(**self._solution) - - - - def stream(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> Iterator[ResourceTypeInstance]: - """ - Streams ResourceTypeInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = self.page( - page_size=limits['page_size'] - ) - - return self._version.stream(page, limits['limit']) - - async def stream_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> AsyncIterator[ResourceTypeInstance]: - """ - Asynchronously streams ResourceTypeInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = await self.page_async( - page_size=limits['page_size'] - ) - - return self._version.stream_async(page, limits['limit']) - - def list(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[ResourceTypeInstance]: - """ - Lists ResourceTypeInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return list(self.stream( - limit=limit, - page_size=page_size, - )) - - async def list_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[ResourceTypeInstance]: - """ - Asynchronously lists ResourceTypeInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return [record async for record in await self.stream_async( - limit=limit, - page_size=page_size, - )] - - def page(self, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> ResourceTypePage: - """ - Retrieve a single page of ResourceTypeInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of ResourceTypeInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = self._version.page(method='GET', uri=self._uri, params=data) - return ResourceTypePage(self._version, response, self._solution) - - async def page_async(self, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> ResourceTypePage: - """ - Asynchronously retrieve a single page of ResourceTypeInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of ResourceTypeInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = await self._version.page_async(method='GET', uri=self._uri, params=data) - return ResourceTypePage(self._version, response, self._solution) - - def get_page(self, target_url: str) -> ResourceTypePage: - """ - Retrieve a specific page of ResourceTypeInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of ResourceTypeInstance - """ - response = self._version.domain.twilio.request( - 'GET', - target_url - ) - return ResourceTypePage(self._version, response, self._solution) - - async def get_page_async(self, target_url: str) -> ResourceTypePage: - """ - Asynchronously retrieve a specific page of ResourceTypeInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of ResourceTypeInstance - """ - response = await self._version.domain.twilio.request_async( - 'GET', - target_url - ) - return ResourceTypePage(self._version, response, self._solution) - - - - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return '' - diff --git a/twilio/rest/preview_iam/organizations_openapi/role_assignment.py b/twilio/rest/preview_iam/organizations_openapi/role_assignment.py deleted file mode 100644 index 664e10bc36..0000000000 --- a/twilio/rest/preview_iam/organizations_openapi/role_assignment.py +++ /dev/null @@ -1,698 +0,0 @@ -r""" - This code was generated by - ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - - Organization Public API - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - NOTE: This class is auto generated by OpenAPI Generator. - https://openapi-generator.tech - Do not edit the class manually. -""" - - -from datetime import date, datetime -from decimal import Decimal -from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values -from twilio.base.instance_context import InstanceContext -from twilio.base.instance_resource import InstanceResource -from twilio.base.list_resource import ListResource -from twilio.base.version import Version -from twilio.base.page import Page - - -class RoleAssignmentInstance(InstanceResource): - - """ - :ivar sid: Twilio Role Assignment Sid representing this role assignment - :ivar role_sid: Twilio Role Sid representing assigned role - :ivar scope: Twilio Sid representing identity of this assignment - :ivar identity: Twilio Sid representing scope of this assignment - :ivar code: Twilio-specific error code - :ivar message: Error message - :ivar more_info: Link to Error Code References - :ivar status: HTTP response status code - """ - - def __init__(self, version: Version, payload: Dict[str, Any], organization_sid: Optional[str] = None, role_assignment_sid: Optional[str] = None): - super().__init__(version) - - - self.sid: Optional[str] = payload.get("sid") - self.role_sid: Optional[str] = payload.get("role_sid") - self.scope: Optional[str] = payload.get("scope") - self.identity: Optional[str] = payload.get("identity") - self.code: Optional[int] = payload.get("code") - self.message: Optional[str] = payload.get("message") - self.more_info: Optional[str] = payload.get("moreInfo") - self.status: Optional[int] = payload.get("status") - - - self._solution = { - "organization_sid": organization_sid or self.organization_sid, - "role_assignment_sid": role_assignment_sid or self.role_assignment_sid, - } - self._context: Optional[RoleAssignmentContext] = None - - @property - def _proxy(self) -> "RoleAssignmentContext": - """ - Generate an instance context for the instance, the context is capable of - performing various actions. All instance actions are proxied to the context - - :returns: RoleAssignmentContext for this RoleAssignmentInstance - """ - if self._context is None: - self._context = RoleAssignmentContext(self._version, organization_sid=self._solution['organization_sid'], role_assignment_sid=self._solution['role_assignment_sid'],) - return self._context - - - def delete(self) -> bool: - """ - Deletes the RoleAssignmentInstance - - - :returns: True if delete succeeds, False otherwise - """ - return self._proxy.delete() - async def delete_async(self) -> bool: - """ - Asynchronous coroutine that deletes the RoleAssignmentInstance - - - :returns: True if delete succeeds, False otherwise - """ - return await self._proxy.delete_async() - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) - -class RoleAssignmentContext(InstanceContext): - - def __init__(self, version: Version, organization_sid: str, role_assignment_sid: str): - """ - Initialize the RoleAssignmentContext - - :param version: Version that contains the resource - :param organization_sid: - :param role_assignment_sid: - """ - super().__init__(version) - - - # Path Solution - self._solution = { - 'organization_sid': organization_sid, - 'role_assignment_sid': role_assignment_sid, - } - self._uri = '/{organization_sid}/RoleAssignments/{role_assignment_sid}'.format(**self._solution) - - - - def delete(self) -> bool: - """ - Deletes the RoleAssignmentInstance - - - :returns: True if delete succeeds, False otherwise - """ - return self._version.delete(method='DELETE', uri=self._uri,) - - async def delete_async(self) -> bool: - """ - Asynchronous coroutine that deletes the RoleAssignmentInstance - - - :returns: True if delete succeeds, False otherwise - """ - return await self._version.delete_async(method='DELETE', uri=self._uri,) - - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) - return ''.format(context) - - - - - - - -class RoleAssignmentPage(Page): - - def get_instance(self, payload: Dict[str, Any]) -> RoleAssignmentInstance: - """ - Build an instance of RoleAssignmentInstance - - :param payload: Payload response from the API - """ - return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return "" - - - - -class RoleAssignmentPage(Page): - - def get_instance(self, payload: Dict[str, Any]) -> RoleAssignmentInstance: - """ - Build an instance of RoleAssignmentInstance - - :param payload: Payload response from the API - """ - return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution["organization_sid"]) - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return "" - - - - - -class RoleAssignmentList(ListResource): - - class PublicApiCreateRoleAssignmentRequest(object): - """ - :ivar role_sid: Twilio Role Sid representing assigned role - :ivar scope: Twilio Sid representing scope of this assignment - :ivar identity: Twilio Sid representing identity of this assignment - """ - - def __init__(self, payload: Dict[str, Any], organization_sid: Optional[str] = None, role_assignment_sid: Optional[str] = None): - - - self.role_sid: Optional[str] = payload.get("role_sid") - self.scope: Optional[str] = payload.get("scope") - self.identity: Optional[str] = payload.get("identity") - - def to_dict(self): - return { - - "role_sid": self.role_sid, - "scope": self.scope, - "identity": self.identity, - } - - - def __init__(self, version: Version, organization_sid: str): - """ - Initialize the RoleAssignmentList - - :param version: Version that contains the resource - :param organization_sid: - - """ - super().__init__(version) - - - # Path Solution - self._solution = { 'organization_sid': organization_sid, } - self._uri = '/{organization_sid}/RoleAssignments'.format(**self._solution) - - - - - def create(self, public_api_create_role_assignment_request: PublicApiCreateRoleAssignmentRequest) -> RoleAssignmentInstance: - """ - Create the RoleAssignmentInstance - - :param public_api_create_role_assignment_request: - - :returns: The created RoleAssignmentInstance - """ - data = public_api_create_role_assignment_request.to_dict() - - - headers = {'Content-Type': 'application/json'} - - payload = self._version.create(method='POST', uri=self._uri, data=data, headers=headers) - - return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution['organization_sid']) - - async def create_async(self, public_api_create_role_assignment_request: PublicApiCreateRoleAssignmentRequest) -> RoleAssignmentInstance: - """ - Asynchronously create the RoleAssignmentInstance - - :param public_api_create_role_assignment_request: - - :returns: The created RoleAssignmentInstance - """ - data = public_api_create_role_assignment_request.to_dict() - - - headers = {'Content-Type': 'application/json'} - - payload = await self._version.create_async(method='POST', uri=self._uri, data=data, headers=headers) - - return RoleAssignmentInstance(self._version, payload, organization_sid=self._solution['organization_sid']) - - - def stream(self, - - identity: Union[str, object] = values.unset, - scope: Union[str, object] = values.unset, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> Iterator[RoleAssignmentInstance]: - """ - Streams RoleAssignmentInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param str identity: - :param str scope: - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = self.page( - identity=identity, - scope=scope, - page_size=limits['page_size'] - ) - - return self._version.stream(page, limits['limit']) - - async def stream_async(self, - - identity: Union[str, object] = values.unset, - scope: Union[str, object] = values.unset, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> AsyncIterator[RoleAssignmentInstance]: - """ - Asynchronously streams RoleAssignmentInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param str identity: - :param str scope: - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = await self.page_async( - identity=identity, - scope=scope, - page_size=limits['page_size'] - ) - - return self._version.stream_async(page, limits['limit']) - - def list(self, - - identity: Union[str, object] = values.unset, - scope: Union[str, object] = values.unset, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[RoleAssignmentInstance]: - """ - Lists RoleAssignmentInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param str identity: - :param str scope: - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return list(self.stream( - identity=identity, - scope=scope, - limit=limit, - page_size=page_size, - )) - - async def list_async(self, - - identity: Union[str, object] = values.unset, - scope: Union[str, object] = values.unset, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[RoleAssignmentInstance]: - """ - Asynchronously lists RoleAssignmentInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param str identity: - :param str scope: - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return [record async for record in await self.stream_async( - identity=identity, - scope=scope, - limit=limit, - page_size=page_size, - )] - - def page(self, - - identity: Union[str, object] = values.unset, - scope: Union[str, object] = values.unset, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> RoleAssignmentPage: - """ - Retrieve a single page of RoleAssignmentInstance records from the API. - Request is executed immediately - - :param identity: - :param scope: - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of RoleAssignmentInstance - """ - data = values.of({ - 'Identity': identity, - 'Scope': scope, - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = self._version.page(method='GET', uri=self._uri, params=data) - return RoleAssignmentPage(self._version, response, self._solution) - - async def page_async(self, - - identity: Union[str, object] = values.unset, - scope: Union[str, object] = values.unset, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> RoleAssignmentPage: - """ - Asynchronously retrieve a single page of RoleAssignmentInstance records from the API. - Request is executed immediately - - :param identity: - :param scope: - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of RoleAssignmentInstance - """ - data = values.of({ - 'Identity': identity, - 'Scope': scope, - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = await self._version.page_async(method='GET', uri=self._uri, params=data) - return RoleAssignmentPage(self._version, response, self._solution) - - def get_page(self, target_url: str) -> RoleAssignmentPage: - """ - Retrieve a specific page of RoleAssignmentInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of RoleAssignmentInstance - """ - response = self._version.domain.twilio.request( - 'GET', - target_url - ) - return RoleAssignmentPage(self._version, response, self._solution) - - async def get_page_async(self, target_url: str) -> RoleAssignmentPage: - """ - Asynchronously retrieve a specific page of RoleAssignmentInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of RoleAssignmentInstance - """ - response = await self._version.domain.twilio.request_async( - 'GET', - target_url - ) - return RoleAssignmentPage(self._version, response, self._solution) - - - def stream(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> Iterator[RoleAssignmentInstance]: - """ - Streams RoleAssignmentInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = self.page( - page_size=limits['page_size'] - ) - - return self._version.stream(page, limits['limit']) - - async def stream_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> AsyncIterator[RoleAssignmentInstance]: - """ - Asynchronously streams RoleAssignmentInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = await self.page_async( - page_size=limits['page_size'] - ) - - return self._version.stream_async(page, limits['limit']) - - def list(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[RoleAssignmentInstance]: - """ - Lists RoleAssignmentInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return list(self.stream( - limit=limit, - page_size=page_size, - )) - - async def list_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[RoleAssignmentInstance]: - """ - Asynchronously lists RoleAssignmentInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return [record async for record in await self.stream_async( - limit=limit, - page_size=page_size, - )] - - def page(self, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> RoleAssignmentPage: - """ - Retrieve a single page of RoleAssignmentInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of RoleAssignmentInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = self._version.page(method='GET', uri=self._uri, params=data) - return RoleAssignmentPage(self._version, response, self._solution) - - async def page_async(self, - page_token: Union[str, object] = values.unset, - page_number: Union[int, object] = values.unset, - page_size: Union[int, object] = values.unset, - ) -> RoleAssignmentPage: - """ - Asynchronously retrieve a single page of RoleAssignmentInstance records from the API. - Request is executed immediately - - :param page_token: PageToken provided by the API - :param page_number: Page Number, this value is simply for client state - :param page_size: Number of records to return, defaults to 50 - - :returns: Page of RoleAssignmentInstance - """ - data = values.of({ - 'PageToken': page_token, - 'Page': page_number, - 'PageSize': page_size, - }) - - response = await self._version.page_async(method='GET', uri=self._uri, params=data) - return RoleAssignmentPage(self._version, response, self._solution) - - def get_page(self, target_url: str) -> RoleAssignmentPage: - """ - Retrieve a specific page of RoleAssignmentInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of RoleAssignmentInstance - """ - response = self._version.domain.twilio.request( - 'GET', - target_url - ) - return RoleAssignmentPage(self._version, response, self._solution) - - async def get_page_async(self, target_url: str) -> RoleAssignmentPage: - """ - Asynchronously retrieve a specific page of RoleAssignmentInstance records from the API. - Request is executed immediately - - :param target_url: API-generated URL for the requested results page - - :returns: Page of RoleAssignmentInstance - """ - response = await self._version.domain.twilio.request_async( - 'GET', - target_url - ) - return RoleAssignmentPage(self._version, response, self._solution) - - - - def get(self, organization_sid: str, role_assignment_sid: str) -> RoleAssignmentContext: - """ - Constructs a RoleAssignmentContext - - :param organization_sid: - :param role_assignment_sid: - """ - return RoleAssignmentContext(self._version, organization_sid=organization_sid, role_assignment_sid=role_assignment_sid) - - def __call__(self, organization_sid: str, role_assignment_sid: str) -> RoleAssignmentContext: - """ - Constructs a RoleAssignmentContext - - :param organization_sid: - :param role_assignment_sid: - """ - return RoleAssignmentContext(self._version, organization_sid=organization_sid, role_assignment_sid=role_assignment_sid) - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return '' - diff --git a/twilio/rest/preview_iam/organizations_openapi/token.py b/twilio/rest/preview_iam/organizations_openapi/token.py deleted file mode 100644 index a05fd9858b..0000000000 --- a/twilio/rest/preview_iam/organizations_openapi/token.py +++ /dev/null @@ -1,331 +0,0 @@ -r""" - This code was generated by - ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - - Organization Public API - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - NOTE: This class is auto generated by OpenAPI Generator. - https://openapi-generator.tech - Do not edit the class manually. -""" - - -from datetime import date, datetime -from decimal import Decimal -from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator -from twilio.base import deserialize, serialize, values - -from twilio.base.instance_resource import InstanceResource -from twilio.base.list_resource import ListResource -from twilio.base.version import Version - - - -class TokenInstance(InstanceResource): - - """ - :ivar access_token: Token which carries the necessary information to access a Twilio resource directly. - :ivar refresh_token: Token which carries the information necessary to get a new access token. - :ivar id_token: Token which carries the information necessary of user profile. - :ivar token_type: Token type - :ivar expires_in: - """ - - def __init__(self, version: Version, payload: Dict[str, Any]): - super().__init__(version) - - - self.access_token: Optional[str] = payload.get("access_token") - self.refresh_token: Optional[str] = payload.get("refresh_token") - self.id_token: Optional[str] = payload.get("id_token") - self.token_type: Optional[str] = payload.get("token_type") - self.expires_in: Optional[int] = payload.get("expires_in") - - - - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - - return '' - - - - -class TokenList(ListResource): - - def __init__(self, version: Version): - """ - Initialize the TokenList - - :param version: Version that contains the resource - - """ - super().__init__(version) - - - self._uri = '/token' - - - - def create(self, grant_type: str, client_id: str, client_secret: Union[str, object]=values.unset, code: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, audience: Union[str, object]=values.unset, refresh_token: Union[str, object]=values.unset, scope: Union[str, object]=values.unset) -> TokenInstance: - """ - Create the TokenInstance - - :param grant_type: Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. - :param client_id: A 34 character string that uniquely identifies this OAuth App. - :param client_secret: The credential for confidential OAuth App. - :param code: JWT token related to the authorization code grant type. - :param redirect_uri: The redirect uri - :param audience: The targeted audience uri - :param refresh_token: JWT token related to refresh access token. - :param scope: The scope of token - - :returns: The created TokenInstance - """ - - data = values.of({ - 'grant_type': grant_type, - 'client_id': client_id, - 'client_secret': client_secret, - 'code': code, - 'redirect_uri': redirect_uri, - 'audience': audience, - 'refresh_token': refresh_token, - 'scope': scope, - }) - - - - payload = self._version.create(method='POST', uri=self._uri, data=data,) - - return TokenInstance(self._version, payload) - - async def create_async(self, grant_type: str, client_id: str, client_secret: Union[str, object]=values.unset, code: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, audience: Union[str, object]=values.unset, refresh_token: Union[str, object]=values.unset, scope: Union[str, object]=values.unset) -> TokenInstance: - """ - Asynchronously create the TokenInstance - - :param grant_type: Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. - :param client_id: A 34 character string that uniquely identifies this OAuth App. - :param client_secret: The credential for confidential OAuth App. - :param code: JWT token related to the authorization code grant type. - :param redirect_uri: The redirect uri - :param audience: The targeted audience uri - :param refresh_token: JWT token related to refresh access token. - :param scope: The scope of token - - :returns: The created TokenInstance - """ - - data = values.of({ - 'grant_type': grant_type, - 'client_id': client_id, - 'client_secret': client_secret, - 'code': code, - 'redirect_uri': redirect_uri, - 'audience': audience, - 'refresh_token': refresh_token, - 'scope': scope, - }) - - - - payload = await self._version.create_async(method='POST', uri=self._uri, data=data,) - - return TokenInstance(self._version, payload) - - - def stream(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> Iterator[TokenInstance]: - """ - Streams TokenInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = self.page( - page_size=limits['page_size'] - ) - - return self._version.stream(page, limits['limit']) - - async def stream_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> AsyncIterator[TokenInstance]: - """ - Asynchronously streams TokenInstance records from the API as a generator stream. - This operation lazily loads records as efficiently as possible until the limit - is reached. - The results are returned as a generator, so this operation is memory efficient. - - :param limit: Upper limit for the number of records to return. stream() - guarantees to never return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, stream() will attempt to read the - limit with the most efficient page size, i.e. min(limit, 1000) - - :returns: Generator that will yield up to limit results - """ - limits = self._version.read_limits(limit, page_size) - page = await self.page_async( - page_size=limits['page_size'] - ) - - return self._version.stream_async(page, limits['limit']) - - def list(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[TokenInstance]: - """ - Lists TokenInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return list(self.stream( - limit=limit, - page_size=page_size, - )) - - async def list_async(self, - limit: Optional[int] = None, - page_size: Optional[int] = None, - ) -> List[TokenInstance]: - """ - Asynchronously lists TokenInstance records from the API as a list. - Unlike stream(), this operation is eager and will load `limit` records into - memory before returning. - - :param limit: Upper limit for the number of records to return. list() guarantees - never to return more than limit. Default is no limit - :param page_size: Number of records to fetch per request, when not set will use - the default value of 50 records. If no page_size is defined - but a limit is defined, list() will attempt to read the limit - with the most efficient page size, i.e. min(limit, 1000) - - :returns: list that will contain up to limit results - """ - return [record async for record in await self.stream_async( - limit=limit, - page_size=page_size, - )] - - # def page(self, - # page_token: Union[str, object] = values.unset, - # page_number: Union[int, object] = values.unset, - # page_size: Union[int, object] = values.unset, - # ) -> TokenPage: - # """ - # Retrieve a single page of TokenInstance records from the API. - # Request is executed immediately - # - # :param page_token: PageToken provided by the API - # :param page_number: Page Number, this value is simply for client state - # :param page_size: Number of records to return, defaults to 50 - # - # :returns: Page of TokenInstance - # """ - # data = values.of({ - # 'PageToken': page_token, - # 'Page': page_number, - # 'PageSize': page_size, - # }) - # - # response = self._version.page(method='GET', uri=self._uri, params=data) - # return TokenPage(self._version, response) - - # async def page_async(self, - # page_token: Union[str, object] = values.unset, - # page_number: Union[int, object] = values.unset, - # page_size: Union[int, object] = values.unset, - # ) -> TokenPage: - # """ - # Asynchronously retrieve a single page of TokenInstance records from the API. - # Request is executed immediately - # - # :param page_token: PageToken provided by the API - # :param page_number: Page Number, this value is simply for client state - # :param page_size: Number of records to return, defaults to 50 - # - # :returns: Page of TokenInstance - # """ - # data = values.of({ - # 'PageToken': page_token, - # 'Page': page_number, - # 'PageSize': page_size, - # }) - # - # response = await self._version.page_async(method='GET', uri=self._uri, params=data) - # return TokenPage(self._version, response) - - # def get_page(self, target_url: str) -> TokenPage: - # """ - # Retrieve a specific page of TokenInstance records from the API. - # Request is executed immediately - # - # :param target_url: API-generated URL for the requested results page - # - # :returns: Page of TokenInstance - # """ - # response = self._version.domain.twilio.request( - # 'GET', - # target_url - # ) - # return TokenPage(self._version, response) - - # async def get_page_async(self, target_url: str) -> TokenPage: - # """ - # Asynchronously retrieve a specific page of TokenInstance records from the API. - # Request is executed immediately - # - # :param target_url: API-generated URL for the requested results page - # - # :returns: Page of TokenInstance - # """ - # response = await self._version.domain.twilio.request_async( - # 'GET', - # target_url - # ) - # return TokenPage(self._version, response) - - - - - def __repr__(self) -> str: - """ - Provide a friendly representation - - :returns: Machine friendly representation - """ - return '' - From f36f7851a05f6cff3ec4635e31ca59e3b9d6ff48 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Mon, 24 Jun 2024 16:35:35 +0530 Subject: [PATCH 03/14] chore: oauth sdk implementation --- twilio/http/no_auth_http_client.py | 5 + twilio/http/orgs_token_manager.py | 33 +++++ twilio/rest/preview_iam/PreviewIamBase.py | 29 +++++ .../organizations_openapi/token.py | 123 ++++++++++++++++++ twilio/twilio_bearer_token_auth.py | 28 +--- 5 files changed, 193 insertions(+), 25 deletions(-) create mode 100644 twilio/http/orgs_token_manager.py create mode 100644 twilio/rest/preview_iam/PreviewIamBase.py create mode 100644 twilio/rest/preview_iam/organizations_openapi/token.py diff --git a/twilio/http/no_auth_http_client.py b/twilio/http/no_auth_http_client.py index e69de29bb2..6b42416560 100644 --- a/twilio/http/no_auth_http_client.py +++ b/twilio/http/no_auth_http_client.py @@ -0,0 +1,5 @@ +class NoAuthHTTPClient: + + def get_headers(self): + headers = {} + return headers diff --git a/twilio/http/orgs_token_manager.py b/twilio/http/orgs_token_manager.py new file mode 100644 index 0000000000..5b523074b8 --- /dev/null +++ b/twilio/http/orgs_token_manager.py @@ -0,0 +1,33 @@ +from twilio.rest.preview_iam.organizations_openapi.token import TokenList +from twilio.http.http_client import TwilioHttpClient + +class OrgTokenManager: + """ + Orgs Token Manager + """ + def __init__(self, grant_type: str, client_id: str, client_secret: str): + self.grant_type = grant_type + self.client_id = client_id + self.client_secret = client_secret + + def __init__(self, grant_type: str, client_id: str, client_secret: str, code: str, redirect_uri: str, audience: str, refreshToken: str, scope: str): + self.grant_type = grant_type + self.client_id = client_id + self.client_secret = client_secret + self.code = code + self.redirect_uri = redirect_uri + self.audience = audience + self.refreshToken = refreshToken + self.scope = scope + + def fetch_access_token(self): + token_list = TokenList() + token_list.create( + grant_type=self.grant_type, + client_id=self.client_id, + client_secret=self.client_secret, + code=self.code, + redirect_uri=self.redirect_uri, + audience=self.audience, + scope=self.scope + ) diff --git a/twilio/rest/preview_iam/PreviewIamBase.py b/twilio/rest/preview_iam/PreviewIamBase.py new file mode 100644 index 0000000000..9cf1f3bac3 --- /dev/null +++ b/twilio/rest/preview_iam/PreviewIamBase.py @@ -0,0 +1,29 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" +from twilio.base.domain import Domain +from twilio.rest import Client +from twilio.rest.preview_iam.organizations_openapi.token import Token +from twilio.rest.preview_iam.organizations_openapi.account import Account +from twilio.rest.preview_iam.organizations_openapi.authorize import AuthorizeList +from twilio.rest.preview_iam.organizations_openapi.resource_type import ResourceTypeList +from twilio.rest.preview_iam.organizations_openapi.role_assignment import RoleAssignmentList + +class PreviewIamBase(Domain): + def __init__(self, twilio: Client): + """ + Initialize the PreviewIam Domain + + :returns: Domain for PreviewIam + """ + super().__init__(twilio, "https://preview.twilio.com/iam") + self._token: Optional[TokenList] = None + self._service_accounts: Optional[ServiceAccounts] = None + self._service_roles: Optional[ServiceRoles] = None \ No newline at end of file diff --git a/twilio/rest/preview_iam/organizations_openapi/token.py b/twilio/rest/preview_iam/organizations_openapi/token.py new file mode 100644 index 0000000000..60c93945cf --- /dev/null +++ b/twilio/rest/preview_iam/organizations_openapi/token.py @@ -0,0 +1,123 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + + +from datetime import date, datetime +from decimal import Decimal +from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator +from twilio.base import deserialize, serialize, values + +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version +from twilio.http.http_client import TwilioHttpClient + + + +class TokenInstance(InstanceResource): + + """ + :ivar access_token: Token which carries the necessary information to access a Twilio resource directly. + :ivar refresh_token: Token which carries the information necessary to get a new access token. + :ivar id_token: Token which carries the information necessary of user profile. + :ivar token_type: Token type + :ivar expires_in: + """ + + def __init__(self, version: Version, payload: Dict[str, Any]): + super().__init__(version) + + + self.access_token: Optional[str] = payload.get("access_token") + self.refresh_token: Optional[str] = payload.get("refresh_token") + self.id_token: Optional[str] = payload.get("id_token") + self.token_type: Optional[str] = payload.get("token_type") + self.expires_in: Optional[int] = payload.get("expires_in") + + + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + + return '' + + + + +class TokenList(ListResource): + + def __init__(self, version: Version): + """ + Initialize the TokenList + + :param version: Version that contains the resource + + """ + super().__init__(version) + + + self._uri = '/token' + + + + def create(self, grant_type: str, client_id: str, client_secret: Union[str, object]=values.unset, code: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, audience: Union[str, object]=values.unset, refresh_token: Union[str, object]=values.unset, scope: Union[str, object]=values.unset) -> TokenInstance: + """ + Create the TokenInstance + + :param grant_type: Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + :param client_id: A 34 character string that uniquely identifies this OAuth App. + :param client_secret: The credential for confidential OAuth App. + :param code: JWT token related to the authorization code grant type. + :param redirect_uri: The redirect uri + :param audience: The targeted audience uri + :param refresh_token: JWT token related to refresh access token. + :param scope: The scope of token + + :returns: The created TokenInstance + """ + + data = values.of({ + 'grant_type': grant_type, + 'client_id': client_id, + 'client_secret': client_secret, + 'code': code, + 'redirect_uri': redirect_uri, + 'audience': audience, + 'refresh_token': refresh_token, + 'scope': scope, + }) + + twilioHttpClient = TwilioHttpClient() + retries = 0 + while retries < 5: + try: + response = twilioHttpClient.request( + 'POST', + 'https://preview-iam.twilio.com', + data=data, + headers= {'content-type': 'json'}, + ) + if response.status_code >= 400 or response.status_code < 500: + retries += 1 + continue + return response.status_code['data'] + except Exception as e: + if retries == 5: + raise e + continue diff --git a/twilio/twilio_bearer_token_auth.py b/twilio/twilio_bearer_token_auth.py index f396e86f5b..90c8b9c9fb 100644 --- a/twilio/twilio_bearer_token_auth.py +++ b/twilio/twilio_bearer_token_auth.py @@ -10,7 +10,6 @@ class TwilioBearerTokenAuth: _lock = Lock() access_token = None rest_client = None - executor_service = None user_agent_extensions = None region = None edge = None @@ -21,7 +20,7 @@ def init(cls, access_token): if not access_token: raise ValueError("Access Token cannot be null or Empty") if access_token != cls.access_token: - cls.invalidate() + cls.access_token = None cls.access_token = access_token @classmethod @@ -30,27 +29,6 @@ def get_access_token(cls): return cls.access_token @classmethod - def get_rest_client(cls): + def get_header_param(cls): with cls._lock: - if cls.rest_client is None: - cls.rest_client = cls.build_oauth_rest_client() - return cls.rest_client - - @classmethod - def get_executor_service(cls): - with cls._lock: - if cls.executor_service is None: - cls.executor_service = ThreadPoolExecutor(max_workers=None) - return cls.executor_service - - @classmethod - def build_oauth_rest_client(cls): - builder = BearerTokenTwilioRestClient.Builder(cls.access_token) - - if cls.user_agent_extensions is not None: - builder.user_agent_extensions(cls.user_agent_extensions) - - builder.region(cls.region) - builder.edge(cls.edge) - - return builder.build() \ No newline at end of file + return {"Authorization": "Bearer {token}".format(token=cls.access_token)} \ No newline at end of file From 8cb3d4780b1f3357dbd5b84ae9c72fdbb419c232 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Mon, 24 Jun 2024 16:35:43 +0530 Subject: [PATCH 04/14] chore: oauth sdk implementation --- twilio/http/bearer_token_http_client.py | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/twilio/http/bearer_token_http_client.py b/twilio/http/bearer_token_http_client.py index e69de29bb2..0b2eff6552 100644 --- a/twilio/http/bearer_token_http_client.py +++ b/twilio/http/bearer_token_http_client.py @@ -0,0 +1,35 @@ +import datetime +import jwt + +from twilio.http.orgs_token_manager import OrgTokenManager +from twilio.twilio_bearer_token_auth import TwilioBearerTokenAuth + + +class BearerTokenHTTPClient: + def __init__(self, orgs_token_manager: OrgTokenManager): + self.orgs_token_manager = orgs_token_manager + + def get_headers(self): + headers = {} + if TwilioBearerTokenAuth.get_access_token() is None: + access_token = OrgTokenManager.fetch_access_token() + TwilioBearerTokenAuth.init(access_token) + elif TwilioBearerTokenAuth.get_access_token() is not None and self.is_token_expired(TwilioBearerTokenAuth.get_access_token()): + access_token = OrgTokenManager.fetch_access_token() + TwilioBearerTokenAuth.init(access_token) + else: + access_token = TwilioBearerTokenAuth.get_access_token() + + headers.update({ + 'Authorization': 'Bearer {}'.format(access_token) + }) + + return headers + + def is_token_expired(self, token): + decoded_jwt = jwt.decode(token, options={"verify_signature": False}) + expires_at = decoded_jwt.get('exp') + # Add a buffer of 30 seconds + buffer_seconds = 30 + buffer_expires_at = expires_at - buffer_seconds + return buffer_expires_at < datetime.datetime.now().timestamp() From 691071d052797dd88ab216e96980d0041238ed97 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Mon, 24 Jun 2024 21:58:48 +0530 Subject: [PATCH 05/14] chore: oauth sdk implementation --- twilio/http/bearer_token_http_client.py | 7 ++----- twilio/http/orgs_token_manager.py | 2 +- .../rest/preview_iam/organizations_openapi/token.py | 13 ++++++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/twilio/http/bearer_token_http_client.py b/twilio/http/bearer_token_http_client.py index 0b2eff6552..a8353d9322 100644 --- a/twilio/http/bearer_token_http_client.py +++ b/twilio/http/bearer_token_http_client.py @@ -11,11 +11,8 @@ def __init__(self, orgs_token_manager: OrgTokenManager): def get_headers(self): headers = {} - if TwilioBearerTokenAuth.get_access_token() is None: - access_token = OrgTokenManager.fetch_access_token() - TwilioBearerTokenAuth.init(access_token) - elif TwilioBearerTokenAuth.get_access_token() is not None and self.is_token_expired(TwilioBearerTokenAuth.get_access_token()): - access_token = OrgTokenManager.fetch_access_token() + if TwilioBearerTokenAuth.get_access_token() is None or self.is_token_expired(TwilioBearerTokenAuth.get_access_token()): + access_token = self.orgs_token_manager.fetch_access_token() TwilioBearerTokenAuth.init(access_token) else: access_token = TwilioBearerTokenAuth.get_access_token() diff --git a/twilio/http/orgs_token_manager.py b/twilio/http/orgs_token_manager.py index 5b523074b8..81fe5093b2 100644 --- a/twilio/http/orgs_token_manager.py +++ b/twilio/http/orgs_token_manager.py @@ -22,7 +22,7 @@ def __init__(self, grant_type: str, client_id: str, client_secret: str, code: st def fetch_access_token(self): token_list = TokenList() - token_list.create( + return token_list.create( grant_type=self.grant_type, client_id=self.client_id, client_secret=self.client_secret, diff --git a/twilio/rest/preview_iam/organizations_openapi/token.py b/twilio/rest/preview_iam/organizations_openapi/token.py index 60c93945cf..4c032b5a04 100644 --- a/twilio/rest/preview_iam/organizations_openapi/token.py +++ b/twilio/rest/preview_iam/organizations_openapi/token.py @@ -17,6 +17,7 @@ from decimal import Decimal from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator from twilio.base import deserialize, serialize, values +import json from twilio.base.instance_resource import InstanceResource from twilio.base.list_resource import ListResource @@ -62,14 +63,13 @@ def __repr__(self) -> str: class TokenList(ListResource): - def __init__(self, version: Version): + def __init__(self): """ Initialize the TokenList :param version: Version that contains the resource """ - super().__init__(version) self._uri = '/token' @@ -109,14 +109,13 @@ def create(self, grant_type: str, client_id: str, client_secret: Union[str, obje try: response = twilioHttpClient.request( 'POST', - 'https://preview-iam.twilio.com', - data=data, - headers= {'content-type': 'json'}, + 'https://preview-iam.twilio.com/v1/token', + data=data ) - if response.status_code >= 400 or response.status_code < 500: + if response.status_code == 401: retries += 1 continue - return response.status_code['data'] + return json.loads(response.content)['access_token'] except Exception as e: if retries == 5: raise e From 6204eae8aab75c88995530c69600d710226ea3b1 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Sat, 6 Jul 2024 21:23:28 +0530 Subject: [PATCH 06/14] chore: oauth sdk implementation --- twilio/http/BaseHttpClient.py | 0 twilio/http/bearer_token_http_client.py | 14 ++-- twilio/http/orgs_token_manager.py | 20 +++-- twilio/http/token_manager.py | 15 ++++ .../token.py | 80 ++++++++++++++----- 5 files changed, 88 insertions(+), 41 deletions(-) delete mode 100644 twilio/http/BaseHttpClient.py create mode 100644 twilio/http/token_manager.py rename twilio/rest/preview_iam/{organizations_openapi => organizations}/token.py (60%) diff --git a/twilio/http/BaseHttpClient.py b/twilio/http/BaseHttpClient.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/twilio/http/bearer_token_http_client.py b/twilio/http/bearer_token_http_client.py index a8353d9322..7e6095a22a 100644 --- a/twilio/http/bearer_token_http_client.py +++ b/twilio/http/bearer_token_http_client.py @@ -1,6 +1,7 @@ import datetime import jwt +from twilio.base.version import Version from twilio.http.orgs_token_manager import OrgTokenManager from twilio.twilio_bearer_token_auth import TwilioBearerTokenAuth @@ -9,22 +10,17 @@ class BearerTokenHTTPClient: def __init__(self, orgs_token_manager: OrgTokenManager): self.orgs_token_manager = orgs_token_manager - def get_headers(self): - headers = {} + def get_headers(self, version: Version): if TwilioBearerTokenAuth.get_access_token() is None or self.is_token_expired(TwilioBearerTokenAuth.get_access_token()): - access_token = self.orgs_token_manager.fetch_access_token() + access_token = self.orgs_token_manager.fetch_access_token(version) TwilioBearerTokenAuth.init(access_token) else: access_token = TwilioBearerTokenAuth.get_access_token() - headers.update({ - 'Authorization': 'Bearer {}'.format(access_token) - }) - - return headers + return access_token def is_token_expired(self, token): - decoded_jwt = jwt.decode(token, options={"verify_signature": False}) + decoded_jwt = jwt.decode(token, options={"verify_signature": True}) expires_at = decoded_jwt.get('exp') # Add a buffer of 30 seconds buffer_seconds = 30 diff --git a/twilio/http/orgs_token_manager.py b/twilio/http/orgs_token_manager.py index 81fe5093b2..363b7549eb 100644 --- a/twilio/http/orgs_token_manager.py +++ b/twilio/http/orgs_token_manager.py @@ -1,16 +1,13 @@ -from twilio.rest.preview_iam.organizations_openapi.token import TokenList -from twilio.http.http_client import TwilioHttpClient -class OrgTokenManager: +from twilio.base.version import Version +from twilio.rest.preview_iam.organizations.token import TokenList + +class OrgTokenManager(): """ Orgs Token Manager """ - def __init__(self, grant_type: str, client_id: str, client_secret: str): - self.grant_type = grant_type - self.client_id = client_id - self.client_secret = client_secret - def __init__(self, grant_type: str, client_id: str, client_secret: str, code: str, redirect_uri: str, audience: str, refreshToken: str, scope: str): + def __init__(self, grant_type: str, client_id: str, client_secret: str, code: str = None, redirect_uri: str = None, audience: str = None, refreshToken: str = None, scope: str = None): self.grant_type = grant_type self.client_id = client_id self.client_secret = client_secret @@ -20,9 +17,9 @@ def __init__(self, grant_type: str, client_id: str, client_secret: str, code: st self.refreshToken = refreshToken self.scope = scope - def fetch_access_token(self): - token_list = TokenList() - return token_list.create( + def fetch_access_token(self, version: Version): + token_list = TokenList(version) + token_instance = token_list.create( grant_type=self.grant_type, client_id=self.client_id, client_secret=self.client_secret, @@ -31,3 +28,4 @@ def fetch_access_token(self): audience=self.audience, scope=self.scope ) + return token_instance.access_token diff --git a/twilio/http/token_manager.py b/twilio/http/token_manager.py new file mode 100644 index 0000000000..fea1f55efc --- /dev/null +++ b/twilio/http/token_manager.py @@ -0,0 +1,15 @@ +from twilio.base.version import Version +from twilio.http.orgs_token_manager import OrgTokenManager +class TokenManager: + org_token_manager = None + + @classmethod + def init(cls, grant_type: str, client_id: str, client_secret: str, code: str = None, redirect_uri: str = None, audience: str = None, refreshToken: str = None, scope: str = None): + cls.org_token_manager = OrgTokenManager(grant_type, client_id, client_secret, code, redirect_uri, audience, refreshToken, scope) + + @classmethod + def get_token_manager(cls, version: Version): + if cls.org_token_manager is None: + raise Exception("Token Manager not initialized") + cls.org_token_manager.version = version + return cls.org_token_manager diff --git a/twilio/rest/preview_iam/organizations_openapi/token.py b/twilio/rest/preview_iam/organizations/token.py similarity index 60% rename from twilio/rest/preview_iam/organizations_openapi/token.py rename to twilio/rest/preview_iam/organizations/token.py index 4c032b5a04..fc28287e8f 100644 --- a/twilio/rest/preview_iam/organizations_openapi/token.py +++ b/twilio/rest/preview_iam/organizations/token.py @@ -17,12 +17,10 @@ from decimal import Decimal from typing import Any, Dict, List, Optional, Union, Iterator, AsyncIterator from twilio.base import deserialize, serialize, values -import json from twilio.base.instance_resource import InstanceResource from twilio.base.list_resource import ListResource from twilio.base.version import Version -from twilio.http.http_client import TwilioHttpClient @@ -56,20 +54,21 @@ def __repr__(self) -> str: :returns: Machine friendly representation """ - return '' + return '' class TokenList(ListResource): - def __init__(self): + def __init__(self, version: Version): """ Initialize the TokenList :param version: Version that contains the resource """ + super().__init__(version) self._uri = '/token' @@ -102,21 +101,60 @@ def create(self, grant_type: str, client_id: str, client_secret: Union[str, obje 'refresh_token': refresh_token, 'scope': scope, }) + headers = values.of({ + 'Content-Type': 'application/x-www-form-urlencoded' + }) + + + + payload = self._version.create(method='POST', uri=self._uri, data=data, headers=headers) + + return TokenInstance(self._version, payload) + + async def create_async(self, grant_type: str, client_id: str, client_secret: Union[str, object]=values.unset, code: Union[str, object]=values.unset, redirect_uri: Union[str, object]=values.unset, audience: Union[str, object]=values.unset, refresh_token: Union[str, object]=values.unset, scope: Union[str, object]=values.unset) -> TokenInstance: + """ + Asynchronously create the TokenInstance + + :param grant_type: Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + :param client_id: A 34 character string that uniquely identifies this OAuth App. + :param client_secret: The credential for confidential OAuth App. + :param code: JWT token related to the authorization code grant type. + :param redirect_uri: The redirect uri + :param audience: The targeted audience uri + :param refresh_token: JWT token related to refresh access token. + :param scope: The scope of token + + :returns: The created TokenInstance + """ + + data = values.of({ + 'grant_type': grant_type, + 'client_id': client_id, + 'client_secret': client_secret, + 'code': code, + 'redirect_uri': redirect_uri, + 'audience': audience, + 'refresh_token': refresh_token, + 'scope': scope, + }) + headers = values.of({ + 'Content-Type': 'application/x-www-form-urlencoded' + }) + - twilioHttpClient = TwilioHttpClient() - retries = 0 - while retries < 5: - try: - response = twilioHttpClient.request( - 'POST', - 'https://preview-iam.twilio.com/v1/token', - data=data - ) - if response.status_code == 401: - retries += 1 - continue - return json.loads(response.content)['access_token'] - except Exception as e: - if retries == 5: - raise e - continue + + payload = await self._version.create_async(method='POST', uri=self._uri, data=data, headers=headers) + + return TokenInstance(self._version, payload) + + + + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return '' + From f429196bb36bfafc6dccbcb7b06e841035f00c99 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Sat, 6 Jul 2024 22:28:28 +0530 Subject: [PATCH 07/14] chore: oauth sdk implementation --- twilio/http/token_manager.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/twilio/http/token_manager.py b/twilio/http/token_manager.py index fea1f55efc..9500c52802 100644 --- a/twilio/http/token_manager.py +++ b/twilio/http/token_manager.py @@ -4,8 +4,11 @@ class TokenManager: org_token_manager = None @classmethod - def init(cls, grant_type: str, client_id: str, client_secret: str, code: str = None, redirect_uri: str = None, audience: str = None, refreshToken: str = None, scope: str = None): - cls.org_token_manager = OrgTokenManager(grant_type, client_id, client_secret, code, redirect_uri, audience, refreshToken, scope) + def init(cls, grant_type: str, client_id: str, client_secret: str, code: str = None, redirect_uri: str = None, audience: str = None, refreshToken: str = None, scope: str = None, tokenManager: OrgTokenManager = None): + if tokenManager is not None: + cls.org_token_manager = OrgTokenManager(grant_type, client_id, client_secret, code, redirect_uri, audience, refreshToken, scope) + else: + cls.org_token_manager = tokenManager @classmethod def get_token_manager(cls, version: Version): From a1521dd9067f566a751fa1a9f2f3ab612ec25f9e Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Tue, 9 Jul 2024 18:20:41 +0530 Subject: [PATCH 08/14] chore: oauth sdk implementation --- twilio/http/token_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twilio/http/token_manager.py b/twilio/http/token_manager.py index 9500c52802..aab200399d 100644 --- a/twilio/http/token_manager.py +++ b/twilio/http/token_manager.py @@ -5,7 +5,7 @@ class TokenManager: @classmethod def init(cls, grant_type: str, client_id: str, client_secret: str, code: str = None, redirect_uri: str = None, audience: str = None, refreshToken: str = None, scope: str = None, tokenManager: OrgTokenManager = None): - if tokenManager is not None: + if tokenManager is None: cls.org_token_manager = OrgTokenManager(grant_type, client_id, client_secret, code, redirect_uri, audience, refreshToken, scope) else: cls.org_token_manager = tokenManager From 404b81b80a2c2c3a38538184dfbf178fd364a402 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Fri, 12 Jul 2024 15:49:04 +0530 Subject: [PATCH 09/14] feat: bearer token client --- test_oauth_sdk.py | 0 twilio/http/bearer_token_http_client.py | 10 ++++++---- twilio/http/no_auth_http_client.py | 1 - twilio/http/orgs_token_manager.py | 19 +++++++++++++++---- twilio/http/token_manager.py | 19 ++++--------------- twilio/http/token_manager_initializer.py | 16 ++++++++++++++++ 6 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 test_oauth_sdk.py create mode 100644 twilio/http/token_manager_initializer.py diff --git a/test_oauth_sdk.py b/test_oauth_sdk.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/twilio/http/bearer_token_http_client.py b/twilio/http/bearer_token_http_client.py index 7e6095a22a..784210c83d 100644 --- a/twilio/http/bearer_token_http_client.py +++ b/twilio/http/bearer_token_http_client.py @@ -2,16 +2,18 @@ import jwt from twilio.base.version import Version -from twilio.http.orgs_token_manager import OrgTokenManager +from twilio.http.token_manager import TokenManager from twilio.twilio_bearer_token_auth import TwilioBearerTokenAuth class BearerTokenHTTPClient: - def __init__(self, orgs_token_manager: OrgTokenManager): + def __init__(self, orgs_token_manager: TokenManager): self.orgs_token_manager = orgs_token_manager def get_headers(self, version: Version): - if TwilioBearerTokenAuth.get_access_token() is None or self.is_token_expired(TwilioBearerTokenAuth.get_access_token()): + if TwilioBearerTokenAuth.get_access_token() is None or self.is_token_expired( + TwilioBearerTokenAuth.get_access_token() + ): access_token = self.orgs_token_manager.fetch_access_token(version) TwilioBearerTokenAuth.init(access_token) else: @@ -21,7 +23,7 @@ def get_headers(self, version: Version): def is_token_expired(self, token): decoded_jwt = jwt.decode(token, options={"verify_signature": True}) - expires_at = decoded_jwt.get('exp') + expires_at = decoded_jwt.get("exp") # Add a buffer of 30 seconds buffer_seconds = 30 buffer_expires_at = expires_at - buffer_seconds diff --git a/twilio/http/no_auth_http_client.py b/twilio/http/no_auth_http_client.py index 6b42416560..daa5e5cdcc 100644 --- a/twilio/http/no_auth_http_client.py +++ b/twilio/http/no_auth_http_client.py @@ -1,5 +1,4 @@ class NoAuthHTTPClient: - def get_headers(self): headers = {} return headers diff --git a/twilio/http/orgs_token_manager.py b/twilio/http/orgs_token_manager.py index 363b7549eb..fbde521a3e 100644 --- a/twilio/http/orgs_token_manager.py +++ b/twilio/http/orgs_token_manager.py @@ -1,13 +1,24 @@ - from twilio.base.version import Version +from twilio.http.token_manager import TokenManager from twilio.rest.preview_iam.organizations.token import TokenList -class OrgTokenManager(): + +class OrgTokenManager(TokenManager): """ Orgs Token Manager """ - def __init__(self, grant_type: str, client_id: str, client_secret: str, code: str = None, redirect_uri: str = None, audience: str = None, refreshToken: str = None, scope: str = None): + def __init__( + self, + grant_type: str, + client_id: str, + client_secret: str, + code: str = None, + redirect_uri: str = None, + audience: str = None, + refreshToken: str = None, + scope: str = None, + ): self.grant_type = grant_type self.client_id = client_id self.client_secret = client_secret @@ -26,6 +37,6 @@ def fetch_access_token(self, version: Version): code=self.code, redirect_uri=self.redirect_uri, audience=self.audience, - scope=self.scope + scope=self.scope, ) return token_instance.access_token diff --git a/twilio/http/token_manager.py b/twilio/http/token_manager.py index aab200399d..28cc731019 100644 --- a/twilio/http/token_manager.py +++ b/twilio/http/token_manager.py @@ -1,18 +1,7 @@ from twilio.base.version import Version -from twilio.http.orgs_token_manager import OrgTokenManager -class TokenManager: - org_token_manager = None - @classmethod - def init(cls, grant_type: str, client_id: str, client_secret: str, code: str = None, redirect_uri: str = None, audience: str = None, refreshToken: str = None, scope: str = None, tokenManager: OrgTokenManager = None): - if tokenManager is None: - cls.org_token_manager = OrgTokenManager(grant_type, client_id, client_secret, code, redirect_uri, audience, refreshToken, scope) - else: - cls.org_token_manager = tokenManager - @classmethod - def get_token_manager(cls, version: Version): - if cls.org_token_manager is None: - raise Exception("Token Manager not initialized") - cls.org_token_manager.version = version - return cls.org_token_manager +class TokenManager: + + def fetch_access_token(self, version: Version): + pass diff --git a/twilio/http/token_manager_initializer.py b/twilio/http/token_manager_initializer.py new file mode 100644 index 0000000000..d4836d68a4 --- /dev/null +++ b/twilio/http/token_manager_initializer.py @@ -0,0 +1,16 @@ +from twilio.http.token_manager import TokenManager + + +class TokenManagerInitializer: + + org_token_manager = None + + @classmethod + def set_token_manager(cls, token_manager: TokenManager): + cls.org_token_manager = token_manager + + @classmethod + def get_token_manager(cls): + if cls.org_token_manager is None: + raise Exception('Token Manager not initialized') + return cls.org_token_manager \ No newline at end of file From 67c86973e4348008c574b102764a9efe0c9a62ca Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Tue, 16 Jul 2024 23:16:55 +0530 Subject: [PATCH 10/14] chore: oauth sdk implementation --- twilio/base/client_base.py | 13 ++++++++++++- twilio/base/domain.py | 3 +++ twilio/base/oauth_token_base.py | 25 +++++++++++++++++++++++++ twilio/base/version.py | 4 ++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 twilio/base/oauth_token_base.py diff --git a/twilio/base/client_base.py b/twilio/base/client_base.py index 5f17c75406..c2fc14af60 100644 --- a/twilio/base/client_base.py +++ b/twilio/base/client_base.py @@ -69,6 +69,8 @@ def request( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, + domain: Optional[str] = None ) -> Response: """ Makes a request to the Twilio API using the configured http client @@ -85,9 +87,13 @@ def request( :returns: Response from the Twilio API """ - auth = self.get_auth(auth) + if not is_oauth: + auth = self.get_auth(auth) headers = self.get_headers(method, headers) uri = self.get_hostname(uri) + if is_oauth: + OauthTokenBase = dynamic_import("twilio.base.oauth_token_base", "OauthTokenBase") + headers['Authorization'] = f'Bearer {OauthTokenBase().get_oauth_token(domain, "v1", self.username, self.password)}' return self.http_client.request( method, @@ -232,3 +238,8 @@ def __repr__(self) -> str: :returns: Machine friendly representation """ return "".format(self.account_sid) + +def dynamic_import(module_name, class_name): + from importlib import import_module + module = import_module(module_name) + return getattr(module, class_name) diff --git a/twilio/base/domain.py b/twilio/base/domain.py index 4f8395ddf2..51375e55c5 100644 --- a/twilio/base/domain.py +++ b/twilio/base/domain.py @@ -32,6 +32,7 @@ def request( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Response: """ Makes an HTTP request to this domain. @@ -55,6 +56,8 @@ def request( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth, + domain=self.base_url, ) async def request_async( diff --git a/twilio/base/oauth_token_base.py b/twilio/base/oauth_token_base.py new file mode 100644 index 0000000000..3576246a86 --- /dev/null +++ b/twilio/base/oauth_token_base.py @@ -0,0 +1,25 @@ +from twilio.http.token_manager_initializer import TokenManagerInitializer + +# Dynamic import utility function +def dynamic_import(module_name, class_name): + from importlib import import_module + module = import_module(module_name) + return getattr(module, class_name) + +class OauthTokenBase: + def get_oauth_token(self, domain: str, version: str, username: str, password: str): + Domain = dynamic_import("twilio.base.domain", "Domain") + Version = dynamic_import("twilio.base.version", "Version") + BearerTokenHTTPClient = dynamic_import("twilio.http.bearer_token_http_client", "BearerTokenHTTPClient") + OrgTokenManager = dynamic_import("twilio.http.orgs_token_manager", "OrgTokenManager") + Client = dynamic_import("twilio.rest", "Client") + try: + orgs_token_manager = TokenManagerInitializer.get_token_manager() + BearerTokenHTTPClient(orgs_token_manager).get_headers(Version(Domain(Client(username, password), domain), version)) + return orgs_token_manager.fetch_access_token(version=version) + except Exception: + orgs_token_manager = OrgTokenManager(grant_type='client_credentials', + client_id=username, + client_secret=password) + BearerTokenHTTPClient(orgs_token_manager).get_headers(Version(Domain(Client(username, password), domain), version)) + return orgs_token_manager.fetch_access_token(version=Version(Domain(Client(username, password), domain), version)) \ No newline at end of file diff --git a/twilio/base/version.py b/twilio/base/version.py index 64cc601faa..9177a18edf 100644 --- a/twilio/base/version.py +++ b/twilio/base/version.py @@ -39,6 +39,7 @@ def request( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Response: """ Make an HTTP request. @@ -53,6 +54,7 @@ def request( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth ) async def request_async( @@ -123,6 +125,7 @@ def fetch( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Any: """ Fetch a resource instance. @@ -136,6 +139,7 @@ def fetch( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth ) return self._parse_fetch(method, uri, response) From 2f329c74b99e28ad98a712483f3750ce7e368f79 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Wed, 17 Jul 2024 21:44:27 +0530 Subject: [PATCH 11/14] chore: oauth sdk implementation --- twilio/base/client_base.py | 14 +++++++++++--- twilio/base/domain.py | 2 ++ twilio/base/oauth_token_base.py | 7 +++---- twilio/base/version.py | 15 +++++++++++++++ twilio/http/bearer_token_http_client.py | 2 +- twilio/twilio_bearer_token_auth.py | 5 ++--- twilio/twilio_no_auth.py | 2 +- 7 files changed, 35 insertions(+), 12 deletions(-) diff --git a/twilio/base/client_base.py b/twilio/base/client_base.py index c2fc14af60..700e420ad8 100644 --- a/twilio/base/client_base.py +++ b/twilio/base/client_base.py @@ -93,7 +93,9 @@ def request( uri = self.get_hostname(uri) if is_oauth: OauthTokenBase = dynamic_import("twilio.base.oauth_token_base", "OauthTokenBase") - headers['Authorization'] = f'Bearer {OauthTokenBase().get_oauth_token(domain, "v1", self.username, self.password)}' + token = OauthTokenBase().get_oauth_token(domain, "v1", self.username, self.password) + headers['Authorization'] = f'Bearer {token}' + headers.get('Authorization') return self.http_client.request( method, @@ -116,6 +118,7 @@ async def request_async( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Response: """ Asynchronously makes a request to the Twilio API using the configured http client @@ -137,10 +140,15 @@ async def request_async( raise RuntimeError( "http_client must be asynchronous to support async API requests" ) - - auth = self.get_auth(auth) + if not is_oauth: + auth = self.get_auth(auth) headers = self.get_headers(method, headers) uri = self.get_hostname(uri) + if is_oauth: + OauthTokenBase = dynamic_import("twilio.base.oauth_token_base", "OauthTokenBase") + token = OauthTokenBase().get_oauth_token(domain, "v1", self.username, self.password) + headers['Authorization'] = f'Bearer {token}' + headers.get('Authorization') return await self.http_client.request( method, diff --git a/twilio/base/domain.py b/twilio/base/domain.py index 51375e55c5..02f4986858 100644 --- a/twilio/base/domain.py +++ b/twilio/base/domain.py @@ -70,6 +70,7 @@ async def request_async( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Response: """ Makes an asynchronous HTTP request to this domain. @@ -93,4 +94,5 @@ async def request_async( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth ) diff --git a/twilio/base/oauth_token_base.py b/twilio/base/oauth_token_base.py index 3576246a86..91e6d5191f 100644 --- a/twilio/base/oauth_token_base.py +++ b/twilio/base/oauth_token_base.py @@ -15,11 +15,10 @@ def get_oauth_token(self, domain: str, version: str, username: str, password: st Client = dynamic_import("twilio.rest", "Client") try: orgs_token_manager = TokenManagerInitializer.get_token_manager() - BearerTokenHTTPClient(orgs_token_manager).get_headers(Version(Domain(Client(username, password), domain), version)) - return orgs_token_manager.fetch_access_token(version=version) + return BearerTokenHTTPClient(orgs_token_manager).get_access_token(Version(Domain(Client(username, password), domain), version)) except Exception: orgs_token_manager = OrgTokenManager(grant_type='client_credentials', client_id=username, client_secret=password) - BearerTokenHTTPClient(orgs_token_manager).get_headers(Version(Domain(Client(username, password), domain), version)) - return orgs_token_manager.fetch_access_token(version=Version(Domain(Client(username, password), domain), version)) \ No newline at end of file + TokenManagerInitializer().set_token_manager(orgs_token_manager) + return BearerTokenHTTPClient(orgs_token_manager).get_access_token(Version(Domain(Client(username, password), domain), version)) \ No newline at end of file diff --git a/twilio/base/version.py b/twilio/base/version.py index 9177a18edf..e7ddaff6c9 100644 --- a/twilio/base/version.py +++ b/twilio/base/version.py @@ -67,6 +67,7 @@ async def request_async( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Response: """ Make an asynchronous HTTP request @@ -81,6 +82,7 @@ async def request_async( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth ) @classmethod @@ -154,6 +156,7 @@ async def fetch_async( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Any: """ Asynchronously fetch a resource instance. @@ -167,6 +170,7 @@ async def fetch_async( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth ) return self._parse_fetch(method, uri, response) @@ -190,6 +194,7 @@ def update( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Any: """ Update a resource instance. @@ -217,6 +222,7 @@ async def update_async( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Any: """ Asynchronously update a resource instance. @@ -230,6 +236,7 @@ async def update_async( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth ) return self._parse_update(method, uri, response) @@ -253,6 +260,7 @@ def delete( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> bool: """ Delete a resource. @@ -280,6 +288,7 @@ async def delete_async( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> bool: """ Asynchronously delete a resource. @@ -293,6 +302,7 @@ async def delete_async( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth ) return self._parse_delete(method, uri, response) @@ -351,6 +361,7 @@ async def page_async( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Response: """ Makes an asynchronous HTTP request. @@ -364,6 +375,7 @@ async def page_async( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth ) def stream( @@ -451,6 +463,7 @@ def create( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Any: """ Create a resource instance. @@ -478,6 +491,7 @@ async def create_async( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Any: """ Asynchronously create a resource instance. @@ -491,6 +505,7 @@ async def create_async( auth=auth, timeout=timeout, allow_redirects=allow_redirects, + is_oauth=is_oauth ) return self._parse_create(method, uri, response) diff --git a/twilio/http/bearer_token_http_client.py b/twilio/http/bearer_token_http_client.py index 784210c83d..eb5758db98 100644 --- a/twilio/http/bearer_token_http_client.py +++ b/twilio/http/bearer_token_http_client.py @@ -10,7 +10,7 @@ class BearerTokenHTTPClient: def __init__(self, orgs_token_manager: TokenManager): self.orgs_token_manager = orgs_token_manager - def get_headers(self, version: Version): + def get_access_token(self, version: Version): if TwilioBearerTokenAuth.get_access_token() is None or self.is_token_expired( TwilioBearerTokenAuth.get_access_token() ): diff --git a/twilio/twilio_bearer_token_auth.py b/twilio/twilio_bearer_token_auth.py index 90c8b9c9fb..ffc8814cdc 100644 --- a/twilio/twilio_bearer_token_auth.py +++ b/twilio/twilio_bearer_token_auth.py @@ -1,5 +1,4 @@ from threading import Lock -from concurrent.futures import ThreadPoolExecutor class BearerTokenTwilioRestClient: @@ -13,7 +12,7 @@ class TwilioBearerTokenAuth: user_agent_extensions = None region = None edge = None - + @classmethod def init(cls, access_token): with cls._lock: @@ -31,4 +30,4 @@ def get_access_token(cls): @classmethod def get_header_param(cls): with cls._lock: - return {"Authorization": "Bearer {token}".format(token=cls.access_token)} \ No newline at end of file + return {"Authorization": "Bearer {token}".format(token=cls.access_token)} diff --git a/twilio/twilio_no_auth.py b/twilio/twilio_no_auth.py index 92ab2c5094..9ea2fc9070 100644 --- a/twilio/twilio_no_auth.py +++ b/twilio/twilio_no_auth.py @@ -30,4 +30,4 @@ def build_oauth_rest_client(cls): builder.region(cls.region) builder.edge(cls.edge) - return builder.build() \ No newline at end of file + return builder.build() From 8f026a0c9637097e38b900ac225c8bd93a6a9e4a Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Wed, 17 Jul 2024 22:02:39 +0530 Subject: [PATCH 12/14] chore: oauth sdk implementation --- twilio/http/http_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/twilio/http/http_client.py b/twilio/http/http_client.py index 9d329c6aa7..c97c6e830d 100644 --- a/twilio/http/http_client.py +++ b/twilio/http/http_client.py @@ -57,6 +57,7 @@ def request( auth: Optional[Tuple[str, str]] = None, timeout: Optional[float] = None, allow_redirects: bool = False, + is_oauth: bool = False, ) -> Response: """ Make an HTTP Request with parameters provided. From 81ec68796afa7fc26ee257e9f80dde5b8e8f1796 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Mon, 22 Jul 2024 14:10:29 +0530 Subject: [PATCH 13/14] chore: oauth sdk implementation --- twilio/twilio_no_auth.py | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 twilio/twilio_no_auth.py diff --git a/twilio/twilio_no_auth.py b/twilio/twilio_no_auth.py deleted file mode 100644 index 9ea2fc9070..0000000000 --- a/twilio/twilio_no_auth.py +++ /dev/null @@ -1,33 +0,0 @@ -import os -from threading import Lock - - -class NoAuthTwilioRestClient: - pass - - -class TwilioNoAuth: - _lock = Lock() - no_auth_twilio_rest_client = None - user_agent_extensions = None - region = os.getenv("TWILIO_REGION") - edge = os.getenv("TWILIO_EDGE") - - @classmethod - def get_rest_client(cls): - with cls._lock: - if cls.no_auth_twilio_rest_client is None: - cls.no_auth_twilio_rest_client = cls.build_oauth_rest_client() - return cls.no_auth_twilio_rest_client - - @classmethod - def build_oauth_rest_client(cls): - builder = NoAuthTwilioRestClient.Builder() - - if cls.user_agent_extensions is not None: - builder.user_agent_extensions(cls.user_agent_extensions) - - builder.region(cls.region) - builder.edge(cls.edge) - - return builder.build() From db266dbfa11a5f9a5add33738c078e047d2aa1a8 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Tue, 23 Jul 2024 11:36:26 +0530 Subject: [PATCH 14/14] chore: oauth sdk implementation --- test_oauth_sdk.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test_oauth_sdk.py diff --git a/test_oauth_sdk.py b/test_oauth_sdk.py deleted file mode 100644 index e69de29bb2..0000000000