Skip to content

Commit

Permalink
refactor: change all for SpaceONE 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stat-kwon committed Dec 17, 2023
1 parent 71a0c97 commit 0f04e70
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 146 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ ENV PACKAGE_VERSION=$PACKAGE_VERSION

COPY pkg/pip_requirements.txt pip_requirements.txt

RUN pip install --upgrade -r pip_requirements.txt
RUN pip install --upgrade pip && \
pip install --upgrade -r pip_requirements.txt

COPY src ${SRC_DIR}
WORKDIR ${SRC_DIR}
Expand All @@ -21,4 +22,4 @@ RUN pip install --upgrade spaceone-api
EXPOSE ${SPACEONE_PORT}

ENTRYPOINT ["spaceone"]
CMD ["run","grpc-server", "spaceone.config", "-m", "/opt"]
CMD ["run", "grpc-server", "spaceone.config", "-m", "/opt"]
22 changes: 4 additions & 18 deletions deploy/helm/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
REMOTE_URL:
- file:///opt/spaceone/config/config/database.yaml
- file:///opt/spaceone/config/config/shared.yaml
- file:///opt/spaceone/config/config/application.yaml
- file:///opt/spaceone/config/config/database.yaml
- file:///opt/spaceone/config/config/shared.yaml
- file:///opt/spaceone/config/config/application.yaml
GLOBAL:
MAX_WORKERS: 1000
DATABASES:
Expand All @@ -17,7 +17,6 @@ GLOBAL:
backend: spaceone.core.cache.redis_cache.RedisCache
host: redis
port: 6379
db: 1
encoding: utf-8
socket_timeout: 10
socket_connect_timeout: 10
Expand All @@ -30,17 +29,4 @@ GLOBAL:
handlers:
file:
type: file
filename: /var/log/spaceone/config.log
CONNECTORS:
IdentityConnector:
endpoint:
v1: grpc://identity:50051
SecretConnector:
endpoint:
v1: grpc://secret:50051
PluginConnector:
endpoint:
v1: grpc://plugin:50051
RepositoryConnector:
endpoint:
v1: grpc://repository:50051
filename: /var/log/spaceone/config.log
3 changes: 2 additions & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import os

from setuptools import setup, find_packages

setup(
Expand All @@ -26,6 +27,6 @@
author_email="[email protected]",
license="Apache License 2.0",
packages=find_packages(),
install_requires=["spaceone-core", "spaceone-api", "mongoengine"],
install_requires=["spaceone-core", "spaceone-api", "mongoengine", "mongomock"],
zip_safe=False,
)
19 changes: 18 additions & 1 deletion src/spaceone/config/conf/global_conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Database Settings
DATABASE_AUTO_CREATE_INDEX = True
DATABASES = {
"default": {
Expand All @@ -9,6 +10,7 @@
}
}

# Cache Settings
CACHES = {
"default": {},
"local": {
Expand All @@ -18,4 +20,19 @@
},
}

HANDLERS = {}
# Handler Settings
HANDLERS = {
# "authentication": [{
# "backend": "spaceone.core.handler.authentication_handler:SpaceONEAuthenticationHandler"
# }],
# "authorization": [{
# "backend": "spaceone.core.handler.authorization_handler:SpaceONEAuthorizationHandler"
# }],
# "mutation": [{
# "backend": "spaceone.core.handler.mutation_handler:SpaceONEMutationHandler"
# }],
# "event": []
}

# Connector Settings
CONNECTORS = {}
28 changes: 15 additions & 13 deletions src/spaceone/config/manager/domain_config_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from spaceone.core.manager import BaseManager

from spaceone.config.model.domain_config_model import DomainConfig

_LOGGER = logging.getLogger(__name__)
Expand All @@ -11,27 +12,28 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.domain_config_model: DomainConfig = self.locator.get_model("DomainConfig")

def create_domain_config(self, params):
def _rollback(domain_config_vo):
def create_domain_config(self, params: dict) -> DomainConfig:
def _rollback(vo: DomainConfig) -> None:
_LOGGER.info(
f"[create_domain_config._rollback] "
f"Delete domain config : {domain_config_vo.name}"
f"[create_domain_config._rollback] " f"Delete domain config : {vo.name}"
)
domain_config_vo.delete()
vo.delete()

domain_config_vo: DomainConfig = self.domain_config_model.create(params)
self.transaction.add_rollback(_rollback, domain_config_vo)

return domain_config_vo

def update_domain_config(self, params):
def update_domain_config(self, params: dict) -> DomainConfig:
domain_config_vo: DomainConfig = self.get_domain_config(
params["name"], params["domain_id"]
)
return self.update_domain_config_by_vo(params, domain_config_vo)

def update_domain_config_by_vo(self, params, domain_config_vo):
def _rollback(old_data):
def update_domain_config_by_vo(
self, params: dict, domain_config_vo: DomainConfig
) -> DomainConfig:
def _rollback(old_data: dict):
_LOGGER.info(
f'[update_domain_config_by_vo._rollback] Revert Data : {old_data["name"]}'
)
Expand All @@ -41,17 +43,17 @@ def _rollback(old_data):

return domain_config_vo.update(params)

def delete_domain_config(self, name, domain_id):
def delete_domain_config(self, name: str, domain_id: str) -> None:
domain_config_vo: DomainConfig = self.get_domain_config(name, domain_id)
domain_config_vo.delete()

def get_domain_config(self, name, domain_id, only=None):
return self.domain_config_model.get(name=name, domain_id=domain_id, only=only)
def get_domain_config(self, name: str, domain_id: str) -> DomainConfig:
return self.domain_config_model.get(name=name, domain_id=domain_id)

def filter_domain_configs(self, **conditions):
def filter_domain_configs(self, **conditions: dict):
return self.domain_config_model.filter(**conditions)

def list_domain_configs(self, query={}):
def list_domain_configs(self, query: dict) -> dict:
return self.domain_config_model.query(**query)

def state_domain_configs(self, query):
Expand Down
30 changes: 16 additions & 14 deletions src/spaceone/config/manager/user_config_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from spaceone.core.manager import BaseManager

from spaceone.config.model.user_config_model import UserConfig

_LOGGER = logging.getLogger(__name__)
Expand All @@ -11,27 +12,28 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user_config_model: UserConfig = self.locator.get_model("UserConfig")

def create_user_config(self, params):
def _rollback(user_config_vo):
def create_user_config(self, params: dict) -> UserConfig:
def _rollback(vo: UserConfig):
_LOGGER.info(
f"[create_user_config._rollback] "
f"Delete config map : {user_config_vo.name}"
f"[create_user_config._rollback] " f"Delete config map : {vo.name}"
)
user_config_vo.delete()
vo.delete()

user_config_vo: UserConfig = self.user_config_model.create(params)
self.transaction.add_rollback(_rollback, user_config_vo)

return user_config_vo

def update_user_config(self, params):
def update_user_config(self, params: dict) -> UserConfig:
user_config_vo: UserConfig = self.get_user_config(
params["name"], params["user_id"], params["domain_id"]
)
return self.update_user_config_by_vo(params, user_config_vo)

def update_user_config_by_vo(self, params, user_config_vo):
def _rollback(old_data):
def update_user_config_by_vo(
self, params: dict, user_config_vo: UserConfig
) -> UserConfig:
def _rollback(old_data: dict):
_LOGGER.info(
f'[update_user_config_by_vo._rollback] Revert Data : {old_data["name"]}'
)
Expand All @@ -41,20 +43,20 @@ def _rollback(old_data):

return user_config_vo.update(params)

def delete_user_config(self, name, user_id, domain_id):
def delete_user_config(self, name: str, user_id: str, domain_id: str) -> None:
user_config_vo: UserConfig = self.get_user_config(name, user_id, domain_id)
user_config_vo.delete()

def get_user_config(self, name, user_id, domain_id, only=None):
def get_user_config(self, name: str, user_id: str, domain_id: str) -> UserConfig:
return self.user_config_model.get(
name=name, user_id=user_id, domain_id=domain_id, only=only
name=name, user_id=user_id, domain_id=domain_id
)

def filter_user_configs(self, **conditions):
def filter_user_configs(self, **conditions: dict):
return self.user_config_model.filter(**conditions)

def list_user_configs(self, query={}):
def list_user_configs(self, query: dict) -> dict:
return self.user_config_model.query(**query)

def state_user_configs(self, query):
def state_user_configs(self, query: dict) -> dict:
return self.user_config_model.stat(**query)
Loading

0 comments on commit 0f04e70

Please sign in to comment.