-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from stat-kwon/master
refactor: change Dashboard resource to PublicDashboard and PrivateDashboard
- Loading branch information
Showing
23 changed files
with
1,196 additions
and
396 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 |
---|---|---|
@@ -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 * |
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,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
52
src/spaceone/dashboard/info/private_dashboard_version_info.py
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,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, | ||
) |
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
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
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 |
---|---|---|
@@ -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
119
src/spaceone/dashboard/interface/grpc/private_dashboard.py
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,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) | ||
) |
Oops, something went wrong.