Skip to content

Commit 3d219e5

Browse files
authored
feat(account/v3): add project api (#259)
1 parent 9c4287f commit 3d219e5

File tree

8 files changed

+1008
-0
lines changed

8 files changed

+1008
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
from .types import ListProjectsRequestOrderBy
4+
from .types import ListProjectsResponse
5+
from .types import Project
6+
from .api import AccountProjectV3API
7+
8+
__all__ = [
9+
"ListProjectsRequestOrderBy",
10+
"ListProjectsResponse",
11+
"Project",
12+
"AccountProjectV3API",
13+
]
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
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+
fetch_all_pages_async,
9+
random_name,
10+
validate_path_param,
11+
)
12+
from .types import (
13+
ListProjectsRequestOrderBy,
14+
ListProjectsResponse,
15+
Project,
16+
ProjectApiCreateProjectRequest,
17+
ProjectApiUpdateProjectRequest,
18+
)
19+
from .marshalling import (
20+
marshal_ProjectApiCreateProjectRequest,
21+
marshal_ProjectApiUpdateProjectRequest,
22+
unmarshal_Project,
23+
unmarshal_ListProjectsResponse,
24+
)
25+
26+
27+
class AccountProjectV3API(API):
28+
"""
29+
Account API.
30+
31+
This API allows you to manage projects.
32+
"""
33+
34+
async def create_project(
35+
self,
36+
*,
37+
description: str,
38+
name: Optional[str] = None,
39+
organization_id: Optional[str] = None,
40+
) -> Project:
41+
"""
42+
Create a new Project for an Organization.
43+
Generate a new Project for an Organization, specifying its configuration including name and description.
44+
:param name: Name of the Project.
45+
:param organization_id: Organization ID of the Project.
46+
:param description: Description of the Project.
47+
:return: :class:`Project <Project>`
48+
49+
Usage:
50+
::
51+
52+
result = await api.create_project(description="example")
53+
"""
54+
55+
res = self._request(
56+
"POST",
57+
f"/account/v3/projects",
58+
body=marshal_ProjectApiCreateProjectRequest(
59+
ProjectApiCreateProjectRequest(
60+
description=description,
61+
name=name or random_name(prefix="proj"),
62+
organization_id=organization_id,
63+
),
64+
self.client,
65+
),
66+
)
67+
68+
self._throw_on_error(res)
69+
return unmarshal_Project(res.json())
70+
71+
async 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: ListProjectsRequestOrderBy = ListProjectsRequestOrderBy.CREATED_AT_ASC,
79+
project_ids: Optional[List[str]] = None,
80+
) -> ListProjectsResponse:
81+
"""
82+
List all Projects of an Organization.
83+
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 includes the creation and update date of the Project.
84+
:param organization_id: Organization ID of the Project.
85+
:param name: Name of the Project.
86+
:param page: Page number for the returned Projects.
87+
:param page_size: Maximum number of Project per page.
88+
:param order_by: Sort order of the returned Projects.
89+
:param project_ids: Project IDs to filter for. The results will be limited to any Projects with an ID in this array.
90+
:return: :class:`ListProjectsResponse <ListProjectsResponse>`
91+
92+
Usage:
93+
::
94+
95+
result = await api.list_projects()
96+
"""
97+
98+
res = self._request(
99+
"GET",
100+
f"/account/v3/projects",
101+
params={
102+
"name": name,
103+
"order_by": order_by,
104+
"organization_id": organization_id
105+
or self.client.default_organization_id,
106+
"page": page,
107+
"page_size": page_size or self.client.default_page_size,
108+
"project_ids": project_ids,
109+
},
110+
)
111+
112+
self._throw_on_error(res)
113+
return unmarshal_ListProjectsResponse(res.json())
114+
115+
async def list_projects_all(
116+
self,
117+
*,
118+
organization_id: Optional[str] = None,
119+
name: Optional[str] = None,
120+
page: Optional[int] = None,
121+
page_size: Optional[int] = None,
122+
order_by: Optional[ListProjectsRequestOrderBy] = None,
123+
project_ids: Optional[List[str]] = None,
124+
) -> List[Project]:
125+
"""
126+
List all Projects of an Organization.
127+
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 includes the creation and update date of the Project.
128+
:param organization_id: Organization ID of the Project.
129+
:param name: Name of the Project.
130+
:param page: Page number for the returned Projects.
131+
:param page_size: Maximum number of Project per page.
132+
:param order_by: Sort order of the returned Projects.
133+
:param project_ids: Project IDs to filter for. The results will be limited to any Projects with an ID in this array.
134+
:return: :class:`List[ListProjectsResponse] <List[ListProjectsResponse]>`
135+
136+
Usage:
137+
::
138+
139+
result = await api.list_projects_all()
140+
"""
141+
142+
return await fetch_all_pages_async(
143+
type=ListProjectsResponse,
144+
key="projects",
145+
fetcher=self.list_projects,
146+
args={
147+
"organization_id": organization_id,
148+
"name": name,
149+
"page": page,
150+
"page_size": page_size,
151+
"order_by": order_by,
152+
"project_ids": project_ids,
153+
},
154+
)
155+
156+
async def get_project(
157+
self,
158+
*,
159+
project_id: Optional[str] = None,
160+
) -> Project:
161+
"""
162+
Get an existing Project.
163+
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.
164+
:param project_id: Project ID of the Project.
165+
:return: :class:`Project <Project>`
166+
167+
Usage:
168+
::
169+
170+
result = await api.get_project()
171+
"""
172+
173+
param_project_id = validate_path_param(
174+
"project_id", project_id or self.client.default_project_id
175+
)
176+
177+
res = self._request(
178+
"GET",
179+
f"/account/v3/projects/{param_project_id}",
180+
)
181+
182+
self._throw_on_error(res)
183+
return unmarshal_Project(res.json())
184+
185+
async def delete_project(
186+
self,
187+
*,
188+
project_id: Optional[str] = None,
189+
) -> Optional[None]:
190+
"""
191+
Delete an existing Project.
192+
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.
193+
:param project_id: Project ID of the Project.
194+
195+
Usage:
196+
::
197+
198+
result = await api.delete_project()
199+
"""
200+
201+
param_project_id = validate_path_param(
202+
"project_id", project_id or self.client.default_project_id
203+
)
204+
205+
res = self._request(
206+
"DELETE",
207+
f"/account/v3/projects/{param_project_id}",
208+
)
209+
210+
self._throw_on_error(res)
211+
return None
212+
213+
async def update_project(
214+
self,
215+
*,
216+
project_id: Optional[str] = None,
217+
name: Optional[str] = None,
218+
description: Optional[str] = None,
219+
) -> Project:
220+
"""
221+
Update Project.
222+
Update the parameters of an existing Project, specified by its Project ID. These parameters include the name and description.
223+
:param project_id: Project ID of the Project.
224+
:param name: Name of the Project.
225+
:param description: Description of the Project.
226+
:return: :class:`Project <Project>`
227+
228+
Usage:
229+
::
230+
231+
result = await api.update_project()
232+
"""
233+
234+
param_project_id = validate_path_param(
235+
"project_id", project_id or self.client.default_project_id
236+
)
237+
238+
res = self._request(
239+
"PATCH",
240+
f"/account/v3/projects/{param_project_id}",
241+
body=marshal_ProjectApiUpdateProjectRequest(
242+
ProjectApiUpdateProjectRequest(
243+
project_id=project_id,
244+
name=name,
245+
description=description,
246+
),
247+
self.client,
248+
),
249+
)
250+
251+
self._throw_on_error(res)
252+
return unmarshal_Project(res.json())
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 Any, Dict
5+
6+
from scaleway_core.profile import ProfileDefaults
7+
from dateutil import parser
8+
from .types import (
9+
ListProjectsResponse,
10+
Project,
11+
ProjectApiCreateProjectRequest,
12+
ProjectApiUpdateProjectRequest,
13+
)
14+
15+
16+
def unmarshal_Project(data: Any) -> Project:
17+
if type(data) is not dict:
18+
raise TypeError(
19+
f"Unmarshalling the type 'Project' failed as data isn't a dictionary."
20+
)
21+
22+
args: Dict[str, Any] = {}
23+
24+
field = data.get("created_at", None)
25+
args["created_at"] = parser.isoparse(field) if type(field) is str else field
26+
27+
field = data.get("description", None)
28+
args["description"] = field
29+
30+
field = data.get("id", None)
31+
args["id"] = field
32+
33+
field = data.get("name", None)
34+
args["name"] = field
35+
36+
field = data.get("organization_id", None)
37+
args["organization_id"] = field
38+
39+
field = data.get("updated_at", None)
40+
args["updated_at"] = parser.isoparse(field) if type(field) is str else field
41+
42+
return Project(**args)
43+
44+
45+
def unmarshal_ListProjectsResponse(data: Any) -> ListProjectsResponse:
46+
if type(data) is not dict:
47+
raise TypeError(
48+
f"Unmarshalling the type 'ListProjectsResponse' failed as data isn't a dictionary."
49+
)
50+
51+
args: Dict[str, Any] = {}
52+
53+
field = data.get("projects", None)
54+
args["projects"] = (
55+
[unmarshal_Project(v) for v in field] if field is not None else None
56+
)
57+
58+
field = data.get("total_count", None)
59+
args["total_count"] = field
60+
61+
return ListProjectsResponse(**args)
62+
63+
64+
def marshal_ProjectApiCreateProjectRequest(
65+
request: ProjectApiCreateProjectRequest,
66+
defaults: ProfileDefaults,
67+
) -> Dict[str, Any]:
68+
return {
69+
"description": request.description,
70+
"name": request.name,
71+
"organization_id": request.organization_id or defaults.default_organization_id,
72+
}
73+
74+
75+
def marshal_ProjectApiUpdateProjectRequest(
76+
request: ProjectApiUpdateProjectRequest,
77+
defaults: ProfileDefaults,
78+
) -> Dict[str, Any]:
79+
return {
80+
"description": request.description,
81+
"name": request.name,
82+
}

0 commit comments

Comments
 (0)