|
| 1 | +r""" |
| 2 | + This code was generated by |
| 3 | + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ |
| 4 | + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ |
| 5 | + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ |
| 6 | +
|
| 7 | + Twilio - Iam |
| 8 | + This is the public Twilio REST API. |
| 9 | +
|
| 10 | + NOTE: This class is auto generated by OpenAPI Generator. |
| 11 | + https://openapi-generator.tech |
| 12 | + Do not edit the class manually. |
| 13 | +""" |
| 14 | + |
| 15 | +from datetime import datetime |
| 16 | +from typing import Any, Dict, Optional, Union |
| 17 | +from twilio.base import deserialize, serialize, values |
| 18 | + |
| 19 | +from twilio.base.instance_resource import InstanceResource |
| 20 | +from twilio.base.list_resource import ListResource |
| 21 | +from twilio.base.version import Version |
| 22 | + |
| 23 | + |
| 24 | +class KeyInstance(InstanceResource): |
| 25 | + |
| 26 | + class Keytype(object): |
| 27 | + RESTRICTED = "restricted" |
| 28 | + |
| 29 | + """ |
| 30 | + :ivar sid: The unique string that that we created to identify the NewKey resource. You will use this as the basic-auth `user` when authenticating to the API. |
| 31 | + :ivar friendly_name: The string that you assigned to describe the resource. |
| 32 | + :ivar date_created: The date and time in GMT that the API Key was created specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. |
| 33 | + :ivar date_updated: The date and time in GMT that the new API Key was last updated specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. |
| 34 | + :ivar secret: The secret your application uses to sign Access Tokens and to authenticate to the REST API (you will use this as the basic-auth `password`). **Note that for security reasons, this field is ONLY returned when the API Key is first created.** |
| 35 | + :ivar policy: Collection of allow assertions. |
| 36 | + """ |
| 37 | + |
| 38 | + def __init__(self, version: Version, payload: Dict[str, Any]): |
| 39 | + super().__init__(version) |
| 40 | + |
| 41 | + self.sid: Optional[str] = payload.get("sid") |
| 42 | + self.friendly_name: Optional[str] = payload.get("friendly_name") |
| 43 | + self.date_created: Optional[datetime] = deserialize.rfc2822_datetime( |
| 44 | + payload.get("date_created") |
| 45 | + ) |
| 46 | + self.date_updated: Optional[datetime] = deserialize.rfc2822_datetime( |
| 47 | + payload.get("date_updated") |
| 48 | + ) |
| 49 | + self.secret: Optional[str] = payload.get("secret") |
| 50 | + self.policy: Optional[Dict[str, object]] = payload.get("policy") |
| 51 | + |
| 52 | + def __repr__(self) -> str: |
| 53 | + """ |
| 54 | + Provide a friendly representation |
| 55 | +
|
| 56 | + :returns: Machine friendly representation |
| 57 | + """ |
| 58 | + |
| 59 | + return "<Twilio.Iam.V1.KeyInstance>" |
| 60 | + |
| 61 | + |
| 62 | +class KeyList(ListResource): |
| 63 | + |
| 64 | + def __init__(self, version: Version): |
| 65 | + """ |
| 66 | + Initialize the KeyList |
| 67 | +
|
| 68 | + :param version: Version that contains the resource |
| 69 | +
|
| 70 | + """ |
| 71 | + super().__init__(version) |
| 72 | + |
| 73 | + self._uri = "/Keys" |
| 74 | + |
| 75 | + def create( |
| 76 | + self, |
| 77 | + account_sid: str, |
| 78 | + friendly_name: Union[str, object] = values.unset, |
| 79 | + key_type: Union["KeyInstance.Keytype", object] = values.unset, |
| 80 | + policy: Union[object, object] = values.unset, |
| 81 | + ) -> KeyInstance: |
| 82 | + """ |
| 83 | + Create the KeyInstance |
| 84 | +
|
| 85 | + :param account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Payments resource. |
| 86 | + :param friendly_name: A descriptive string that you create to describe the resource. It can be up to 64 characters long. |
| 87 | + :param key_type: |
| 88 | + :param policy: The \\\\`Policy\\\\` object is a collection that specifies the allowed Twilio permissions for the restricted key. For more information on the permissions available with restricted API keys, refer to the [Twilio documentation](https://www.twilio.com/docs/iam/api-keys/restricted-api-keys#permissions-available-with-restricted-api-keys). |
| 89 | +
|
| 90 | + :returns: The created KeyInstance |
| 91 | + """ |
| 92 | + |
| 93 | + data = values.of( |
| 94 | + { |
| 95 | + "AccountSid": account_sid, |
| 96 | + "FriendlyName": friendly_name, |
| 97 | + "KeyType": key_type, |
| 98 | + "Policy": serialize.object(policy), |
| 99 | + } |
| 100 | + ) |
| 101 | + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) |
| 102 | + |
| 103 | + headers["Content-Type"] = "application/x-www-form-urlencoded" |
| 104 | + |
| 105 | + headers["Accept"] = "application/json" |
| 106 | + |
| 107 | + payload = self._version.create( |
| 108 | + method="POST", uri=self._uri, data=data, headers=headers |
| 109 | + ) |
| 110 | + |
| 111 | + return KeyInstance(self._version, payload) |
| 112 | + |
| 113 | + async def create_async( |
| 114 | + self, |
| 115 | + account_sid: str, |
| 116 | + friendly_name: Union[str, object] = values.unset, |
| 117 | + key_type: Union["KeyInstance.Keytype", object] = values.unset, |
| 118 | + policy: Union[object, object] = values.unset, |
| 119 | + ) -> KeyInstance: |
| 120 | + """ |
| 121 | + Asynchronously create the KeyInstance |
| 122 | +
|
| 123 | + :param account_sid: The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Payments resource. |
| 124 | + :param friendly_name: A descriptive string that you create to describe the resource. It can be up to 64 characters long. |
| 125 | + :param key_type: |
| 126 | + :param policy: The \\\\`Policy\\\\` object is a collection that specifies the allowed Twilio permissions for the restricted key. For more information on the permissions available with restricted API keys, refer to the [Twilio documentation](https://www.twilio.com/docs/iam/api-keys/restricted-api-keys#permissions-available-with-restricted-api-keys). |
| 127 | +
|
| 128 | + :returns: The created KeyInstance |
| 129 | + """ |
| 130 | + |
| 131 | + data = values.of( |
| 132 | + { |
| 133 | + "AccountSid": account_sid, |
| 134 | + "FriendlyName": friendly_name, |
| 135 | + "KeyType": key_type, |
| 136 | + "Policy": serialize.object(policy), |
| 137 | + } |
| 138 | + ) |
| 139 | + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) |
| 140 | + |
| 141 | + headers["Content-Type"] = "application/x-www-form-urlencoded" |
| 142 | + |
| 143 | + headers["Accept"] = "application/json" |
| 144 | + |
| 145 | + payload = await self._version.create_async( |
| 146 | + method="POST", uri=self._uri, data=data, headers=headers |
| 147 | + ) |
| 148 | + |
| 149 | + return KeyInstance(self._version, payload) |
| 150 | + |
| 151 | + def __repr__(self) -> str: |
| 152 | + """ |
| 153 | + Provide a friendly representation |
| 154 | +
|
| 155 | + :returns: Machine friendly representation |
| 156 | + """ |
| 157 | + return "<Twilio.Iam.V1.KeyList>" |
0 commit comments