|
4 | 4 | from typing import List, Optional
|
5 | 5 |
|
6 | 6 | from scaleway_core.api import API
|
| 7 | +from scaleway_core.bridge import ( |
| 8 | + ScwFile, |
| 9 | + unmarshal_ScwFile, |
| 10 | +) |
7 | 11 | from scaleway_core.utils import (
|
8 | 12 | random_name,
|
9 | 13 | validate_path_param,
|
10 | 14 | fetch_all_pages_async,
|
11 | 15 | )
|
12 | 16 | from .types import (
|
| 17 | + ContractType, |
| 18 | + ListContractSignaturesRequestOrderBy, |
13 | 19 | ListProjectsRequestOrderBy,
|
| 20 | + CheckContractSignatureResponse, |
| 21 | + ContractApiCheckContractSignatureRequest, |
| 22 | + ContractApiCreateContractSignatureRequest, |
| 23 | + ContractSignature, |
| 24 | + ListContractSignaturesResponse, |
14 | 25 | ListProjectsResponse,
|
15 | 26 | Project,
|
16 | 27 | ProjectApiCreateProjectRequest,
|
17 | 28 | ProjectApiUpdateProjectRequest,
|
18 | 29 | )
|
19 | 30 | from .marshalling import (
|
| 31 | + unmarshal_ContractSignature, |
20 | 32 | unmarshal_Project,
|
| 33 | + unmarshal_CheckContractSignatureResponse, |
| 34 | + unmarshal_ListContractSignaturesResponse, |
21 | 35 | unmarshal_ListProjectsResponse,
|
| 36 | + marshal_ContractApiCheckContractSignatureRequest, |
| 37 | + marshal_ContractApiCreateContractSignatureRequest, |
22 | 38 | marshal_ProjectApiCreateProjectRequest,
|
23 | 39 | marshal_ProjectApiUpdateProjectRequest,
|
24 | 40 | )
|
| 41 | +from ...std.types import ( |
| 42 | + LanguageCode as StdLanguageCode, |
| 43 | +) |
| 44 | + |
| 45 | + |
| 46 | +class AccountV3ContractAPI(API): |
| 47 | + """ |
| 48 | + The Contract API allows you to manage contracts. |
| 49 | + """ |
| 50 | + |
| 51 | + async def download_contract_signature( |
| 52 | + self, |
| 53 | + *, |
| 54 | + contract_signature_id: str, |
| 55 | + locale: Optional[StdLanguageCode] = None, |
| 56 | + ) -> ScwFile: |
| 57 | + """ |
| 58 | + Download a contract content. |
| 59 | + :param contract_signature_id: The contract signature ID. |
| 60 | + :param locale: The locale requested for the content of the contract. |
| 61 | + :return: :class:`ScwFile <ScwFile>` |
| 62 | +
|
| 63 | + Usage: |
| 64 | + :: |
| 65 | +
|
| 66 | + result = await api.download_contract_signature( |
| 67 | + contract_signature_id="example", |
| 68 | + ) |
| 69 | + """ |
| 70 | + |
| 71 | + param_contract_signature_id = validate_path_param( |
| 72 | + "contract_signature_id", contract_signature_id |
| 73 | + ) |
| 74 | + |
| 75 | + res = self._request( |
| 76 | + "GET", |
| 77 | + f"/account/v3/contract-signatures/{param_contract_signature_id}/download", |
| 78 | + params={ |
| 79 | + "locale": locale, |
| 80 | + }, |
| 81 | + ) |
| 82 | + |
| 83 | + self._throw_on_error(res) |
| 84 | + return unmarshal_ScwFile(res.json()) |
| 85 | + |
| 86 | + async def create_contract_signature( |
| 87 | + self, |
| 88 | + *, |
| 89 | + contract_name: str, |
| 90 | + validated: bool, |
| 91 | + contract_type: Optional[ContractType] = None, |
| 92 | + organization_id: Optional[str] = None, |
| 93 | + ) -> ContractSignature: |
| 94 | + """ |
| 95 | + Create a signature for your Organization for the latest version of the requested contract. |
| 96 | + :param contract_name: The name of the contract. |
| 97 | + :param validated: Whether the contract is validated at creation. |
| 98 | + :param contract_type: The type of the contract. |
| 99 | + :param organization_id: ID of the Organization. |
| 100 | + :return: :class:`ContractSignature <ContractSignature>` |
| 101 | +
|
| 102 | + Usage: |
| 103 | + :: |
| 104 | +
|
| 105 | + result = await api.create_contract_signature( |
| 106 | + contract_name="example", |
| 107 | + validated=False, |
| 108 | + ) |
| 109 | + """ |
| 110 | + |
| 111 | + res = self._request( |
| 112 | + "POST", |
| 113 | + "/account/v3/contract-signatures", |
| 114 | + body=marshal_ContractApiCreateContractSignatureRequest( |
| 115 | + ContractApiCreateContractSignatureRequest( |
| 116 | + contract_name=contract_name, |
| 117 | + validated=validated, |
| 118 | + contract_type=contract_type, |
| 119 | + organization_id=organization_id, |
| 120 | + ), |
| 121 | + self.client, |
| 122 | + ), |
| 123 | + ) |
| 124 | + |
| 125 | + self._throw_on_error(res) |
| 126 | + return unmarshal_ContractSignature(res.json()) |
| 127 | + |
| 128 | + async def validate_contract_signature( |
| 129 | + self, |
| 130 | + *, |
| 131 | + contract_signature_id: str, |
| 132 | + ) -> ContractSignature: |
| 133 | + """ |
| 134 | + Sign a contract for your Organization. |
| 135 | + :param contract_signature_id: The contract linked to your Organization you want to sign. |
| 136 | + :return: :class:`ContractSignature <ContractSignature>` |
| 137 | +
|
| 138 | + Usage: |
| 139 | + :: |
| 140 | +
|
| 141 | + result = await api.validate_contract_signature( |
| 142 | + contract_signature_id="example", |
| 143 | + ) |
| 144 | + """ |
| 145 | + |
| 146 | + param_contract_signature_id = validate_path_param( |
| 147 | + "contract_signature_id", contract_signature_id |
| 148 | + ) |
| 149 | + |
| 150 | + res = self._request( |
| 151 | + "POST", |
| 152 | + f"/account/v3/contract-signatures/{param_contract_signature_id}/validate", |
| 153 | + body={}, |
| 154 | + ) |
| 155 | + |
| 156 | + self._throw_on_error(res) |
| 157 | + return unmarshal_ContractSignature(res.json()) |
| 158 | + |
| 159 | + async def check_contract_signature( |
| 160 | + self, |
| 161 | + *, |
| 162 | + contract_name: str, |
| 163 | + organization_id: Optional[str] = None, |
| 164 | + contract_type: Optional[ContractType] = None, |
| 165 | + ) -> CheckContractSignatureResponse: |
| 166 | + """ |
| 167 | + Check if a contract is signed for your Organization. |
| 168 | + :param contract_name: Filter on contract name. |
| 169 | + :param organization_id: ID of the Organization to check the contract signature for. |
| 170 | + :param contract_type: Filter on contract type. |
| 171 | + :return: :class:`CheckContractSignatureResponse <CheckContractSignatureResponse>` |
| 172 | +
|
| 173 | + Usage: |
| 174 | + :: |
| 175 | +
|
| 176 | + result = await api.check_contract_signature( |
| 177 | + contract_name="example", |
| 178 | + ) |
| 179 | + """ |
| 180 | + |
| 181 | + res = self._request( |
| 182 | + "POST", |
| 183 | + "/account/v3/contract-signatures/check", |
| 184 | + body=marshal_ContractApiCheckContractSignatureRequest( |
| 185 | + ContractApiCheckContractSignatureRequest( |
| 186 | + contract_name=contract_name, |
| 187 | + organization_id=organization_id, |
| 188 | + contract_type=contract_type, |
| 189 | + ), |
| 190 | + self.client, |
| 191 | + ), |
| 192 | + ) |
| 193 | + |
| 194 | + self._throw_on_error(res) |
| 195 | + return unmarshal_CheckContractSignatureResponse(res.json()) |
| 196 | + |
| 197 | + async def list_contract_signatures( |
| 198 | + self, |
| 199 | + *, |
| 200 | + page: Optional[int] = None, |
| 201 | + page_size: Optional[int] = None, |
| 202 | + order_by: Optional[ListContractSignaturesRequestOrderBy] = None, |
| 203 | + organization_id: Optional[str] = None, |
| 204 | + ) -> ListContractSignaturesResponse: |
| 205 | + """ |
| 206 | + List contract signatures for an Organization. |
| 207 | + :param page: The page number for the returned contracts. |
| 208 | + :param page_size: The maximum number of contracts per page. |
| 209 | + :param order_by: How the contracts are ordered in the response. |
| 210 | + :param organization_id: Filter on Organization ID. |
| 211 | + :return: :class:`ListContractSignaturesResponse <ListContractSignaturesResponse>` |
| 212 | +
|
| 213 | + Usage: |
| 214 | + :: |
| 215 | +
|
| 216 | + result = await api.list_contract_signatures() |
| 217 | + """ |
| 218 | + |
| 219 | + res = self._request( |
| 220 | + "GET", |
| 221 | + "/account/v3/contract-signatures", |
| 222 | + params={ |
| 223 | + "order_by": order_by, |
| 224 | + "organization_id": organization_id |
| 225 | + or self.client.default_organization_id, |
| 226 | + "page": page, |
| 227 | + "page_size": page_size or self.client.default_page_size, |
| 228 | + }, |
| 229 | + ) |
| 230 | + |
| 231 | + self._throw_on_error(res) |
| 232 | + return unmarshal_ListContractSignaturesResponse(res.json()) |
| 233 | + |
| 234 | + async def list_contract_signatures_all( |
| 235 | + self, |
| 236 | + *, |
| 237 | + page: Optional[int] = None, |
| 238 | + page_size: Optional[int] = None, |
| 239 | + order_by: Optional[ListContractSignaturesRequestOrderBy] = None, |
| 240 | + organization_id: Optional[str] = None, |
| 241 | + ) -> List[ContractSignature]: |
| 242 | + """ |
| 243 | + List contract signatures for an Organization. |
| 244 | + :param page: The page number for the returned contracts. |
| 245 | + :param page_size: The maximum number of contracts per page. |
| 246 | + :param order_by: How the contracts are ordered in the response. |
| 247 | + :param organization_id: Filter on Organization ID. |
| 248 | + :return: :class:`List[ContractSignature] <List[ContractSignature]>` |
| 249 | +
|
| 250 | + Usage: |
| 251 | + :: |
| 252 | +
|
| 253 | + result = await api.list_contract_signatures_all() |
| 254 | + """ |
| 255 | + |
| 256 | + return await fetch_all_pages_async( |
| 257 | + type=ListContractSignaturesResponse, |
| 258 | + key="contract_signatures", |
| 259 | + fetcher=self.list_contract_signatures, |
| 260 | + args={ |
| 261 | + "page": page, |
| 262 | + "page_size": page_size, |
| 263 | + "order_by": order_by, |
| 264 | + "organization_id": organization_id, |
| 265 | + }, |
| 266 | + ) |
25 | 267 |
|
26 | 268 |
|
27 | 269 | class AccountV3ProjectAPI(API):
|
|
0 commit comments