-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(account/v3): add project api (#259)
- Loading branch information
1 parent
9c4287f
commit 3d219e5
Showing
8 changed files
with
1,008 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# This file was automatically generated. DO NOT EDIT. | ||
# If you have any remark or suggestion do not hesitate to open an issue. | ||
from .types import ListProjectsRequestOrderBy | ||
from .types import ListProjectsResponse | ||
from .types import Project | ||
from .api import AccountProjectV3API | ||
|
||
__all__ = [ | ||
"ListProjectsRequestOrderBy", | ||
"ListProjectsResponse", | ||
"Project", | ||
"AccountProjectV3API", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
# This file was automatically generated. DO NOT EDIT. | ||
# If you have any remark or suggestion do not hesitate to open an issue. | ||
|
||
from typing import List, Optional | ||
|
||
from scaleway_core.api import API | ||
from scaleway_core.utils import ( | ||
fetch_all_pages_async, | ||
random_name, | ||
validate_path_param, | ||
) | ||
from .types import ( | ||
ListProjectsRequestOrderBy, | ||
ListProjectsResponse, | ||
Project, | ||
ProjectApiCreateProjectRequest, | ||
ProjectApiUpdateProjectRequest, | ||
) | ||
from .marshalling import ( | ||
marshal_ProjectApiCreateProjectRequest, | ||
marshal_ProjectApiUpdateProjectRequest, | ||
unmarshal_Project, | ||
unmarshal_ListProjectsResponse, | ||
) | ||
|
||
|
||
class AccountProjectV3API(API): | ||
""" | ||
Account API. | ||
This API allows you to manage projects. | ||
""" | ||
|
||
async def create_project( | ||
self, | ||
*, | ||
description: str, | ||
name: Optional[str] = None, | ||
organization_id: Optional[str] = None, | ||
) -> Project: | ||
""" | ||
Create a new Project for an Organization. | ||
Generate a new Project for an Organization, specifying its configuration including name and description. | ||
:param name: Name of the Project. | ||
:param organization_id: Organization ID of the Project. | ||
:param description: Description of the Project. | ||
:return: :class:`Project <Project>` | ||
Usage: | ||
:: | ||
result = await api.create_project(description="example") | ||
""" | ||
|
||
res = self._request( | ||
"POST", | ||
f"/account/v3/projects", | ||
body=marshal_ProjectApiCreateProjectRequest( | ||
ProjectApiCreateProjectRequest( | ||
description=description, | ||
name=name or random_name(prefix="proj"), | ||
organization_id=organization_id, | ||
), | ||
self.client, | ||
), | ||
) | ||
|
||
self._throw_on_error(res) | ||
return unmarshal_Project(res.json()) | ||
|
||
async def list_projects( | ||
self, | ||
*, | ||
organization_id: Optional[str] = None, | ||
name: Optional[str] = None, | ||
page: Optional[int] = None, | ||
page_size: Optional[int] = None, | ||
order_by: ListProjectsRequestOrderBy = ListProjectsRequestOrderBy.CREATED_AT_ASC, | ||
project_ids: Optional[List[str]] = None, | ||
) -> ListProjectsResponse: | ||
""" | ||
List all Projects of an Organization. | ||
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. | ||
:param organization_id: Organization ID of the Project. | ||
:param name: Name of the Project. | ||
:param page: Page number for the returned Projects. | ||
:param page_size: Maximum number of Project per page. | ||
:param order_by: Sort order of the returned Projects. | ||
:param project_ids: Project IDs to filter for. The results will be limited to any Projects with an ID in this array. | ||
:return: :class:`ListProjectsResponse <ListProjectsResponse>` | ||
Usage: | ||
:: | ||
result = await api.list_projects() | ||
""" | ||
|
||
res = self._request( | ||
"GET", | ||
f"/account/v3/projects", | ||
params={ | ||
"name": name, | ||
"order_by": order_by, | ||
"organization_id": organization_id | ||
or self.client.default_organization_id, | ||
"page": page, | ||
"page_size": page_size or self.client.default_page_size, | ||
"project_ids": project_ids, | ||
}, | ||
) | ||
|
||
self._throw_on_error(res) | ||
return unmarshal_ListProjectsResponse(res.json()) | ||
|
||
async def list_projects_all( | ||
self, | ||
*, | ||
organization_id: Optional[str] = None, | ||
name: Optional[str] = None, | ||
page: Optional[int] = None, | ||
page_size: Optional[int] = None, | ||
order_by: Optional[ListProjectsRequestOrderBy] = None, | ||
project_ids: Optional[List[str]] = None, | ||
) -> List[Project]: | ||
""" | ||
List all Projects of an Organization. | ||
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. | ||
:param organization_id: Organization ID of the Project. | ||
:param name: Name of the Project. | ||
:param page: Page number for the returned Projects. | ||
:param page_size: Maximum number of Project per page. | ||
:param order_by: Sort order of the returned Projects. | ||
:param project_ids: Project IDs to filter for. The results will be limited to any Projects with an ID in this array. | ||
:return: :class:`List[ListProjectsResponse] <List[ListProjectsResponse]>` | ||
Usage: | ||
:: | ||
result = await api.list_projects_all() | ||
""" | ||
|
||
return await fetch_all_pages_async( | ||
type=ListProjectsResponse, | ||
key="projects", | ||
fetcher=self.list_projects, | ||
args={ | ||
"organization_id": organization_id, | ||
"name": name, | ||
"page": page, | ||
"page_size": page_size, | ||
"order_by": order_by, | ||
"project_ids": project_ids, | ||
}, | ||
) | ||
|
||
async def get_project( | ||
self, | ||
*, | ||
project_id: Optional[str] = None, | ||
) -> Project: | ||
""" | ||
Get an existing Project. | ||
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. | ||
:param project_id: Project ID of the Project. | ||
:return: :class:`Project <Project>` | ||
Usage: | ||
:: | ||
result = await api.get_project() | ||
""" | ||
|
||
param_project_id = validate_path_param( | ||
"project_id", project_id or self.client.default_project_id | ||
) | ||
|
||
res = self._request( | ||
"GET", | ||
f"/account/v3/projects/{param_project_id}", | ||
) | ||
|
||
self._throw_on_error(res) | ||
return unmarshal_Project(res.json()) | ||
|
||
async def delete_project( | ||
self, | ||
*, | ||
project_id: Optional[str] = None, | ||
) -> Optional[None]: | ||
""" | ||
Delete an existing Project. | ||
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. | ||
:param project_id: Project ID of the Project. | ||
Usage: | ||
:: | ||
result = await api.delete_project() | ||
""" | ||
|
||
param_project_id = validate_path_param( | ||
"project_id", project_id or self.client.default_project_id | ||
) | ||
|
||
res = self._request( | ||
"DELETE", | ||
f"/account/v3/projects/{param_project_id}", | ||
) | ||
|
||
self._throw_on_error(res) | ||
return None | ||
|
||
async def update_project( | ||
self, | ||
*, | ||
project_id: Optional[str] = None, | ||
name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
) -> Project: | ||
""" | ||
Update Project. | ||
Update the parameters of an existing Project, specified by its Project ID. These parameters include the name and description. | ||
:param project_id: Project ID of the Project. | ||
:param name: Name of the Project. | ||
:param description: Description of the Project. | ||
:return: :class:`Project <Project>` | ||
Usage: | ||
:: | ||
result = await api.update_project() | ||
""" | ||
|
||
param_project_id = validate_path_param( | ||
"project_id", project_id or self.client.default_project_id | ||
) | ||
|
||
res = self._request( | ||
"PATCH", | ||
f"/account/v3/projects/{param_project_id}", | ||
body=marshal_ProjectApiUpdateProjectRequest( | ||
ProjectApiUpdateProjectRequest( | ||
project_id=project_id, | ||
name=name, | ||
description=description, | ||
), | ||
self.client, | ||
), | ||
) | ||
|
||
self._throw_on_error(res) | ||
return unmarshal_Project(res.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# This file was automatically generated. DO NOT EDIT. | ||
# If you have any remark or suggestion do not hesitate to open an issue. | ||
|
||
from typing import Any, Dict | ||
|
||
from scaleway_core.profile import ProfileDefaults | ||
from dateutil import parser | ||
from .types import ( | ||
ListProjectsResponse, | ||
Project, | ||
ProjectApiCreateProjectRequest, | ||
ProjectApiUpdateProjectRequest, | ||
) | ||
|
||
|
||
def unmarshal_Project(data: Any) -> Project: | ||
if type(data) is not dict: | ||
raise TypeError( | ||
f"Unmarshalling the type 'Project' failed as data isn't a dictionary." | ||
) | ||
|
||
args: Dict[str, Any] = {} | ||
|
||
field = data.get("created_at", None) | ||
args["created_at"] = parser.isoparse(field) if type(field) is str else field | ||
|
||
field = data.get("description", None) | ||
args["description"] = field | ||
|
||
field = data.get("id", None) | ||
args["id"] = field | ||
|
||
field = data.get("name", None) | ||
args["name"] = field | ||
|
||
field = data.get("organization_id", None) | ||
args["organization_id"] = field | ||
|
||
field = data.get("updated_at", None) | ||
args["updated_at"] = parser.isoparse(field) if type(field) is str else field | ||
|
||
return Project(**args) | ||
|
||
|
||
def unmarshal_ListProjectsResponse(data: Any) -> ListProjectsResponse: | ||
if type(data) is not dict: | ||
raise TypeError( | ||
f"Unmarshalling the type 'ListProjectsResponse' failed as data isn't a dictionary." | ||
) | ||
|
||
args: Dict[str, Any] = {} | ||
|
||
field = data.get("projects", None) | ||
args["projects"] = ( | ||
[unmarshal_Project(v) for v in field] if field is not None else None | ||
) | ||
|
||
field = data.get("total_count", None) | ||
args["total_count"] = field | ||
|
||
return ListProjectsResponse(**args) | ||
|
||
|
||
def marshal_ProjectApiCreateProjectRequest( | ||
request: ProjectApiCreateProjectRequest, | ||
defaults: ProfileDefaults, | ||
) -> Dict[str, Any]: | ||
return { | ||
"description": request.description, | ||
"name": request.name, | ||
"organization_id": request.organization_id or defaults.default_organization_id, | ||
} | ||
|
||
|
||
def marshal_ProjectApiUpdateProjectRequest( | ||
request: ProjectApiUpdateProjectRequest, | ||
defaults: ProfileDefaults, | ||
) -> Dict[str, Any]: | ||
return { | ||
"description": request.description, | ||
"name": request.name, | ||
} |
Oops, something went wrong.