Пример #1
0
    def create_message(self, payload):
        """
        Creates a Message object.

        :param payload: A dictionary of values to save to the database.
        :return: The newly created Message object.
        """

        try:
            message = self.post(payload, path=BEAKER_API_PATHS['MESSAGES'])
        except RequestException:
            log.exception("Error while attempting to save Message information.")
            raise IOError()

        if not message.get('id'):
            return None

        message_id = message.get('id')
        service_message_id = message.get('service_message_id')

        # We are also going to include a signed JWT in the response.
        # This 'Signed ID' will be placed in the final message header,
        # and will be tamper evident.
        claims = {
            'i': message_id,
            's': service_message_id,
        }
        message["signed_id"] = jwt.encode_jwt(claims, version=1)
        return message
Пример #2
0
    def create_message(self, payload):
        """
        Creates a Message object.

        :param payload: A dictionary of values to save to the database.
        :return: The newly created Message object.
        """

        try:
            message = self.post(payload, path=BEAKER_API_PATHS['MESSAGES'])
        except RequestException:
            log.exception(
                "Error while attempting to save Message information.")
            raise IOError()

        if not message.get('id'):
            return None

        message_id = message.get('id')
        service_message_id = message.get('service_message_id')

        # We are also going to include a signed JWT in the response.
        # This 'Signed ID' will be placed in the final message header,
        # and will be tamper evident.
        claims = {
            'i': message_id,
            's': service_message_id,
        }
        message["signed_id"] = jwt.encode_jwt(claims, version=1)
        return message
Пример #3
0
    def create_url_from_link_id(self, link_id, url):
        """
        Generates the url that the link server will serve for the link.

        :param link_id: The link ID to create a final URL for.
        :param url: The final URL to redirect the user to.
        :return: The final, valid URL to be served by the link server.
        """

        claims = {
            # These are short to keep the JWT small.
            'i': link_id,
            'u': url,
        }
        link_jwt = jwt.encode_jwt(claims, version=1)
        link_url = "%s%s/" % (self.link_server, link_jwt)

        return link_url
Пример #4
0
    def create_url_from_link_id(self, link_id, url):
        """
        Generates the url that the link server will serve for the link.

        :param link_id: The link ID to create a final URL for.
        :param url: The final URL to redirect the user to.
        :return: The final, valid URL to be served by the link server.
        """

        claims = {
            # These are short to keep the JWT small.
            'i': link_id,
            'u': url,
        }
        link_jwt = jwt.encode_jwt(claims, version=1)
        link_url = "%s%s/" % (self.link_server, link_jwt)

        return link_url