def post(self): # Deserialize the body. Dying here with 500 is ok, it should not happen, so # if it is happening, it's nice to get an exception report. request = replication_pb2.ServiceLinkRequest.FromString(self.request.body) # Ensure the ticket was generated by us (by checking HMAC tag). ticket_data = None try: ticket_data = LinkTicketToken.validate(request.ticket, []) except tokens.InvalidTokenError: self.reply(replication_pb2.ServiceLinkResponse.BAD_TICKET) return # Ensure the ticket was generated for the calling application. replica_app_id = ticket_data['app_id'] expected_ident = auth.Identity(auth.IDENTITY_SERVICE, replica_app_id) if auth.get_current_identity() != expected_ident: self.reply(replication_pb2.ServiceLinkResponse.AUTH_ERROR) return # Register the replica. If it is already there, will reset its known state. replication.register_replica(replica_app_id, request.replica_url) self.reply(replication_pb2.ServiceLinkResponse.SUCCESS)