Example #1
0
    def __init__(
        self,
        name: Optional[str],
        domain_url: str,
        network: Optional[Location] = None,
        domain: SpecificLocation = SpecificLocation(),
        device: Optional[Location] = None,
        vm: Optional[Location] = None,
        signing_key: Optional[SigningKey] = None,
        verify_key: Optional[VerifyKey] = None,
        root_key: Optional[VerifyKey] = None,
        db_path: Optional[str] = None,
    ):
        super().__init__(
            name=name,
            network=network,
            domain=domain,
            device=device,
            vm=vm,
            signing_key=signing_key,
            verify_key=verify_key,
            db_path=db_path,
        )

        self.domain_client = connect(
            url=domain_url,  # Domain Address
            conn_type=GridHTTPConnection,  # HTTP Connection Protocol
            client_type=DomainClient,
        )
        self.immediate_services_with_reply.append(TransferObjectService)
        self.immediate_services_without_reply.append(SaveObjectService)

        # Grid Worker Services
        self._register_services()
Example #2
0
def send_obj(address, obj, node):
    client = connect(
        url=address, conn_type=GridHTTPConnection  # Domain Address
    )  # HTTP Connection Protocol
    y_s = obj.data.send(
        client, pointable=True, tags=obj.tags, description=obj.description
    )
Example #3
0
        def filter_domains(url):
            domain = connect(
                url=url,  # Domain Address
                conn_type=GridHTTPConnection,  # HTTP Connection Protocol
            )

            for data in domain.store:
                if queries.issubset(set(data.tags)):
                    return True
            return False
Example #4
0
def get_worker_msg(msg: GetWorkerMessage, node: AbstractNode,
                   verify_key: VerifyKey) -> GetWorkerResponse:
    try:

        worker_id = msg.content.get("worker_id", None)
        _current_user_id = msg.content.get("current_user", None)

        users = node.users

        if not _current_user_id:
            _current_user_id = users.first(verify_key=verify_key.encode(
                encoder=HexEncoder).decode("utf-8")).id

        env_ids = [
            env.id for env in node.environments.get_environments(
                user=_current_user_id)
        ]
        is_admin = users.can_manage_infrastructure(user_id=_current_user_id)

        if (int(worker_id) in env_ids) or is_admin:
            worker = node.environments.first(id=int(worker_id))

            try:
                worker_client = connect(
                    url="http://" + worker.address,
                    conn_type=GridHTTPConnection,  # HTTP Connection Protocol
                )

                node.environments.set(
                    id=worker.id,
                    syft_address=serialize(
                        worker_client.address).SerializeToString().decode(
                            "ISO-8859-1"),
                )

                node.in_memory_client_registry[
                    worker_client.domain_id] = worker_client
            except Exception as e:
                return GetWorkerResponse(
                    address=msg.reply_to,
                    status_code=500,
                    content={"error": str(e)},
                )
            _msg = model_to_json(node.environments.first(id=int(worker_id)))
        else:
            _msg = {}

        return GetWorkerResponse(address=msg.reply_to,
                                 status_code=200,
                                 content=_msg)
    except Exception as e:
        return GetWorkerResponse(address=msg.reply_to,
                                 status_code=500,
                                 content={"error": str(e)})
Example #5
0
def setup_domain() -> None:
    # this ensures that the new PyGrid Domain is setup and will respond to commands
    try:
        ua_client = connect(url=f"http://*****:*****@myorg.com",
            password="******",
            token="9G9MJ06OQH",
        )

    except Exception as e:
        if "domain already has an owner" not in str(e):
            raise e
        else:
            print(f"Failed to run setup. {e}")