| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# File generated from our OpenAPI spec |
| 3 |
from stripe._createable_api_resource import CreateableAPIResource |
| 4 |
from stripe._list_object import ListObject |
| 5 |
from stripe._listable_api_resource import ListableAPIResource |
| 6 |
from stripe._stripe_object import StripeObject |
| 7 |
from typing import ClassVar, Optional, cast |
| 8 |
from typing_extensions import Literal, Unpack, TYPE_CHECKING |
| 9 |
|
| 10 |
if TYPE_CHECKING: |
| 11 |
from stripe.params.apps._secret_create_params import SecretCreateParams |
| 12 |
from stripe.params.apps._secret_delete_where_params import ( |
| 13 |
SecretDeleteWhereParams, |
| 14 |
) |
| 15 |
from stripe.params.apps._secret_find_params import SecretFindParams |
| 16 |
from stripe.params.apps._secret_list_params import SecretListParams |
| 17 |
|
| 18 |
|
| 19 |
class Secret(CreateableAPIResource["Secret"], ListableAPIResource["Secret"]): |
| 20 |
""" |
| 21 |
Secret Store is an API that allows Stripe Apps developers to securely persist secrets for use by UI Extensions and app backends. |
| 22 |
|
| 23 |
The primary resource in Secret Store is a `secret`. Other apps can't view secrets created by an app. Additionally, secrets are scoped to provide further permission control. |
| 24 |
|
| 25 |
All Dashboard users and the app backend share `account` scoped secrets. Use the `account` scope for secrets that don't change per-user, like a third-party API key. |
| 26 |
|
| 27 |
A `user` scoped secret is accessible by the app backend and one specific Dashboard user. Use the `user` scope for per-user secrets like per-user OAuth tokens, where different users might have different permissions. |
| 28 |
|
| 29 |
Related guide: [Store data between page reloads](https://docs.stripe.com/stripe-apps/store-auth-data-custom-objects) |
| 30 |
""" |
| 31 |
|
| 32 |
OBJECT_NAME: ClassVar[Literal["apps.secret"]] = "apps.secret" |
| 33 |
|
| 34 |
class Scope(StripeObject): |
| 35 |
type: Literal["account", "user"] |
| 36 |
""" |
| 37 |
The secret scope type. |
| 38 |
""" |
| 39 |
user: Optional[str] |
| 40 |
""" |
| 41 |
The user ID, if type is set to "user" |
| 42 |
""" |
| 43 |
|
| 44 |
created: int |
| 45 |
""" |
| 46 |
Time at which the object was created. Measured in seconds since the Unix epoch. |
| 47 |
""" |
| 48 |
deleted: Optional[bool] |
| 49 |
""" |
| 50 |
If true, indicates that this secret has been deleted |
| 51 |
""" |
| 52 |
expires_at: Optional[int] |
| 53 |
""" |
| 54 |
The Unix timestamp for the expiry time of the secret, after which the secret deletes. |
| 55 |
""" |
| 56 |
id: str |
| 57 |
""" |
| 58 |
Unique identifier for the object. |
| 59 |
""" |
| 60 |
livemode: bool |
| 61 |
""" |
| 62 |
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. |
| 63 |
""" |
| 64 |
name: str |
| 65 |
""" |
| 66 |
A name for the secret that's unique within the scope. |
| 67 |
""" |
| 68 |
object: Literal["apps.secret"] |
| 69 |
""" |
| 70 |
String representing the object's type. Objects of the same type share the same value. |
| 71 |
""" |
| 72 |
payload: Optional[str] |
| 73 |
""" |
| 74 |
The plaintext secret value to be stored. |
| 75 |
""" |
| 76 |
scope: Scope |
| 77 |
|
| 78 |
@classmethod |
| 79 |
def create(cls, **params: Unpack["SecretCreateParams"]) -> "Secret": |
| 80 |
""" |
| 81 |
Create or replace a secret in the secret store. |
| 82 |
""" |
| 83 |
return cast( |
| 84 |
"Secret", |
| 85 |
cls._static_request( |
| 86 |
"post", |
| 87 |
cls.class_url(), |
| 88 |
params=params, |
| 89 |
), |
| 90 |
) |
| 91 |
|
| 92 |
@classmethod |
| 93 |
async def create_async( |
| 94 |
cls, **params: Unpack["SecretCreateParams"] |
| 95 |
) -> "Secret": |
| 96 |
""" |
| 97 |
Create or replace a secret in the secret store. |
| 98 |
""" |
| 99 |
return cast( |
| 100 |
"Secret", |
| 101 |
await cls._static_request_async( |
| 102 |
"post", |
| 103 |
cls.class_url(), |
| 104 |
params=params, |
| 105 |
), |
| 106 |
) |
| 107 |
|
| 108 |
@classmethod |
| 109 |
def delete_where( |
| 110 |
cls, **params: Unpack["SecretDeleteWhereParams"] |
| 111 |
) -> "Secret": |
| 112 |
""" |
| 113 |
Deletes a secret from the secret store by name and scope. |
| 114 |
""" |
| 115 |
return cast( |
| 116 |
"Secret", |
| 117 |
cls._static_request( |
| 118 |
"post", |
| 119 |
"/v1/apps/secrets/delete", |
| 120 |
params=params, |
| 121 |
), |
| 122 |
) |
| 123 |
|
| 124 |
@classmethod |
| 125 |
async def delete_where_async( |
| 126 |
cls, **params: Unpack["SecretDeleteWhereParams"] |
| 127 |
) -> "Secret": |
| 128 |
""" |
| 129 |
Deletes a secret from the secret store by name and scope. |
| 130 |
""" |
| 131 |
return cast( |
| 132 |
"Secret", |
| 133 |
await cls._static_request_async( |
| 134 |
"post", |
| 135 |
"/v1/apps/secrets/delete", |
| 136 |
params=params, |
| 137 |
), |
| 138 |
) |
| 139 |
|
| 140 |
@classmethod |
| 141 |
def find(cls, **params: Unpack["SecretFindParams"]) -> "Secret": |
| 142 |
""" |
| 143 |
Finds a secret in the secret store by name and scope. |
| 144 |
""" |
| 145 |
return cast( |
| 146 |
"Secret", |
| 147 |
cls._static_request( |
| 148 |
"get", |
| 149 |
"/v1/apps/secrets/find", |
| 150 |
params=params, |
| 151 |
), |
| 152 |
) |
| 153 |
|
| 154 |
@classmethod |
| 155 |
async def find_async( |
| 156 |
cls, **params: Unpack["SecretFindParams"] |
| 157 |
) -> "Secret": |
| 158 |
""" |
| 159 |
Finds a secret in the secret store by name and scope. |
| 160 |
""" |
| 161 |
return cast( |
| 162 |
"Secret", |
| 163 |
await cls._static_request_async( |
| 164 |
"get", |
| 165 |
"/v1/apps/secrets/find", |
| 166 |
params=params, |
| 167 |
), |
| 168 |
) |
| 169 |
|
| 170 |
@classmethod |
| 171 |
def list( |
| 172 |
cls, **params: Unpack["SecretListParams"] |
| 173 |
) -> ListObject["Secret"]: |
| 174 |
""" |
| 175 |
List all secrets stored on the given scope. |
| 176 |
""" |
| 177 |
result = cls._static_request( |
| 178 |
"get", |
| 179 |
cls.class_url(), |
| 180 |
params=params, |
| 181 |
) |
| 182 |
if not isinstance(result, ListObject): |
| 183 |
raise TypeError( |
| 184 |
"Expected list object from API, got %s" |
| 185 |
% (type(result).__name__) |
| 186 |
) |
| 187 |
|
| 188 |
return result |
| 189 |
|
| 190 |
@classmethod |
| 191 |
async def list_async( |
| 192 |
cls, **params: Unpack["SecretListParams"] |
| 193 |
) -> ListObject["Secret"]: |
| 194 |
""" |
| 195 |
List all secrets stored on the given scope. |
| 196 |
""" |
| 197 |
result = await cls._static_request_async( |
| 198 |
"get", |
| 199 |
cls.class_url(), |
| 200 |
params=params, |
| 201 |
) |
| 202 |
if not isinstance(result, ListObject): |
| 203 |
raise TypeError( |
| 204 |
"Expected list object from API, got %s" |
| 205 |
% (type(result).__name__) |
| 206 |
) |
| 207 |
|
| 208 |
return result |
| 209 |
|
| 210 |
_inner_class_types = {"scope": Scope} |