-
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.
Signed-off-by: Jongmin Kim <[email protected]>
- Loading branch information
Showing
16 changed files
with
615 additions
and
20 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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from spaceone.core.pygrpc import BaseAPI | ||
from spaceone.api.identity.v2 import package_pb2, package_pb2_grpc | ||
from spaceone.identity.service.package_service import PackageService | ||
|
||
|
||
class Package(BaseAPI, package_pb2_grpc.PackageServicer): | ||
pb2 = package_pb2 | ||
pb2_grpc = package_pb2_grpc | ||
|
||
def create(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
package_svc = PackageService(metadata) | ||
response: dict = package_svc.create(params) | ||
return self.dict_to_message(response) | ||
|
||
def update(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
package_svc = PackageService(metadata) | ||
response: dict = package_svc.update(params) | ||
return self.dict_to_message(response) | ||
|
||
def delete(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
package_svc = PackageService(metadata) | ||
package_svc.delete(params) | ||
return self.empty() | ||
|
||
def set_default(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
package_svc = PackageService(metadata) | ||
response: dict = package_svc.set_default(params) | ||
return self.dict_to_message(response) | ||
|
||
def change_order(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
package_svc = PackageService(metadata) | ||
response: dict = package_svc.change_order(params) | ||
return self.dict_to_message(response) | ||
|
||
def get(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
package_svc = PackageService(metadata) | ||
response: dict = package_svc.get(params) | ||
return self.dict_to_message(response) | ||
|
||
def list(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
package_svc = PackageService(metadata) | ||
response: dict = package_svc.list(params) | ||
return self.dict_to_message(response) | ||
|
||
def stat(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
package_svc = PackageService(metadata) | ||
response: dict = package_svc.stat(params) | ||
return self.dict_to_message(response) |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import logging | ||
from typing import Tuple | ||
|
||
from mongoengine import QuerySet | ||
from spaceone.core.manager import BaseManager | ||
|
||
from spaceone.identity.model.package.database import Package | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class PackageManager(BaseManager): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.package_model = Package | ||
|
||
def create_package(self, params: dict) -> Package: | ||
def _rollback(vo: Package): | ||
_LOGGER.info( | ||
f"[create_package._rollback] Delete package: {vo.package_id} ({vo.name})" | ||
) | ||
vo.delete() | ||
|
||
package_vo = self.package_model.create(params) | ||
|
||
self.transaction.add_rollback(_rollback, package_vo) | ||
|
||
return package_vo | ||
|
||
def update_package_by_vo(self, params: dict, package_vo: Package) -> Package: | ||
def _rollback(old_data): | ||
_LOGGER.info( | ||
f'[update_package_by_vo._rollback] Revert Data: {old_data["package_id"]}' | ||
) | ||
package_vo.update(old_data) | ||
|
||
self.transaction.add_rollback(_rollback, package_vo.to_dict()) | ||
return package_vo.update(params) | ||
|
||
@staticmethod | ||
def delete_package_by_vo(package_vo: Package) -> None: | ||
package_vo.delete() | ||
|
||
def get_package(self, package_id: str, domain_id: str) -> Package: | ||
return self.package_model.get(package_id=package_id, domain_id=domain_id) | ||
|
||
def filter_packages(self, **conditions) -> QuerySet: | ||
return self.package_model.filter(**conditions) | ||
|
||
def list_packages(self, query: dict) -> Tuple[QuerySet, int]: | ||
return self.package_model.query(**query) | ||
|
||
def stat_package(self, query: dict) -> dict: | ||
return self.package_model.stat(**query) |
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
Empty file.
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,29 @@ | ||
from mongoengine import * | ||
from spaceone.core.model.mongo_model import MongoModel | ||
|
||
|
||
class Package(MongoModel): | ||
package_id = StringField(max_length=40, generate_id="p", unique=True) | ||
name = StringField(max_length=255, unique_with=["domain_id"]) | ||
description = StringField(max_length=255, default=None, null=True) | ||
order = IntField(required=True) | ||
is_default = BooleanField(default=False) | ||
tags = DictField(Default=None) | ||
domain_id = StringField(max_length=40) | ||
created_at = DateTimeField(auto_now_add=True) | ||
updated_at = DateTimeField(auto_now=True) | ||
|
||
meta = { | ||
"updatable_fields": ["name", "description", "order", "is_default", "tags"], | ||
"minimal_fields": [ | ||
"package_id", | ||
"name", | ||
"is_default", | ||
"domain_id", | ||
], | ||
"ordering": ["order"], | ||
"indexes": [ | ||
"name", | ||
"domain_id", | ||
], | ||
} |
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,61 @@ | ||
from typing import Union, List | ||
from pydantic import BaseModel | ||
|
||
__all__ = [ | ||
"PackageCreateRequest", | ||
"PackageUpdateRequest", | ||
"PackageDeleteRequest", | ||
"PackageSetDefaultRequest", | ||
"PackageChangeOrderRequest", | ||
"PackageGetRequest", | ||
"PackageSearchQueryRequest", | ||
"PackageStatQueryRequest", | ||
] | ||
|
||
|
||
class PackageCreateRequest(BaseModel): | ||
name: str | ||
description: Union[str, None] = None | ||
tags: Union[dict, None] = None | ||
domain_id: str | ||
|
||
|
||
class PackageUpdateRequest(BaseModel): | ||
package_id: str | ||
name: Union[str, None] = None | ||
description: Union[str, None] = None | ||
tags: Union[dict, None] = None | ||
domain_id: str | ||
|
||
|
||
class PackageDeleteRequest(BaseModel): | ||
package_id: str | ||
domain_id: str | ||
|
||
|
||
class PackageSetDefaultRequest(BaseModel): | ||
package_id: str | ||
domain_id: str | ||
|
||
|
||
class PackageChangeOrderRequest(BaseModel): | ||
package_id: str | ||
order: int | ||
domain_id: str | ||
|
||
|
||
class PackageGetRequest(BaseModel): | ||
package_id: str | ||
domain_id: str | ||
|
||
|
||
class PackageSearchQueryRequest(BaseModel): | ||
query: Union[dict, None] = None | ||
package_id: Union[str, None] = None | ||
name: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class PackageStatQueryRequest(BaseModel): | ||
query: dict | ||
domain_id: str |
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,29 @@ | ||
from datetime import datetime | ||
from typing import Union, List | ||
from pydantic import BaseModel | ||
from spaceone.core import utils | ||
|
||
__all__ = ["PackageResponse", "PackagesResponse"] | ||
|
||
|
||
class PackageResponse(BaseModel): | ||
package_id: Union[str, None] = None | ||
name: Union[str, None] = None | ||
description: Union[str, None] = None | ||
order: Union[int, None] = None | ||
is_default: Union[bool, None] = None | ||
tags: Union[dict, None] = None | ||
domain_id: Union[str, None] = None | ||
created_at: Union[datetime, None] = None | ||
updated_at: Union[datetime, None] = None | ||
|
||
def dict(self, *args, **kwargs): | ||
data = super().dict(*args, **kwargs) | ||
data["created_at"] = utils.datetime_to_iso8601(data["created_at"]) | ||
data["updated_at"] = utils.datetime_to_iso8601(data["updated_at"]) | ||
return data | ||
|
||
|
||
class PackagesResponse(BaseModel): | ||
results: List[PackageResponse] | ||
total_count: int |
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
Oops, something went wrong.