Esempio n. 1
0
def _build_mpc_service(
    config: Dict[str, Any],
    onedocker_service_config: OneDockerServiceConfig,
    container_service: ContainerService,
    storage_service: StorageService,
) -> MPCService:

    mpcinstance_repository_config = config["dependency"][
        "MPCInstanceRepository"]
    repository_service = reflect.get_instance(mpcinstance_repository_config,
                                              MPCInstanceRepository)

    mpc_game_config = config["dependency"]["MPCGameService"]
    pc_game_repo_config = mpc_game_config["dependency"][
        "PrivateComputationGameRepository"]
    pc_game_repo = reflect.get_instance(pc_game_repo_config, MPCGameRepository)
    mpc_game_class = reflect.get_class(mpc_game_config["class"],
                                       MPCGameService)
    mpc_game_svc = mpc_game_class(pc_game_repo)

    task_definition = onedocker_service_config.task_definition

    return MPCService(
        container_service,
        repository_service,
        task_definition,
        mpc_game_svc,
    )
Esempio n. 2
0
def _parse_pc_validator_config(pc_config: Dict[str, Any]) -> PCValidatorConfig:
    raw_pc_validator_config = pc_config["dependency"].get("PCValidatorConfig")
    if not raw_pc_validator_config:
        storage_svc_region = pc_config["dependency"]["StorageService"][
            "constructor"]["region"]
        # The Validator needs to run in the same region as the storage_svc by default
        return PCValidatorConfig(region=storage_svc_region)
    return reflect.get_instance(raw_pc_validator_config, PCValidatorConfig)
Esempio n. 3
0
def _get_post_processing_handlers(
        config: Dict[str, Any]) -> Dict[str, PostProcessingHandler]:
    if not config:
        return {}
    return {
        name: reflect.get_instance(handler_config, PostProcessingHandler)
        for name, handler_config in config["dependency"].items()
    }
Esempio n. 4
0
def _build_private_computation_service(
    pc_config: Dict[str, Any],
    mpc_config: Dict[str, Any],
    pid_config: Dict[str, Any],
    pph_config: Dict[str, Any],
    pid_pph_config: Dict[str, Any],
) -> PrivateComputationService:
    instance_repository_config = pc_config["dependency"][
        "PrivateComputationInstanceRepository"]
    repository_service = reflect.get_instance(
        instance_repository_config, PrivateComputationInstanceRepository)
    container_service = _build_container_service(
        pc_config["dependency"]["ContainerService"])
    onedocker_service_config = _build_onedocker_service_cfg(
        pc_config["dependency"]["OneDockerServiceConfig"])
    onedocker_binary_config_map = _build_onedocker_binary_cfg_map(
        pc_config["dependency"]["OneDockerBinaryConfig"])
    onedocker_service = _build_onedocker_service(
        container_service, onedocker_service_config.task_definition)
    storage_service = _build_storage_service(
        pc_config["dependency"]["StorageService"])
    if "WorkflowService" in pc_config["dependency"]:
        workflow_service = _build_workflow_service(
            pc_config["dependency"]["WorkflowService"])
    else:
        workflow_service = None
    return PrivateComputationService(
        repository_service,
        storage_service,
        _build_mpc_service(mpc_config, onedocker_service_config,
                           container_service, storage_service),
        _build_pid_service(
            pid_config,
            onedocker_service,
            storage_service,
            onedocker_binary_config_map,
        ),
        onedocker_service,
        onedocker_binary_config_map,
        _parse_pc_validator_config(pc_config),
        _get_post_processing_handlers(pph_config),
        _get_post_processing_handlers(pid_pph_config),
        workflow_svc=workflow_service,
    )
Esempio n. 5
0
def _build_pid_service(
    pid_config: Dict[str, Any],
    onedocker_service: OneDockerService,
    storage_service: StorageService,
    onedocker_binary_config_map: DefaultDict[str, OneDockerBinaryConfig],
) -> PIDService:
    pidinstance_repository_config = pid_config["dependency"][
        "PIDInstanceRepository"]
    repository_service = reflect.get_instance(pidinstance_repository_config,
                                              PIDInstanceRepository)

    multikey_enabled = True
    if "multikey_enabled" in pid_config.keys(
    ) and not pid_config["multikey_enabled"]:
        multikey_enabled = False
    return PIDService(
        onedocker_service,
        storage_service,
        repository_service,
        onedocker_binary_config_map,
        multikey_enabled,
    )
Esempio n. 6
0
def _build_workflow_service(config: Dict[str, Any]) -> WorkflowService:
    return reflect.get_instance(config, WorkflowService)
Esempio n. 7
0
def _build_storage_service(config: Dict[str, Any]) -> StorageService:
    return reflect.get_instance(config, StorageService)
Esempio n. 8
0
def _build_container_service(config: Dict[str, Any]) -> PCSContainerService:
    return PCSContainerService(reflect.get_instance(config, ContainerService))