|
| 1 | +from typing import TypedDict, Optional, List, Dict, Any, Literal |
| 2 | + |
| 3 | +from method.resource import MethodResponse, Resource, RequestOpts |
| 4 | +from method.configuration import Configuration |
| 5 | + |
| 6 | + |
| 7 | +TeamStatusesLiterals = Literal[ |
| 8 | + 'active', |
| 9 | + 'verified', |
| 10 | + 'disabled', |
| 11 | + 'pending_disablement' |
| 12 | +] |
| 13 | + |
| 14 | + |
| 15 | +class TeamProduct(TypedDict): |
| 16 | + type: str |
| 17 | + enabled: bool |
| 18 | + |
| 19 | + |
| 20 | +class TeamKey(TypedDict): |
| 21 | + id: str |
| 22 | + type: Literal['secret', 'public'] |
| 23 | + deleted: bool |
| 24 | + created_at: str |
| 25 | + updated_at: str |
| 26 | + last_used_at: Optional[str] |
| 27 | + |
| 28 | + |
| 29 | +class Team(TypedDict): |
| 30 | + id: str |
| 31 | + parent_id: Optional[str] |
| 32 | + name: str |
| 33 | + legal_name: str |
| 34 | + logo: Optional[str] |
| 35 | + api_version: str |
| 36 | + status: TeamStatusesLiterals |
| 37 | + products: List[TeamProduct] |
| 38 | + keys: List[TeamKey] |
| 39 | + created_at: str |
| 40 | + updated_at: str |
| 41 | + |
| 42 | + |
| 43 | +class TeamCreateOpts(TypedDict): |
| 44 | + name: str |
| 45 | + |
| 46 | + |
| 47 | +class TeamEncryptionKeyOpts(TypedDict): |
| 48 | + key: str |
| 49 | + |
| 50 | + |
| 51 | +class MLEPublicKey(TypedDict): |
| 52 | + id: str |
| 53 | + jwk: Dict[str, Any] |
| 54 | + created_at: str |
| 55 | + updated_at: str |
| 56 | + |
| 57 | + |
| 58 | +class MLEPublicKeyCreateOpts(TypedDict): |
| 59 | + jwk: Dict[str, Any] |
| 60 | + |
| 61 | + |
| 62 | +class TeamPublicKeysResource(Resource): |
| 63 | + def __init__(self, config: Configuration): |
| 64 | + super(TeamPublicKeysResource, self).__init__(config.add_path('mle/public_keys')) |
| 65 | + |
| 66 | + def list(self) -> MethodResponse[List[MLEPublicKey]]: |
| 67 | + return super(TeamPublicKeysResource, self)._list() |
| 68 | + |
| 69 | + def retrieve(self, _id: str) -> MethodResponse[MLEPublicKey]: |
| 70 | + return super(TeamPublicKeysResource, self)._get_with_id(_id) |
| 71 | + |
| 72 | + def create(self, opts: MLEPublicKeyCreateOpts, request_opts: Optional[RequestOpts] = None) -> MethodResponse[MLEPublicKey]: |
| 73 | + return super(TeamPublicKeysResource, self)._create(opts, request_opts=request_opts) |
| 74 | + |
| 75 | + def delete(self, _id: str) -> MethodResponse[MLEPublicKey]: |
| 76 | + return super(TeamPublicKeysResource, self)._delete(_id) |
| 77 | + |
| 78 | + |
| 79 | +class TeamResource(Resource): |
| 80 | + public_keys: TeamPublicKeysResource |
| 81 | + |
| 82 | + def __init__(self, config: Configuration): |
| 83 | + _config = config.add_path('teams') |
| 84 | + super(TeamResource, self).__init__(_config) |
| 85 | + self.public_keys = TeamPublicKeysResource(_config) |
| 86 | + |
| 87 | + def retrieve(self) -> MethodResponse[Team]: |
| 88 | + return super(TeamResource, self)._get() |
| 89 | + |
| 90 | + def create(self, opts: TeamCreateOpts, request_opts: Optional[RequestOpts] = None) -> MethodResponse[Team]: |
| 91 | + return super(TeamResource, self)._create(opts, request_opts=request_opts) |
| 92 | + |
| 93 | + def update_encryption_key(self, opts: TeamEncryptionKeyOpts) -> MethodResponse[Team]: |
| 94 | + return super(TeamResource, self)._create_with_sub_path('default_encryption_key', opts) |
0 commit comments