Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,5 @@ cython_debug/
*.log
.logs

node_modules
node_modules
.DS_Store
20 changes: 11 additions & 9 deletions naas_python/domains/space/SpaceDomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
ISpaceAdaptor,
Space,
SpaceListResponse,
Container,
)

from typing import List
import json

class SpaceDomain(ISpaceDomain):
def __init__(self, adaptor: ISpaceAdaptor):
Expand All @@ -17,11 +19,13 @@ def add(self):
def create(
self,
name: str,
containers: list,
containers: List[Container],
domain: str,
) -> Space:
) -> Space:
response = self.adaptor.create_space(
name=name, containers=containers, domain=domain
name=name,
containers=containers,
domain=domain
)
return Space(**response)

Expand All @@ -32,11 +36,9 @@ def get(self, name: str):
def delete(self, name: str):
return self.adaptor.delete_space(name=name)

def list(self, page_size: int, page_number: int) -> SpaceListResponse:
response = self.adaptor.list_spaces(
page_size=page_size, page_number=page_number
)
return SpaceListResponse(spaces=response)
def list(self) -> SpaceListResponse:
response = self.adaptor.list_spaces()
return SpaceListResponse(spaces=response)

def update(self, name: str, containers: list, domain: str) -> Space:
response = self.adaptor.update_space(
Expand Down
24 changes: 1 addition & 23 deletions naas_python/domains/space/SpaceSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,7 @@ def add(self):


class ISpaceInvoker(metaclass=ABCMeta):
@abstractmethod
def create(self, **kwargs):
raise NotImplementedError

@abstractmethod
def update(self, **kwargs):
raise NotImplementedError

@abstractmethod
def get(self, **kwargs):
raise NotImplementedError

@abstractmethod
def list(self, **kwargs):
raise NotImplementedError

@abstractmethod
def delete(self, **kwargs):
raise NotImplementedError

@abstractmethod
def add(self, **kwargs):
raise NotImplementedError
pass


# Exceptions
Expand Down
31 changes: 13 additions & 18 deletions naas_python/domains/space/adaptors/primary/SDKSpaceAdaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ISpaceInvoker,
SpaceConflictError,
)
from naas_python.utils.cicd import Pipeline
# from naas_python.utils.cicd import Pipeline


class SDKSpaceAdaptor(ISpaceInvoker):
Expand All @@ -19,36 +19,31 @@ def __init__(self, domain: ISpaceDomain):
def create(
self,
name: str,
namespace: str,
image: str,
user_id: str,
env: dict,
resources: dict,
containers: list,
domain: str,
):
"""Create a space with the given name"""
space = self.domain.create(
name=name,
namespace=namespace,
image=image,
user_id=user_id,
env=env,
resources=resources,
containers=containers,
domain=domain
)
return space

def get(self, name: str, namespace: str):
def get(self, name: str):
"""Get a space with the given name"""
space = self.domain.get(name=name, namespace=namespace)
space = self.domain.get(name=name)
return space

def list(self, user_id: str, namespace: str):
def list(self):
"""List all spaces for the current user"""
space_list = self.domain.list(user_id=user_id, namespace=namespace)
return space_list
space_list = self.domain.list()
return space_list

def delete(self, name: str, namespace: str):
def delete(self, name: str):
"""Delete a space by name"""
self.domain.delete(name=name, namespace=namespace)
self.domain.delete(name=name)


def update(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def create(
name: str = typer.Option(..., "--name", "-n", help="Name of the space"),
image: str = typer.Option(..., "--image", help="Image of the space"),
domain: str = typer.Option("", "--domain", "-d", help="Domain of the space"),
# namespace: str = typer.Option("", "--namespace", "-d", help="Namespace of the space"),
env: str = typer.Option(
{},
"--env",
Expand Down Expand Up @@ -124,6 +125,7 @@ def create(
space = self.domain.create(
name=name,
domain=domain,
# domain=domain,
containers=[
{
"name": name,
Expand Down Expand Up @@ -249,8 +251,8 @@ def delete(

def list(
self,
page_size: int = typer.Option(0, help="Size of each page of results"),
page_number: int = typer.Option(0, help="Target page number of results"),
# page_size: int = typer.Option(0, help="Size of each page of results"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why removing this ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, this is not yet implemented in API

# page_number: int = typer.Option(0, help="Target page number of results"),
rich_preview: bool = typer.Option(
False,
"--rich-preview",
Expand All @@ -259,7 +261,8 @@ def list(
),
):
"""List all spaces for the current user"""
space_list = self.domain.list(page_size=page_size, page_number=page_number)
# space_list = self.domain.list(page_size=page_size, page_number=page_number)
space_list = self.domain.list()

data = []
headers = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def get_space_by_name(self, name):
return self._handle_get_response(api_response)

@BaseAPIAdaptor.service_status_decorator
def list_spaces(self, page_size, page_number) -> dict:
_url = f"{self.host}/space/?page_size={page_size}&page_number={page_number}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, this is not yet implemented in API

def list_spaces(self) -> dict:

_url = f"{self.host}/space/"

logging.debug(f"list request url: {_url}")

Expand Down
17 changes: 11 additions & 6 deletions naas_python/domains/storage/StorageDomain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .models.Storage import Storage

from typing import Mapping
import json

from naas_python.domains.storage.StorageSchema import (
IStorageDomain,
Expand Down Expand Up @@ -75,7 +76,8 @@ def create_credentials(self,
storage_name: Storage.__fields__['name'],
) -> dict:
credentials = self.adaptor.generate_credentials(workspace_id, storage_name)
self.__get_storage_provider_adaptor(workspace_id=workspace_id, storage_name=storage_name).save_naas_credentials(workspace_id, storage_name, credentials)
json_credentials = json.dumps(credentials)
self.__get_storage_provider_adaptor(workspace_id=workspace_id, storage_name=storage_name).save_naas_credentials(workspace_id, storage_name, json_credentials)
return credentials

############### BOTO ###############
Expand Down Expand Up @@ -110,9 +112,10 @@ def post_object(self,

storage_provider : IStorageProviderAdaptor = self.storage_provider_adaptors[storage_provider_id]

if not storage_provider.valid_naas_credentials(workspace_id, storage_name):
if storage_provider.valid_naas_credentials(workspace_id, storage_name) is False:
credentials = self.adaptor.generate_credentials(workspace_id, storage_name)
storage_provider.save_naas_credentials(workspace_id, storage_name, credentials)
json_credentials = json.dumps(credentials)
storage_provider.save_naas_credentials(workspace_id, storage_name, json_credentials)

response = storage_provider.post_workspace_storage_object(workspace_id=workspace_id, storage_name=storage_name, src_file=src_file, dst_file=dst_file)
return response
Expand All @@ -130,10 +133,12 @@ def get_object(self,
raise StorageProviderNotFound(f'Provider "{storage_provider_id}" is not implemented or not loaded.')

storage_provider : IStorageProviderAdaptor = self.storage_provider_adaptors[storage_provider_id]

if not storage_provider.valid_naas_credentials(workspace_id, storage_name):
if storage_provider.valid_naas_credentials(workspace_id, storage_name) is False:
credentials = self.adaptor.generate_credentials(workspace_id, storage_name)
storage_provider.save_naas_credentials(workspace_id, storage_name, credentials)
json_credentials = json.dumps(credentials)
storage_provider.save_naas_credentials(workspace_id, storage_name, json_credentials)


response = storage_provider.get_workspace_storage_object(workspace_id=workspace_id, storage_name=storage_name, src_file=src_file, dst_file=dst_file)
return response
6 changes: 5 additions & 1 deletion naas_python/domains/storage/StorageSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ def get_workspace_storage_object(self,
raise NotImplementedError

@abstractmethod
def save_naas_credentials(self, workspace_id:str, storage_name:str, credentials:dict)-> str:
def save_naas_credentials(self, workspace_id:str, storage_name:str, credentials:str)-> None:
raise NotImplementedError

@abstractmethod
def valid_naas_credentials(self, workspace_id:str, storage_name:str)-> bool:
raise NotImplementedError

# Domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def post_workspace_storage_object(self,
storage_name: str = "",
src_file: str = "",
dst_file: str = "",
) -> bytes:
) -> dict:
if os.path.isfile(src_file):
response = self.domain.post_workspace_storage_object(
workspace_id=workspace_id,
Expand Down
Loading