From 2a47a095eff74bc0fc1ae59b3ff77a83cc19b32d Mon Sep 17 00:00:00 2001 From: Joe Wu Date: Thu, 10 Nov 2022 20:14:30 -0800 Subject: [PATCH] mpc_game entity/repository migrate from fbpcp to fbpcs (#1909) Summary: Pull Request resolved: https://github.com/facebookresearch/fbpcs/pull/1909 ## Why In next couple weeks, I'm going to migrate mpc service from fbpcp to fbpcs. This is the first guard to avoid any further changes in fbpcp's mpc realted files detailed plan: https://docs.google.com/document/d/1qR1XVVCA2By95tldl2Ey9m__GKX3raodGAZ5yK9SCEw/edit?usp=sharing ## What - hg copy `mpc_game_config.py` from fbpcp to fbpcs - hg copy `mpc_game_repository.py` as as well - change import to fbpcs Reviewed By: musebc Differential Revision: D41201899 fbshipit-source-id: 8a9de4f03188febcbfece0c8d9badd2c559b4d42 --- .../repository/private_computation_game.py | 11 +++++++-- .../service/mpc/entity/mpc_game_config.py | 23 +++++++++++++++++++ .../service/mpc/mpc_game.py | 7 ++++-- .../mpc/repository/mpc_game_repository.py | 17 ++++++++++++++ .../test_private_computation_game.py | 3 ++- .../test/service/mpc/test_mpc_game.py | 6 ++++- .../private_computation_service_wrapper.py | 4 +++- ...est_private_computation_service_wrapper.py | 5 +++- 8 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 fbpcs/private_computation/service/mpc/entity/mpc_game_config.py create mode 100644 fbpcs/private_computation/service/mpc/repository/mpc_game_repository.py diff --git a/fbpcs/private_computation/repository/private_computation_game.py b/fbpcs/private_computation/repository/private_computation_game.py index d31361dd9..c3064df73 100644 --- a/fbpcs/private_computation/repository/private_computation_game.py +++ b/fbpcs/private_computation/repository/private_computation_game.py @@ -11,10 +11,17 @@ from enum import Enum from typing import Dict, List, TypedDict -from fbpcp.entity.mpc_game_config import MPCGameArgument, MPCGameConfig -from fbpcp.repository.mpc_game_repository import MPCGameRepository from fbpcs.onedocker_binary_names import OneDockerBinaryNames +from fbpcs.private_computation.service.mpc.entity.mpc_game_config import ( + MPCGameArgument, + MPCGameConfig, +) + +from fbpcs.private_computation.service.mpc.repository.mpc_game_repository import ( + MPCGameRepository, +) + class GameNames(Enum): SECURE_RANDOM_SHARDER = "secure_random_sharder" diff --git a/fbpcs/private_computation/service/mpc/entity/mpc_game_config.py b/fbpcs/private_computation/service/mpc/entity/mpc_game_config.py new file mode 100644 index 000000000..2d9fe5695 --- /dev/null +++ b/fbpcs/private_computation/service/mpc/entity/mpc_game_config.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# pyre-strict + +from dataclasses import dataclass +from typing import List + + +@dataclass +class MPCGameArgument: + name: str + required: bool + + +@dataclass +class MPCGameConfig: + game_name: str + onedocker_package_name: str + arguments: List[MPCGameArgument] diff --git a/fbpcs/private_computation/service/mpc/mpc_game.py b/fbpcs/private_computation/service/mpc/mpc_game.py index 9f5e759c4..004455b5d 100644 --- a/fbpcs/private_computation/service/mpc/mpc_game.py +++ b/fbpcs/private_computation/service/mpc/mpc_game.py @@ -9,11 +9,14 @@ import logging from typing import Any, Dict, Optional, Tuple -from fbpcp.entity.mpc_game_config import MPCGameConfig from fbpcp.entity.mpc_instance import MPCParty -from fbpcp.repository.mpc_game_repository import MPCGameRepository from fbpcp.util.arg_builder import build_cmd_args +from fbpcs.private_computation.service.mpc.entity.mpc_game_config import MPCGameConfig +from fbpcs.private_computation.service.mpc.repository.mpc_game_repository import ( + MPCGameRepository, +) + LIFT_GAME_NAME = "lift" LIFT_AGGREGATOR_GAME_NAME = "aggregator" diff --git a/fbpcs/private_computation/service/mpc/repository/mpc_game_repository.py b/fbpcs/private_computation/service/mpc/repository/mpc_game_repository.py new file mode 100644 index 000000000..a3a9147a8 --- /dev/null +++ b/fbpcs/private_computation/service/mpc/repository/mpc_game_repository.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# pyre-strict + +import abc + +from fbpcs.private_computation.service.mpc.entity.mpc_game_config import MPCGameConfig + + +class MPCGameRepository(abc.ABC): + @abc.abstractmethod + def get_game(self, name: str) -> MPCGameConfig: + pass diff --git a/fbpcs/private_computation/test/repository/test_private_computation_game.py b/fbpcs/private_computation/test/repository/test_private_computation_game.py index d82b09f44..dfdb411b4 100644 --- a/fbpcs/private_computation/test/repository/test_private_computation_game.py +++ b/fbpcs/private_computation/test/repository/test_private_computation_game.py @@ -10,12 +10,13 @@ from typing import List from unittest.mock import patch -from fbpcp.entity.mpc_game_config import MPCGameArgument from fbpcs.private_computation.repository.private_computation_game import ( OneDockerArgument, PrivateComputationGameRepository, ) +from fbpcs.private_computation.service.mpc.entity.mpc_game_config import MPCGameArgument + class TestPrivateComputationGameRepository(unittest.TestCase): @patch( diff --git a/fbpcs/private_computation/test/service/mpc/test_mpc_game.py b/fbpcs/private_computation/test/service/mpc/test_mpc_game.py index 0ec739574..62c3d7b9d 100644 --- a/fbpcs/private_computation/test/service/mpc/test_mpc_game.py +++ b/fbpcs/private_computation/test/service/mpc/test_mpc_game.py @@ -8,8 +8,12 @@ from typing import List from unittest.mock import MagicMock, Mock -from fbpcp.entity.mpc_game_config import MPCGameArgument, MPCGameConfig from fbpcp.entity.mpc_instance import MPCParty + +from fbpcs.private_computation.service.mpc.entity.mpc_game_config import ( + MPCGameArgument, + MPCGameConfig, +) from fbpcs.private_computation.service.mpc.mpc_game import MPCGameService diff --git a/fbpcs/private_computation_cli/private_computation_service_wrapper.py b/fbpcs/private_computation_cli/private_computation_service_wrapper.py index 87f4872f2..48e88c183 100644 --- a/fbpcs/private_computation_cli/private_computation_service_wrapper.py +++ b/fbpcs/private_computation_cli/private_computation_service_wrapper.py @@ -10,7 +10,6 @@ from typing import Any, DefaultDict, Dict, List, Optional, Type from fbpcp.entity.mpc_instance import MPCInstance -from fbpcp.repository.mpc_game_repository import MPCGameRepository from fbpcp.repository.mpc_instance import MPCInstanceRepository from fbpcp.service.container import ContainerService from fbpcp.service.onedocker import OneDockerService @@ -43,6 +42,9 @@ ) from fbpcs.private_computation.service.mpc.mpc import MPCService from fbpcs.private_computation.service.mpc.mpc_game import MPCGameService +from fbpcs.private_computation.service.mpc.repository.mpc_game_repository import ( + MPCGameRepository, +) from fbpcs.private_computation.service.private_computation import ( PrivateComputationService, ) diff --git a/fbpcs/private_computation_cli/tests/test_private_computation_service_wrapper.py b/fbpcs/private_computation_cli/tests/test_private_computation_service_wrapper.py index 812cf288f..dd3eccbcc 100644 --- a/fbpcs/private_computation_cli/tests/test_private_computation_service_wrapper.py +++ b/fbpcs/private_computation_cli/tests/test_private_computation_service_wrapper.py @@ -7,7 +7,6 @@ from unittest import TestCase from unittest.mock import ANY, call, MagicMock, patch -from fbpcp.repository.mpc_game_repository import MPCGameRepository from fbpcp.repository.mpc_instance import MPCInstanceRepository from fbpcp.service.container import ContainerService from fbpcp.service.storage import StorageService @@ -22,6 +21,10 @@ PrivateComputationInstanceRepository, ) from fbpcs.private_computation.service.mpc.mpc_game import MPCGameService + +from fbpcs.private_computation.service.mpc.repository.mpc_game_repository import ( + MPCGameRepository, +) from fbpcs.private_computation.service.private_computation import ( PrivateComputationService, )