-
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.
Merge pull request #108 from ImMin5/master
Add App apis except generate_api_key
- Loading branch information
Showing
14 changed files
with
663 additions
and
33 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,62 @@ | ||
from spaceone.core.pygrpc import BaseAPI | ||
from spaceone.api.identity.v2 import app_pb2, app_pb2_grpc | ||
from spaceone.identity.service.app_service import AppService | ||
|
||
|
||
class App(BaseAPI, app_pb2_grpc.AppServicer): | ||
pb2 = app_pb2 | ||
pb2_grpc = app_pb2_grpc | ||
|
||
def create(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
app_svc = AppService(metadata) | ||
response: dict = app_svc.create(params) | ||
return self.dict_to_message(response) | ||
|
||
def update(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
app_svc = AppService(metadata) | ||
response: dict = app_svc.update(params) | ||
return self.dict_to_message(response) | ||
|
||
def generate_api_key(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
app_svc = AppService(metadata) | ||
response: dict = app_svc.generate_api_key(params) | ||
return self.dict_to_message(response) | ||
|
||
def enable(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
app_svc = AppService(metadata) | ||
response: dict = app_svc.enable(params) | ||
return self.dict_to_message(response) | ||
|
||
def disable(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
app_svc = AppService(metadata) | ||
response: dict = app_svc.disable(params) | ||
return self.dict_to_message(response) | ||
|
||
def delete(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
app_svc = AppService(metadata) | ||
app_svc.delete(params) | ||
return self.empty() | ||
|
||
def get(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
app_svc = AppService(metadata) | ||
response: dict = app_svc.get(params) | ||
return self.dict_to_message(response) | ||
|
||
def list(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
app_svc = AppService(metadata) | ||
response: dict = app_svc.list(params) | ||
return self.dict_to_message(response) | ||
|
||
def stat(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
app_svc = AppService(metadata) | ||
response: dict = app_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,79 @@ | ||
import logging | ||
from typing import Tuple, Union | ||
|
||
from spaceone.core.cache import cacheable | ||
from spaceone.core.manager import BaseManager | ||
from spaceone.identity.model.app.database import App | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class AppManager(BaseManager): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.app_model = App | ||
|
||
def create_app(self, params: dict) -> App: | ||
def _rollback(vo: App): | ||
_LOGGER.info(f"[create_app._rollback] Delete app: {vo.name} ({vo.app_id})") | ||
vo.delete() | ||
|
||
app_vo = self.app_model.create(params) | ||
self.transaction.add_rollback(_rollback, app_vo) | ||
|
||
return app_vo | ||
|
||
def update_app_by_vo(self, params: dict, app_vo: App) -> App: | ||
def _rollback(old_data): | ||
_LOGGER.info( | ||
f'[update_app._rollback] Revert Data: {old_data["name"]} ({old_data["app_id"]})' | ||
) | ||
app_vo.update(old_data) | ||
|
||
self.transaction.add_rollback(_rollback, app_vo.to_dict()) | ||
|
||
return app_vo.update(params) | ||
|
||
def enable_app(self, app_vo: App) -> App: | ||
def _rollback(old_data): | ||
_LOGGER.info(f"[enable_app._rollback] Revert Data: {old_data}") | ||
app_vo.update(old_data) | ||
|
||
if app_vo.state != "ENABLED": | ||
self.transaction.add_rollback(_rollback, app_vo.to_dict()) | ||
app_vo.update({"state": "ENABLED"}) | ||
|
||
return app_vo | ||
|
||
def disable_app(self, app_vo: App) -> App: | ||
def _rollback(old_data): | ||
_LOGGER.info(f"[disable_app._rollback] Revert Data: {old_data}") | ||
app_vo.update(old_data) | ||
|
||
if app_vo.state != "DISABLED": | ||
self.transaction.add_rollback(_rollback, app_vo.to_dict()) | ||
app_vo.update({"state": "DISABLED"}) | ||
|
||
return app_vo | ||
|
||
@staticmethod | ||
def delete_app_by_vo(app_vo: App) -> None: | ||
app_vo.delete() | ||
|
||
def get_app( | ||
self, app_id: str, workspace_id: Union[str, None], domain_id: str | ||
) -> App: | ||
conditions = { | ||
"app_id": app_id, | ||
"domain_id": domain_id, | ||
} | ||
if workspace_id: | ||
conditions["workspace_id"] = workspace_id | ||
|
||
return self.app_model.get(**conditions) | ||
|
||
def list_apps(self, query: dict) -> Tuple[list, int]: | ||
return self.app_model.query(**query) | ||
|
||
def stat_apps(self, query: dict) -> dict: | ||
return self.app_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
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,35 @@ | ||
from mongoengine import * | ||
from spaceone.core.model.mongo_model import MongoModel | ||
|
||
|
||
class App(MongoModel): | ||
app_id = StringField(max_length=40, generate_id="app", unique=True) | ||
name = StringField(max_length=40, required=True) | ||
state = StringField( | ||
max_length=20, default="ENABLED", choices=("ENABLED", "DISABLED", "EXPIRED") | ||
) | ||
role_type = StringField( | ||
max_length=20, | ||
default="WORKSPACE_MEMBER", | ||
choices=( | ||
"SYSTEM", | ||
"SYSTEM_ADMIN", | ||
"DOMAIN_ADMIN", | ||
"WORKSPACE_OWNER", | ||
"WORKSPACE_MEMBER", | ||
), | ||
) | ||
api_key_id = StringField(max_length=40, default=None, null=True) | ||
role_id = StringField(max_length=40, required=True) | ||
|
||
domain_id = StringField(max_length=40, required=True) | ||
created_at = DateTimeField(auto_now_add=True) | ||
last_accessed_at = DateTimeField(default=None, null=True) | ||
expired_at = DateTimeField(required=True) | ||
|
||
meta = { | ||
"updatable_fields": ["name", "state", "api_key_id", "tags", "last_accessed_at"], | ||
"minimal_fields": ["app_id", "state", "expired_at", "api_key_id"], | ||
"ordering": ["app_id"], | ||
"indexes": ["state", "domain_id", "last_accessed_at", "expired_at"], | ||
} |
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,91 @@ | ||
from datetime import datetime | ||
from typing import Union, Literal | ||
from pydantic import BaseModel | ||
|
||
__all__ = [ | ||
"AppCreateRequest", | ||
"AppUpdateRequest", | ||
"AppGenerateAPIKeyRequest", | ||
"AppEnableRequest", | ||
"AppDisableRequest", | ||
"AppDeleteRequest", | ||
"AppGetRequest", | ||
"AppSearchQueryRequest", | ||
"AppStatQueryRequest", | ||
"State", | ||
"PermissionGroup", | ||
"RoleType", | ||
] | ||
|
||
State = Literal["ENABLED", "DISABLED", "EXPIRED"] | ||
PermissionGroup = Literal["DOMAIN", "WORKSPACE"] | ||
RoleType = Literal[ | ||
"SYSTEM", "SYSTEM_ADMIN", "DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER" | ||
] | ||
|
||
|
||
class AppCreateRequest(BaseModel): | ||
name: str | ||
role_id: str | ||
tags: Union[dict, None] = None | ||
expired_at: Union[datetime, None] = None | ||
permission_group: PermissionGroup | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class AppUpdateRequest(BaseModel): | ||
app_id: str | ||
name: Union[str, None] = None | ||
tags: Union[dict, None] = None | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class AppGenerateAPIKeyRequest(BaseModel): | ||
app_id: str | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class AppEnableRequest(BaseModel): | ||
app_id: str | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class AppDisableRequest(BaseModel): | ||
app_id: str | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class AppDeleteRequest(BaseModel): | ||
app_id: str | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class AppGetRequest(BaseModel): | ||
app_id: str | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class AppSearchQueryRequest(BaseModel): | ||
query: Union[dict, None] = None | ||
app_id: Union[str, None] = None | ||
name: Union[str, None] = None | ||
state: Union[State, None] = None | ||
role_type: Union[str, None] = None | ||
role_id: Union[str, None] = None | ||
api_key_id: Union[str, None] = None | ||
permission_group: Union[PermissionGroup, None] = None | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class AppStatQueryRequest(BaseModel): | ||
query: dict | ||
workspace_id: Union[str, None] = None | ||
domain_id: str |
Oops, something went wrong.