Skip to content

Commit

Permalink
Merge pull request #35 from stat-kwon/master
Browse files Browse the repository at this point in the history
refactor: change Dashboard resource to PublicDashboard and PrivateDashboard
  • Loading branch information
stat-kwon authored Dec 19, 2023
2 parents e45fea4 + 72e6f88 commit 4536503
Show file tree
Hide file tree
Showing 23 changed files with 1,196 additions and 396 deletions.
6 changes: 4 additions & 2 deletions src/spaceone/dashboard/info/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from spaceone.dashboard.info.dashboard_info import *
from spaceone.dashboard.info.dashboard_version_info import *
from spaceone.dashboard.info.public_dashboard_info import *
from spaceone.dashboard.info.private_dashboard_info import *
from spaceone.dashboard.info.public_dashboard_version_info import *
from spaceone.dashboard.info.private_dashboard_version_info import *
from spaceone.dashboard.info.common_info import *
44 changes: 44 additions & 0 deletions src/spaceone/dashboard/info/private_dashboard_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import functools
from spaceone.api.dashboard.v1 import private_dashboard_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.dashboard.model.private_dashboard_model import PrivateDashboard

__all__ = ["PrivateDashboardInfo", "PrivateDashboardsInfo"]


def PrivateDashboardInfo(dashboard_vo: PrivateDashboard, minimal=False):
info = {
"private_dashboard_id": dashboard_vo.private_dashboard_id,
"name": dashboard_vo.name,
"version": dashboard_vo.version,
"labels": change_list_value_type(dashboard_vo.labels),
"user_id": dashboard_vo.user_id,
"domain_id": dashboard_vo.domain_id,
}

if not minimal:
info.update(
{
"layouts": change_list_value_type(dashboard_vo.layouts)
if dashboard_vo.layouts
else None,
"variables": change_struct_type(dashboard_vo.variables),
"settings": change_struct_type(dashboard_vo.settings),
"variables_schema": change_struct_type(dashboard_vo.variables_schema),
"tags": change_struct_type(dashboard_vo.tags),
"created_at": utils.datetime_to_iso8601(dashboard_vo.created_at),
"updated_at": utils.datetime_to_iso8601(dashboard_vo.updated_at),
}
)

return private_dashboard_pb2.PrivateDashboardInfo(**info)


def PrivateDashboardsInfo(dashboard_vos, total_count, **kwargs):
return private_dashboard_pb2.PrivateDashboardsInfo(
results=list(
map(functools.partial(PrivateDashboardInfo, **kwargs), dashboard_vos)
),
total_count=total_count,
)
52 changes: 52 additions & 0 deletions src/spaceone/dashboard/info/private_dashboard_version_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import functools
from spaceone.api.dashboard.v1 import private_dashboard_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.dashboard.model import PrivateDashboardVersion

__all__ = ["PrivateDashboardVersionInfo", "PrivateDashboardVersionsInfo"]


def PrivateDashboardVersionInfo(
dashboard_version_vo: PrivateDashboardVersion, minimal=False, latest_version=None
):
info = {
"private_dashboard_id": dashboard_version_vo.private_dashboard_id,
"version": dashboard_version_vo.version,
"created_at": utils.datetime_to_iso8601(dashboard_version_vo.created_at),
"domain_id": dashboard_version_vo.domain_id,
}

if latest_version:
if latest_version == dashboard_version_vo.version:
info.update({"latest": True})
else:
info.update({"latest": False})

if not minimal:
info.update(
{
"layouts": change_list_value_type(dashboard_version_vo.layouts)
if dashboard_version_vo.layouts
else None,
"variables": change_struct_type(dashboard_version_vo.variables),
"settings": change_struct_type(dashboard_version_vo.settings),
"variables_schema": change_struct_type(
dashboard_version_vo.variables_schema
),
}
)

return private_dashboard_pb2.PrivateDashboardVersionInfo(**info)


def PrivateDashboardVersionsInfo(dashboard_version_vos, total_count, **kwargs):
return private_dashboard_pb2.PrivateDashboardVersionsInfo(
results=list(
map(
functools.partial(PrivateDashboardVersionInfo, **kwargs),
dashboard_version_vos,
)
),
total_count=total_count,
)
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import functools
from spaceone.api.dashboard.v1 import dashboard_pb2
from spaceone.api.dashboard.v1 import public_dashboard_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.dashboard.model.dashboard_model import Dashboard
from spaceone.dashboard.model.public_dashboard_model import PublicDashboard

__all__ = ["DashboardInfo", "DashboardsInfo"]
__all__ = ["PublicDashboardInfo", "PublicDashboardsInfo"]


def DashboardInfo(dashboard_vo: Dashboard, minimal=False):
def PublicDashboardInfo(dashboard_vo: PublicDashboard, minimal=False):
info = {
"dashboard_id": dashboard_vo.dashboard_id,
"public_dashboard_id": dashboard_vo.public_dashboard_id,
"name": dashboard_vo.name,
"dashboard_type": dashboard_vo.dashboard_type,
"version": dashboard_vo.version,
"labels": change_list_value_type(dashboard_vo.labels),
"resource_group": dashboard_vo.resource_group,
"user_id": dashboard_vo.user_id,
"project_id": dashboard_vo.project_id,
"workspace_id": dashboard_vo.workspace_id,
"domain_id": dashboard_vo.domain_id,
Expand All @@ -36,11 +34,13 @@ def DashboardInfo(dashboard_vo: Dashboard, minimal=False):
}
)

return dashboard_pb2.DashboardInfo(**info)
return public_dashboard_pb2.PublicDashboardInfo(**info)


def DashboardsInfo(dashboard_vos, total_count, **kwargs):
return dashboard_pb2.DashboardsInfo(
results=list(map(functools.partial(DashboardInfo, **kwargs), dashboard_vos)),
def PublicDashboardsInfo(dashboard_vos, total_count, **kwargs):
return public_dashboard_pb2.PublicDashboardsInfo(
results=list(
map(functools.partial(PublicDashboardInfo, **kwargs), dashboard_vos)
),
total_count=total_count,
)
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import functools
from spaceone.api.dashboard.v1 import dashboard_pb2
from spaceone.api.dashboard.v1 import public_dashboard_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.dashboard.model import DashboardVersion
from spaceone.dashboard.model import PublicDashboardVersion

__all__ = ["DashboardVersionInfo", "DashboardVersionsInfo"]
__all__ = ["PublicDashboardVersionInfo", "PublicDashboardVersionsInfo"]


def DashboardVersionInfo(
dashboard_version_vo: DashboardVersion, minimal=False, latest_version=None
def PublicDashboardVersionInfo(
dashboard_version_vo: PublicDashboardVersion, minimal=False, latest_version=None
):
info = {
"dashboard_id": dashboard_version_vo.dashboard_id,
"public_dashboard_id": dashboard_version_vo.public_dashboard_id,
"version": dashboard_version_vo.version,
"created_at": utils.datetime_to_iso8601(dashboard_version_vo.created_at),
"domain_id": dashboard_version_vo.domain_id,
Expand All @@ -37,14 +37,14 @@ def DashboardVersionInfo(
}
)

return dashboard_pb2.DashboardVersionInfo(**info)
return public_dashboard_pb2.PublicDashboardVersionInfo(**info)


def DashboardVersionsInfo(dashboard_version_vos, total_count, **kwargs):
return dashboard_pb2.DashboardVersionsInfo(
def PublicDashboardVersionsInfo(dashboard_version_vos, total_count, **kwargs):
return public_dashboard_pb2.PublicDashboardVersionsInfo(
results=list(
map(
functools.partial(DashboardVersionInfo, **kwargs),
functools.partial(PublicDashboardVersionInfo, **kwargs),
dashboard_version_vos,
)
),
Expand Down
6 changes: 4 additions & 2 deletions src/spaceone/dashboard/interface/grpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from spaceone.core.pygrpc.server import GRPCServer
from spaceone.dashboard.interface.grpc.dashboard import Dashboard
from spaceone.dashboard.interface.grpc.public_dashboard import PublicDashboard
from spaceone.dashboard.interface.grpc.private_dashboard import PrivateDashboard

__all__ = ["app"]

app = GRPCServer()
app.add_service(Dashboard)
app.add_service(PublicDashboard)
app.add_service(PrivateDashboard)
119 changes: 119 additions & 0 deletions src/spaceone/dashboard/interface/grpc/private_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from spaceone.api.dashboard.v1 import private_dashboard_pb2, private_dashboard_pb2_grpc
from spaceone.core.pygrpc import BaseAPI


class PrivateDashboard(BaseAPI, private_dashboard_pb2_grpc.PrivateDashboardServicer):
pb2 = private_dashboard_pb2
pb2_grpc = private_dashboard_pb2_grpc

def create(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
return self.locator.get_info(
"PrivateDashboardInfo", dashboard_service.create(params)
)

def update(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
return self.locator.get_info(
"PrivateDashboardInfo", dashboard_service.update(params)
)

def delete(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
dashboard_service.delete(params)
return self.locator.get_info("EmptyInfo")

def get(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
return self.locator.get_info(
"PrivateDashboardInfo", dashboard_service.get(params)
)

def delete_version(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
dashboard_service.delete_version(params)
return self.locator.get_info("EmptyInfo")

def revert_version(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
return self.locator.get_info(
"PrivateDashboardInfo", dashboard_service.revert_version(params)
)

def get_version(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
return self.locator.get_info(
"PrivateDashboardVersionInfo",
dashboard_service.get_version(params),
)

def list_versions(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
(
private_dashboard_version_vos,
total_count,
private_dashboard_version,
) = dashboard_service.list_versions(params)
return self.locator.get_info(
"PrivateDashboardVersionsInfo",
private_dashboard_version_vos,
total_count,
minimal=self.get_minimal(params),
latest_version=private_dashboard_version,
)

def list(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
private_dashboard_vos, total_count = dashboard_service.list(params)
return self.locator.get_info(
"PrivateDashboardsInfo",
private_dashboard_vos,
total_count,
minimal=self.get_minimal(params),
)

def stat(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
"PrivateDashboardService", metadata
) as dashboard_service:
return self.locator.get_info(
"StatisticsInfo", dashboard_service.stat(params)
)
Loading

0 comments on commit 4536503

Please sign in to comment.