Ejemplo n.º 1
0
 def translate_auth_to_avro(*, auth: AuthToken) -> AuthAvro:
     result = AuthAvro()
     result.name = auth.get_name()
     result.guid = str(auth.get_guid())
     result.oidc_sub_claim = auth.get_oidc_sub_claim()
     result.email = auth.get_email()
     return result
Ejemplo n.º 2
0
    def do_reclaim_delegation(self,
                              *,
                              actor: ABCActorMixin,
                              proxy: ABCBrokerProxy,
                              delegation: ABCDelegation,
                              callback: ABCClientCallbackProxy,
                              caller: AuthToken,
                              id_token: str = None):
        proxy.get_logger().info(
            "Outbound reclaim delegation request from <{}>: {}".format(
                caller.get_name(), delegation))

        state = proxy.prepare_reclaim_delegation(delegation=delegation,
                                                 callback=callback,
                                                 caller=caller,
                                                 id_token=id_token)
        state.set_caller(caller=caller)
        state.set_type(rtype=RPCRequestType.ReclaimDelegation)

        rpc = RPCRequest(request=state,
                         actor=actor,
                         proxy=proxy,
                         delegation=delegation,
                         sequence=delegation.get_sequence_out())
        # Schedule a timeout
        rpc.timer = KernelTimer.schedule(queue=actor,
                                         task=ReclaimTimeout(req=rpc),
                                         delay=self.CLAIM_TIMEOUT_SECONDS)
        proxy.get_logger().info("Timer started: {} for Reclaim".format(
            rpc.timer))
        self.enqueue(rpc=rpc)
Ejemplo n.º 3
0
    def advertise(self, *, delegation: ABCPropertyGraph, delegation_name: str, client: AuthToken) -> str:
        slice_obj = SliceFactory.create(slice_id=ID(), name=client.get_name())
        slice_obj.set_owner(owner=client)
        slice_obj.set_broker_client()

        dlg_obj = DelegationFactory.create(did=delegation.get_graph_id(), slice_id=slice_obj.get_slice_id(),
                                           delegation_name=delegation_name)
        dlg_obj.set_slice_object(slice_object=slice_obj)
        dlg_obj.set_graph(graph=delegation)
        self.wrapper.advertise(delegation=dlg_obj, client=client)
        return dlg_obj.get_delegation_id()
Ejemplo n.º 4
0
 def __init__(self, *, auth: AuthToken = None):
     self.logger = None
     self.proxy_type = None
     self.callback = False
     self.actor_name = None
     if auth is not None:
         self.actor_name = auth.get_name()
     self.actor_guid = None
     if auth is not None:
         self.actor_guid = auth.get_guid()
     self.auth = auth
Ejemplo n.º 5
0
    def do_query_result(self, *, actor: ABCActorMixin,
                        remote_actor: ABCCallbackProxy, request_id: str,
                        response: dict, caller: AuthToken):
        remote_actor.get_logger().info(
            "Outbound query_result request from <{}>".format(
                caller.get_name()))

        state = remote_actor.prepare_query_result(request_id=request_id,
                                                  response=response,
                                                  caller=caller)
        state.set_caller(caller=caller)
        state.set_type(rtype=RPCRequestType.QueryResult)
        rpc = RPCRequest(request=state, actor=actor, proxy=remote_actor)
        self.enqueue(rpc=rpc)
Ejemplo n.º 6
0
    def do_close(self, *, actor: ABCActorMixin, proxy: ABCAuthorityProxy,
                 reservation: ABCControllerReservation,
                 callback: ABCControllerCallbackProxy, caller: AuthToken):
        proxy.get_logger().info("Outbound close request from <{}>: {}".format(
            caller.get_name(), reservation))

        state = proxy.prepare_close(reservation=reservation,
                                    callback=callback,
                                    caller=caller)
        state.set_caller(caller=caller)
        state.set_type(rtype=RPCRequestType.Close)
        rpc = RPCRequest(request=state,
                         actor=actor,
                         proxy=proxy,
                         reservation=reservation,
                         sequence=reservation.get_lease_sequence_out())
        self.enqueue(rpc=rpc)
Ejemplo n.º 7
0
    def do_ticket(self, *, actor: ABCActorMixin, proxy: ABCBrokerProxy,
                  reservation: ABCClientReservation,
                  callback: ABCClientCallbackProxy, caller: AuthToken):
        proxy.get_logger().info("Outbound ticket request from <{}>: {}".format(
            caller.get_name(), reservation))

        state = proxy.prepare_ticket(reservation=reservation,
                                     callback=callback,
                                     caller=caller)
        state.set_caller(caller=caller)
        state.set_type(rtype=RPCRequestType.Ticket)
        rpc = RPCRequest(request=state,
                         actor=actor,
                         proxy=proxy,
                         reservation=reservation,
                         sequence=reservation.get_ticket_sequence_out())
        self.enqueue(rpc=rpc)
    def pass_client_delegation(self, *, delegation: DelegationAvro,
                               caller: AuthToken) -> ABCDelegation:
        slice_obj = Translate.translate_slice(slice_avro=delegation.slice)

        dlg = BrokerDelegationFactory.create(
            did=delegation.get_delegation_id(),
            slice_id=slice_obj.get_slice_id(),
            broker=None)
        dlg.restore(actor=self.actor, slice_obj=slice_obj)

        site_proxy = ActorRegistrySingleton.get().get_proxy(
            protocol=Constants.PROTOCOL_KAFKA, actor_name=caller.get_name())
        dlg.set_site_proxy(site_proxy=site_proxy)

        if delegation.graph is not None:
            dlg.load_graph(graph_str=delegation.graph)
        return dlg
Ejemplo n.º 9
0
    def do_update_delegation(self, *, actor: ABCActorMixin,
                             proxy: ABCClientCallbackProxy,
                             delegation: ABCDelegation,
                             update_data: UpdateData,
                             callback: ABCCallbackProxy, caller: AuthToken):
        proxy.get_logger().info(
            "Outbound update delegation request from <{}>: {}".format(
                caller.get_name(), delegation))

        state = proxy.prepare_update_delegation(delegation=delegation,
                                                update_data=update_data,
                                                callback=callback,
                                                caller=caller)
        state.set_caller(caller=caller)
        state.set_type(rtype=RPCRequestType.UpdateDelegation)
        rpc = RPCRequest(request=state,
                         actor=actor,
                         proxy=proxy,
                         delegation=delegation,
                         sequence=delegation.get_sequence_out())
        self.enqueue(rpc=rpc)
class ActorIdentity(ABCActorIdentity):
    """
    Represent Actor Identity
    """
    def __init__(self, *, name: str, guid: ID):
        self.auth = AuthToken(name=name, guid=guid)

    def get_guid(self) -> ID:
        """
        Return guid
        @return guid
        """
        return self.auth.get_guid()

    def get_identity(self) -> AuthToken:
        """
        Return identity
        @return identity
        """
        return self.auth

    def get_name(self) -> str:
        return self.auth.get_name()
Ejemplo n.º 11
0
    def do_query(self, *, actor: ABCActorMixin, remote_actor: ABCActorProxy,
                 local_actor: ABCCallbackProxy, query: dict,
                 handler: ABCQueryResponseHandler, caller: AuthToken,
                 id_token: str):
        remote_actor.get_logger().info(
            "Outbound query request from <{}>".format(caller.get_name()))

        state = remote_actor.prepare_query(callback=local_actor,
                                           query=query,
                                           caller=caller,
                                           id_token=id_token)
        state.set_caller(caller=caller)
        state.set_type(rtype=RPCRequestType.Query)
        rpc = RPCRequest(request=state,
                         actor=actor,
                         proxy=remote_actor,
                         handler=handler)
        # Timer
        rpc.timer = KernelTimer.schedule(queue=actor,
                                         task=QueryTimeout(req=rpc),
                                         delay=self.QUERY_TIMEOUT_SECONDS)
        remote_actor.get_logger().info("Timer started: {} for Query".format(
            rpc.timer))
        self.enqueue(rpc=rpc)
Ejemplo n.º 12
0
class ClientCallbackHelper(ABCClientCallbackProxy):
    class MyRequestState(RPCRequestState):
        def __init__(self):
            super().__init__()
            self.reservation = None
            self.update_data = None

    def __init__(self, *, name: str, guid: ID):
        self.token = AuthToken(name=name, guid=guid)
        self.called = 0
        self.prepared = 0
        self.reservation = None

    def get_called(self) -> int:
        return self.called

    def get_guid(self) -> ID:
        return self.token.get_guid()

    def get_identity(self) -> AuthToken:
        return self.token

    def get_name(self) -> str:
        return self.token.get_name()

    def get_reservation(self) -> ABCReservationMixin:
        return self.reservation

    def get_type(self):
        return Constants.PROTOCOL_LOCAL

    def prepare_update_delegation(self, *, delegation: ABCDelegation, update_data: UpdateData,
                                  callback: ABCCallbackProxy, caller: AuthToken) -> ABCRPCRequestState:
        raise NotImplementedError

    def set_logger(self, *, logger):
        pass

    def prepare_update_ticket(self, *, reservation: ABCBrokerReservation, update_data: UpdateData,
                              callback: ABCCallbackProxy, caller: AuthToken) -> ABCRPCRequestState:
        state = self.MyRequestState()
        state.reservation = LocalReturn.pass_reservation(reservation=reservation,
                                                         plugin=ActorRegistrySingleton.get().get_actor(
                                                             actor_name_or_guid=self.token.get_name()).get_plugin())

        self.prepared += 1
        return state

    def execute(self, *, request: ABCRPCRequestState, producer: AvroProducerApi):
        if request.get_type() == RPCRequestType.UpdateTicket:
            self.called += 1
            self.reservation = request.reservation

    def get_logger(self):
        from fabric_cf.actor.core.container.globals import GlobalsSingleton
        return GlobalsSingleton.get().get_logger()

    def prepare_query_result(self, *, request_id: str, response, caller: AuthToken) -> ABCRPCRequestState:
        raise NotImplementedError

    def prepare_failed_request(self, *, request_id: str, failed_request_type,
                               failed_reservation_id: ID, error: str, caller: AuthToken) -> ABCRPCRequestState:
        raise NotImplementedError