-
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 #8 from ImMin5/master
Add new feature PublicConfig resource
- Loading branch information
Showing
14 changed files
with
496 additions
and
365 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,11 +1,11 @@ | ||
from spaceone.core.pygrpc.server import GRPCServer | ||
from spaceone.config.interface.grpc.domain_config import DomainConfig | ||
from spaceone.config.interface.grpc.workspace_config import WorkspaceConfig | ||
from spaceone.config.interface.grpc.public_config import PublicConfig | ||
from spaceone.config.interface.grpc.user_config import UserConfig | ||
|
||
_all_ = ["app"] | ||
|
||
app = GRPCServer() | ||
app.add_service(DomainConfig) | ||
app.add_service(WorkspaceConfig) | ||
app.add_service(UserConfig) | ||
app.add_service(PublicConfig) |
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,51 @@ | ||
from spaceone.api.config.v1 import public_config_pb2, public_config_pb2_grpc | ||
from spaceone.core.pygrpc import BaseAPI | ||
|
||
from spaceone.config.service.public_config_service import PublicConfigService | ||
|
||
|
||
class PublicConfig(BaseAPI, public_config_pb2_grpc.PublicConfigServicer): | ||
pb2 = public_config_pb2 | ||
pb2_grpc = public_config_pb2_grpc | ||
|
||
def create(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
public_config_svc = PublicConfigService(metadata) | ||
response: dict = public_config_svc.create(params) | ||
return self.dict_to_message(response) | ||
|
||
def update(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
public_config_svc = PublicConfigService(metadata) | ||
response: dict = public_config_svc.update(params) | ||
return self.dict_to_message(response) | ||
|
||
def set(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
public_config_svc = PublicConfigService(metadata) | ||
response: dict = public_config_svc.set(params) | ||
return self.dict_to_message(response) | ||
|
||
def delete(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
public_config_svc = PublicConfigService(metadata) | ||
public_config_svc.delete(params) | ||
return self.empty() | ||
|
||
def get(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
public_config_svc = PublicConfigService(metadata) | ||
response: dict = public_config_svc.get(params) | ||
return self.dict_to_message(response) | ||
|
||
def list(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
public_config_svc = PublicConfigService(metadata) | ||
response: dict = public_config_svc.list(params) | ||
return self.dict_to_message(response) | ||
|
||
def stat(self, request, context): | ||
params, metadata = self.parse_request(request, context) | ||
public_config_svc = PublicConfigService(metadata) | ||
response: dict = public_config_svc.stat(params) | ||
return self.dict_to_message(response) |
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
import logging | ||
|
||
from spaceone.core import cache | ||
from spaceone.core import config | ||
from spaceone.core.manager import BaseManager | ||
from spaceone.core.connector.space_connector import SpaceConnector | ||
from spaceone.core.auth.jwt.jwt_util import JWTUtil | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class IdentityManager(BaseManager): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
token = self.transaction.get_meta("token") | ||
self.token_type = JWTUtil.get_value_from_token(token, "typ") | ||
self.identity_conn: SpaceConnector = self.locator.get_connector( | ||
SpaceConnector, service="identity" | ||
) | ||
|
||
def check_workspace(self, workspace_id: str, domain_id: str) -> None: | ||
system_token = config.get_global("TOKEN") | ||
|
||
self.identity_conn.dispatch( | ||
"Workspace.check", | ||
{"workspace_id": workspace_id, "domain_id": domain_id}, | ||
token=system_token, | ||
) | ||
|
||
@cache.cacheable(key="inventory:project:{domain_id}:{project_id}", expire=600) | ||
def get_project(self, project_id: str, domain_id: str): | ||
if self.token_type == "SYSTEM_TOKEN": | ||
return self.identity_conn.dispatch( | ||
"Project.get", {"project_id": project_id}, x_domain_id=domain_id | ||
) | ||
else: | ||
return self.identity_conn.dispatch( | ||
"Project.get", {"project_id": project_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,66 @@ | ||
import logging | ||
from typing import Tuple, Union | ||
|
||
from mongoengine import QuerySet | ||
from spaceone.core.manager import BaseManager | ||
|
||
from spaceone.config.model.public_config.database import PublicConfig | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class PublicConfigManager(BaseManager): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.public_config_model = PublicConfig | ||
|
||
def create_public_config(self, params: dict) -> PublicConfig: | ||
def _rollback(vo: PublicConfig) -> None: | ||
_LOGGER.info( | ||
f"[create_public_config._rollback] " f"Delete public config : {vo.name}" | ||
) | ||
vo.delete() | ||
|
||
public_config_vo: PublicConfig = self.public_config_model.create(params) | ||
self.transaction.add_rollback(_rollback, public_config_vo) | ||
|
||
return public_config_vo | ||
|
||
def update_public_config_by_vo( | ||
self, params: dict, public_config_vo: PublicConfig | ||
) -> PublicConfig: | ||
def _rollback(old_data: dict): | ||
_LOGGER.info( | ||
f'[update_public_config_by_vo._rollback] Revert Data : {old_data["name"]}' | ||
) | ||
public_config_vo.update(old_data) | ||
|
||
self.transaction.add_rollback(_rollback, public_config_vo.to_dict()) | ||
|
||
return public_config_vo.update(params) | ||
|
||
@staticmethod | ||
def delete_public_config_by_vo(public_config_vo: PublicConfig) -> None: | ||
public_config_vo.delete() | ||
|
||
def get_public_config(self, name: str, domain_id: str, workspace_id: Union[list, str, None], | ||
project_id: Union[list, str, None]) -> PublicConfig: | ||
conditions = { | ||
"name": name, | ||
"domain_id": domain_id, | ||
} | ||
if workspace_id: | ||
conditions["workspace_id"] = workspace_id | ||
if project_id: | ||
conditions["project_id"] = project_id | ||
|
||
return self.public_config_model.get(**conditions) | ||
|
||
def filter_public_configs(self, **conditions): | ||
return self.public_config_model.filter(**conditions) | ||
|
||
def list_public_configs(self, query: dict) -> Tuple[QuerySet, int]: | ||
return self.public_config_model.query(**query) | ||
|
||
def stat_public_configs(self, query: dict) -> dict: | ||
return self.public_config_model.stat(**query) |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
from spaceone.config.model.user_config_model import UserConfig | ||
from spaceone.config.model.workspace_config.database import WorkspaceConfig | ||
from spaceone.config.model.domain_config_model import DomainConfig | ||
from spaceone.config.model.public_config.database import PublicConfig |
File renamed without changes.
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,76 @@ | ||
from typing import Union, Literal | ||
from pydantic import BaseModel | ||
|
||
__all__ = [ | ||
"PublicConfigCreateRequest", | ||
"PublicConfigUpdateRequest", | ||
"PublicConfigSetRequest", | ||
"PublicConfigDeleteRequest", | ||
"PublicConfigGetRequest", | ||
"PublicConfigSearchQueryRequest", | ||
"PublicConfigQueryRequest", | ||
] | ||
|
||
ResourceGroup = Literal["DOMAIN", "WORKSPACE", "PROJECT"] | ||
|
||
|
||
class PublicConfigCreateRequest(BaseModel): | ||
name: str | ||
data: dict | ||
tags: Union[dict, None] = None | ||
resource_group: ResourceGroup | ||
user_projects: Union[list, None] = None | ||
project_id: Union[list, str, None] = None | ||
workspace_id: Union[list, str, None] = None | ||
domain_id: str | ||
|
||
|
||
class PublicConfigUpdateRequest(BaseModel): | ||
name: str | ||
data: Union[dict, None] = None | ||
tags: Union[dict, None] = None | ||
user_projects: Union[list, None] = None | ||
project_id: Union[str, None] = None | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class PublicConfigSetRequest(BaseModel): | ||
name: str | ||
data: str | ||
tags: Union[dict, None] = None | ||
user_projects: Union[list, None] = None | ||
project_id: Union[str, None] = None | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class PublicConfigDeleteRequest(BaseModel): | ||
name: str | ||
user_projects: Union[list, None] = None | ||
project_id: Union[str, None] = None | ||
workspace_id: Union[str, None] = None | ||
domain_id: str | ||
|
||
|
||
class PublicConfigGetRequest(BaseModel): | ||
name: str | ||
user_projects: Union[list, None] = None | ||
project_id: Union[list, str, None] = None | ||
workspace_id: Union[list, str, None] = None | ||
domain_id: str | ||
|
||
|
||
class PublicConfigSearchQueryRequest(BaseModel): | ||
query: Union[dict, None] = None | ||
name: Union[str, None] = None | ||
user_project: Union[list, None] = None | ||
project_id: Union[list, str, None] = None | ||
workspace_id: Union[list, str, None] = None | ||
domain_id: str | ||
|
||
|
||
class PublicConfigQueryRequest(BaseModel): | ||
query: dict | ||
workspace_id: str | ||
domain_id: str |
Oops, something went wrong.