Skip to content

Commit

Permalink
refactor: refactor config service
Browse files Browse the repository at this point in the history
  • Loading branch information
whdalsrnt committed Dec 23, 2024
1 parent b945ee0 commit 96d340b
Show file tree
Hide file tree
Showing 33 changed files with 866 additions and 681 deletions.
3 changes: 0 additions & 3 deletions src/spaceone/config/info/__init__.py

This file was deleted.

12 changes: 0 additions & 12 deletions src/spaceone/config/info/common_info.py

This file was deleted.

35 changes: 0 additions & 35 deletions src/spaceone/config/info/domain_config_info.py

This file was deleted.

34 changes: 0 additions & 34 deletions src/spaceone/config/info/user_config_info.py

This file was deleted.

6 changes: 4 additions & 2 deletions src/spaceone/config/interface/grpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from spaceone.core.pygrpc.server import GRPCServer
from spaceone.config.interface.grpc.user_config import UserConfig
from spaceone.config.interface.grpc.domain_config import DomainConfig
from spaceone.config.interface.grpc.shared_config import SharedConfig
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(UserConfig)
app.add_service(DomainConfig)
app.add_service(SharedConfig)
app.add_service(PublicConfig)
76 changes: 19 additions & 57 deletions src/spaceone/config/interface/grpc/domain_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from spaceone.api.config.v1 import domain_config_pb2, domain_config_pb2_grpc
from spaceone.core.pygrpc import BaseAPI

from spaceone.config.service.domain_config_service import DomainConfigService
from spaceone.config.info.domain_config_info import *
from spaceone.config.info.common_info import *


class DomainConfig(BaseAPI, domain_config_pb2_grpc.DomainConfigServicer):
Expand All @@ -11,73 +10,36 @@ class DomainConfig(BaseAPI, domain_config_pb2_grpc.DomainConfigServicer):

def create(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
DomainConfigService, metadata
) as domain_config_service:
return self.locator.get_info(
DomainConfigInfo, domain_config_service.create(params)
)
domain_config_svc = DomainConfigService(metadata)
response: dict = domain_config_svc.create(params)
return self.dict_to_message(response)

def update(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
DomainConfigService, metadata
) as domain_config_service:
return self.locator.get_info(
DomainConfigInfo, domain_config_service.update(params)
)
domain_config_svc = DomainConfigService(metadata)
response: dict = domain_config_svc.update(params)
return self.dict_to_message(response)

def set(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
DomainConfigService, metadata
) as domain_config_service:
return self.locator.get_info(
DomainConfigInfo, domain_config_service.set(params)
)
domain_config_svc = DomainConfigService(metadata)
response: dict = domain_config_svc.set(params)
return self.dict_to_message(response)

def delete(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
DomainConfigService, metadata
) as domain_config_service:
domain_config_service.delete(params)
return self.locator.get_info(EmptyInfo)
domain_config_svc = DomainConfigService(metadata)
domain_config_svc.delete(params)
return self.empty()

def get(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
DomainConfigService, metadata
) as domain_config_service:
return self.locator.get_info(
DomainConfigInfo, domain_config_service.get(params)
)
domain_config_svc = DomainConfigService(metadata)
response: dict = domain_config_svc.get(params)
return self.dict_to_message(response)

def list(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
DomainConfigService, metadata
) as domain_config_service:
domain_config_vos, total_count = domain_config_service.list(params)
return self.locator.get_info(
DomainConfigsInfo,
domain_config_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(
DomainConfigService, metadata
) as domain_config_service:
return self.locator.get_info(
StatisticsInfo, domain_config_service.stat(params)
)
domain_config_svc = DomainConfigService(metadata)
response: dict = domain_config_svc.list(params)
return self.dict_to_message(response)
12 changes: 0 additions & 12 deletions src/spaceone/config/interface/grpc/public_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,8 @@ def get(self, request, context):
response: dict = public_config_svc.get(params)
return self.dict_to_message(response)

def get_accessible_configs(self, request, context):
params, metadata = self.parse_request(request, context)
public_config_svc = PublicConfigService(metadata)
response: dict = public_config_svc.get_accessible_configs(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)
39 changes: 39 additions & 0 deletions src/spaceone/config/interface/grpc/shared_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from spaceone.api.config.v1 import shared_config_pb2, shared_config_pb2_grpc
from spaceone.core.pygrpc import BaseAPI

from spaceone.config.service.shared_config_service import SharedConfigService


class SharedConfig(BaseAPI, shared_config_pb2_grpc.SharedConfigServicer):
pb2 = shared_config_pb2
pb2_grpc = shared_config_pb2_grpc

def create(self, request, context):
params, metadata = self.parse_request(request, context)
shared_config_svc = SharedConfigService(metadata)
response: dict = shared_config_svc.create(params)
return self.dict_to_message(response)

def update(self, request, context):
params, metadata = self.parse_request(request, context)
shared_config_svc = SharedConfigService(metadata)
response: dict = shared_config_svc.update(params)
return self.dict_to_message(response)

def delete(self, request, context):
params, metadata = self.parse_request(request, context)
shared_config_svc = SharedConfigService(metadata)
shared_config_svc.delete(params)
return self.empty()

def get(self, request, context):
params, metadata = self.parse_request(request, context)
shared_config_svc = SharedConfigService(metadata)
response: dict = shared_config_svc.get(params)
return self.dict_to_message(response)

def list(self, request, context):
params, metadata = self.parse_request(request, context)
shared_config_svc = SharedConfigService(metadata)
response: dict = shared_config_svc.list(params)
return self.dict_to_message(response)
76 changes: 19 additions & 57 deletions src/spaceone/config/interface/grpc/user_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from spaceone.api.config.v1 import user_config_pb2, user_config_pb2_grpc
from spaceone.core.pygrpc import BaseAPI

from spaceone.config.service.user_config_service import UserConfigService
from spaceone.config.info.user_config_info import *
from spaceone.config.info.common_info import *


class UserConfig(BaseAPI, user_config_pb2_grpc.UserConfigServicer):
Expand All @@ -11,73 +10,36 @@ class UserConfig(BaseAPI, user_config_pb2_grpc.UserConfigServicer):

def create(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
UserConfigService, metadata
) as user_config_service:
return self.locator.get_info(
UserConfigInfo, user_config_service.create(params)
)
user_config_svc = UserConfigService(metadata)
response: dict = user_config_svc.create(params)
return self.dict_to_message(response)

def update(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
UserConfigService, metadata
) as user_config_service:
return self.locator.get_info(
UserConfigInfo, user_config_service.update(params)
)
user_config_svc = UserConfigService(metadata)
response: dict = user_config_svc.update(params)
return self.dict_to_message(response)

def set(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
UserConfigService, metadata
) as user_config_service:
return self.locator.get_info(
UserConfigInfo, user_config_service.set(params)
)
user_config_svc = UserConfigService(metadata)
response: dict = user_config_svc.set(params)
return self.dict_to_message(response)

def delete(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
UserConfigService, metadata
) as user_config_service:
user_config_service.delete(params)
return self.locator.get_info(EmptyInfo)
user_config_svc = UserConfigService(metadata)
user_config_svc.delete(params)
return self.empty()

def get(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
UserConfigService, metadata
) as user_config_service:
return self.locator.get_info(
UserConfigInfo, user_config_service.get(params)
)
user_config_svc = UserConfigService(metadata)
response: dict = user_config_svc.get(params)
return self.dict_to_message(response)

def list(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service(
UserConfigService, metadata
) as user_config_service:
user_config_vos, total_count = user_config_service.list(params)
return self.locator.get_info(
UserConfigsInfo,
user_config_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(
UserConfigService, metadata
) as user_config_service:
return self.locator.get_info(
StatisticsInfo, user_config_service.stat(params)
)
user_config_svc = UserConfigService(metadata)
response: dict = user_config_svc.list(params)
return self.dict_to_message(response)
Loading

0 comments on commit 96d340b

Please sign in to comment.