|
| 1 | +# This file was automatically generated. DO NOT EDIT. |
| 2 | +# If you have any remark or suggestion do not hesitate to open an issue. |
| 3 | + |
| 4 | +from typing import List, Optional |
| 5 | + |
| 6 | +from scaleway_core.api import API |
| 7 | +from scaleway_core.utils import ( |
| 8 | + random_name, |
| 9 | + validate_path_param, |
| 10 | + fetch_all_pages, |
| 11 | +) |
| 12 | +from .types import ( |
| 13 | + ListProjectsRequestOrderBy, |
| 14 | + CreateProjectRequest, |
| 15 | + ListProjectsResponse, |
| 16 | + Project, |
| 17 | + UpdateProjectRequest, |
| 18 | +) |
| 19 | +from .marshalling import ( |
| 20 | + unmarshal_Project, |
| 21 | + unmarshal_ListProjectsResponse, |
| 22 | + marshal_CreateProjectRequest, |
| 23 | + marshal_UpdateProjectRequest, |
| 24 | +) |
| 25 | + |
| 26 | + |
| 27 | +class AccountV2API(API): |
| 28 | + """ |
| 29 | + This API allows you to manage your Scaleway Projects. |
| 30 | + """ |
| 31 | + |
| 32 | + def create_project( |
| 33 | + self, |
| 34 | + *, |
| 35 | + name: Optional[str] = None, |
| 36 | + organization_id: Optional[str] = None, |
| 37 | + description: Optional[str] = None, |
| 38 | + ) -> Project: |
| 39 | + """ |
| 40 | + Create a new Project for an Organization. |
| 41 | + Deprecated in favor of Account API v3. |
| 42 | + Generate a new Project for an Organization, specifying its configuration including name and description. |
| 43 | + :param name: Name of the Project. |
| 44 | + :param organization_id: Organization ID of the Project. |
| 45 | + :param description: Description of the Project. |
| 46 | + :return: :class:`Project <Project>` |
| 47 | + :deprecated |
| 48 | +
|
| 49 | + Usage: |
| 50 | + :: |
| 51 | +
|
| 52 | + result = api.create_project() |
| 53 | + """ |
| 54 | + |
| 55 | + res = self._request( |
| 56 | + "POST", |
| 57 | + "/account/v2/projects", |
| 58 | + body=marshal_CreateProjectRequest( |
| 59 | + CreateProjectRequest( |
| 60 | + name=name or random_name(prefix="proj"), |
| 61 | + organization_id=organization_id, |
| 62 | + description=description, |
| 63 | + ), |
| 64 | + self.client, |
| 65 | + ), |
| 66 | + ) |
| 67 | + |
| 68 | + self._throw_on_error(res) |
| 69 | + return unmarshal_Project(res.json()) |
| 70 | + |
| 71 | + def list_projects( |
| 72 | + self, |
| 73 | + *, |
| 74 | + organization_id: Optional[str] = None, |
| 75 | + name: Optional[str] = None, |
| 76 | + page: Optional[int] = None, |
| 77 | + page_size: Optional[int] = None, |
| 78 | + order_by: Optional[ListProjectsRequestOrderBy] = None, |
| 79 | + project_ids: Optional[List[str]] = None, |
| 80 | + ) -> ListProjectsResponse: |
| 81 | + """ |
| 82 | + List all Projects of an Organization. |
| 83 | + Deprecated in favor of Account API v3. |
| 84 | + List all Projects of an Organization. The response will include the total number of Projects as well as their associated Organizations, names and IDs. Other information include the creation and update date of the Project. |
| 85 | + :param organization_id: Organization ID of the Project. |
| 86 | + :param name: Name of the Project. |
| 87 | + :param page: Page number for the returned Projects. |
| 88 | + :param page_size: Maximum number of Project per page. |
| 89 | + :param order_by: Sort order of the returned Projects. |
| 90 | + :param project_ids: Project IDs to filter for. The results will be limited to any Projects with an ID in this array. |
| 91 | + :return: :class:`ListProjectsResponse <ListProjectsResponse>` |
| 92 | + :deprecated |
| 93 | +
|
| 94 | + Usage: |
| 95 | + :: |
| 96 | +
|
| 97 | + result = api.list_projects() |
| 98 | + """ |
| 99 | + |
| 100 | + res = self._request( |
| 101 | + "GET", |
| 102 | + "/account/v2/projects", |
| 103 | + params={ |
| 104 | + "name": name, |
| 105 | + "order_by": order_by, |
| 106 | + "organization_id": organization_id |
| 107 | + or self.client.default_organization_id, |
| 108 | + "page": page, |
| 109 | + "page_size": page_size or self.client.default_page_size, |
| 110 | + "project_ids": project_ids, |
| 111 | + }, |
| 112 | + ) |
| 113 | + |
| 114 | + self._throw_on_error(res) |
| 115 | + return unmarshal_ListProjectsResponse(res.json()) |
| 116 | + |
| 117 | + def list_projects_all( |
| 118 | + self, |
| 119 | + *, |
| 120 | + organization_id: Optional[str] = None, |
| 121 | + name: Optional[str] = None, |
| 122 | + page: Optional[int] = None, |
| 123 | + page_size: Optional[int] = None, |
| 124 | + order_by: Optional[ListProjectsRequestOrderBy] = None, |
| 125 | + project_ids: Optional[List[str]] = None, |
| 126 | + ) -> List[Project]: |
| 127 | + """ |
| 128 | + List all Projects of an Organization. |
| 129 | + Deprecated in favor of Account API v3. |
| 130 | + List all Projects of an Organization. The response will include the total number of Projects as well as their associated Organizations, names and IDs. Other information include the creation and update date of the Project. |
| 131 | + :param organization_id: Organization ID of the Project. |
| 132 | + :param name: Name of the Project. |
| 133 | + :param page: Page number for the returned Projects. |
| 134 | + :param page_size: Maximum number of Project per page. |
| 135 | + :param order_by: Sort order of the returned Projects. |
| 136 | + :param project_ids: Project IDs to filter for. The results will be limited to any Projects with an ID in this array. |
| 137 | + :return: :class:`List[Project] <List[Project]>` |
| 138 | + :deprecated |
| 139 | +
|
| 140 | + Usage: |
| 141 | + :: |
| 142 | +
|
| 143 | + result = api.list_projects_all() |
| 144 | + """ |
| 145 | + |
| 146 | + return fetch_all_pages( |
| 147 | + type=ListProjectsResponse, |
| 148 | + key="projects", |
| 149 | + fetcher=self.list_projects, |
| 150 | + args={ |
| 151 | + "organization_id": organization_id, |
| 152 | + "name": name, |
| 153 | + "page": page, |
| 154 | + "page_size": page_size, |
| 155 | + "order_by": order_by, |
| 156 | + "project_ids": project_ids, |
| 157 | + }, |
| 158 | + ) |
| 159 | + |
| 160 | + def get_project( |
| 161 | + self, |
| 162 | + *, |
| 163 | + project_id: Optional[str] = None, |
| 164 | + ) -> Project: |
| 165 | + """ |
| 166 | + Get an existing Project. |
| 167 | + Deprecated in favor of Account API v3. |
| 168 | + Retrieve information about an existing Project, specified by its Project ID. Its full details, including ID, name and description, are returned in the response object. |
| 169 | + :param project_id: Project ID of the Project. |
| 170 | + :return: :class:`Project <Project>` |
| 171 | + :deprecated |
| 172 | +
|
| 173 | + Usage: |
| 174 | + :: |
| 175 | +
|
| 176 | + result = api.get_project() |
| 177 | + """ |
| 178 | + |
| 179 | + param_project_id = validate_path_param( |
| 180 | + "project_id", project_id or self.client.default_project_id |
| 181 | + ) |
| 182 | + |
| 183 | + res = self._request( |
| 184 | + "GET", |
| 185 | + f"/account/v2/projects/{param_project_id}", |
| 186 | + ) |
| 187 | + |
| 188 | + self._throw_on_error(res) |
| 189 | + return unmarshal_Project(res.json()) |
| 190 | + |
| 191 | + def delete_project( |
| 192 | + self, |
| 193 | + *, |
| 194 | + project_id: Optional[str] = None, |
| 195 | + ) -> None: |
| 196 | + """ |
| 197 | + Delete an existing Project. |
| 198 | + Deprecated in favor of Account API v3. |
| 199 | + Delete an existing Project, specified by its Project ID. The Project needs to be empty (meaning there are no resources left in it) to be deleted effectively. Note that deleting a Project is permanent, and cannot be undone. |
| 200 | + :param project_id: Project ID of the Project. |
| 201 | + :deprecated |
| 202 | +
|
| 203 | + Usage: |
| 204 | + :: |
| 205 | +
|
| 206 | + result = api.delete_project() |
| 207 | + """ |
| 208 | + |
| 209 | + param_project_id = validate_path_param( |
| 210 | + "project_id", project_id or self.client.default_project_id |
| 211 | + ) |
| 212 | + |
| 213 | + res = self._request( |
| 214 | + "DELETE", |
| 215 | + f"/account/v2/projects/{param_project_id}", |
| 216 | + ) |
| 217 | + |
| 218 | + self._throw_on_error(res) |
| 219 | + |
| 220 | + def update_project( |
| 221 | + self, |
| 222 | + *, |
| 223 | + project_id: Optional[str] = None, |
| 224 | + name: Optional[str] = None, |
| 225 | + description: Optional[str] = None, |
| 226 | + ) -> Project: |
| 227 | + """ |
| 228 | + Update Project. |
| 229 | + Deprecated in favor of Account API v3. |
| 230 | + Update the parameters of an existing Project, specified by its Project ID. These parameters include the name and description. |
| 231 | + :param project_id: Project ID of the Project. |
| 232 | + :param name: Name of the Project. |
| 233 | + :param description: Description of the Project. |
| 234 | + :return: :class:`Project <Project>` |
| 235 | + :deprecated |
| 236 | +
|
| 237 | + Usage: |
| 238 | + :: |
| 239 | +
|
| 240 | + result = api.update_project() |
| 241 | + """ |
| 242 | + |
| 243 | + param_project_id = validate_path_param( |
| 244 | + "project_id", project_id or self.client.default_project_id |
| 245 | + ) |
| 246 | + |
| 247 | + res = self._request( |
| 248 | + "PATCH", |
| 249 | + f"/account/v2/projects/{param_project_id}", |
| 250 | + body=marshal_UpdateProjectRequest( |
| 251 | + UpdateProjectRequest( |
| 252 | + project_id=project_id, |
| 253 | + name=name, |
| 254 | + description=description, |
| 255 | + ), |
| 256 | + self.client, |
| 257 | + ), |
| 258 | + ) |
| 259 | + |
| 260 | + self._throw_on_error(res) |
| 261 | + return unmarshal_Project(res.json()) |
0 commit comments