Ejemplo n.º 1
0
    def get_business_party(self, key):
        """
        Gets the business party from redis or the party service

        :param key: Key in redis (for this example will be a frontstage:business-party:id)
        :return: Result from either the cache or party service
        """
        redis_key = f"frontstage:business-party:{key}"
        try:
            result = redis.get(redis_key)
        except RedisError:
            logger.error("Error getting value from cache, please investigate",
                         key=redis_key,
                         exc_info=True)
            result = None

        if not result:
            logger.info("Key not in cache, getting value from party service",
                        key=redis_key)
            result = get_party_by_business_id(key, app.config["PARTY_URL"],
                                              app.config["BASIC_AUTH"])
            self.save(redis_key, result, self.BUSINESS_PARTY_CATEGORY_EXPIRY)
            return result

        return json.loads(result.decode("utf-8"))
Ejemplo n.º 2
0
    def get_collection_instrument(self, key):
        """
        Gets the collection-instrument from redis or the collection-instrument service

        :param key: Key in redis (for this example will be a frontstage:collection-instrument:id)
        :return: Result from either the cache or collection instrument service
        """
        redis_key = f"frontstage:collection-instrument:{key}"
        try:
            result = redis.get(redis_key)
        except RedisError:
            logger.error("Error getting value from cache, please investigate",
                         key=redis_key,
                         exc_info=True)
            result = None

        if not result:
            logger.info(
                "Key not in cache, getting value from collection instrument service",
                key=redis_key)
            result = get_collection_instrument(
                key, app.config["COLLECTION_INSTRUMENT_URL"],
                app.config["BASIC_AUTH"])
            self.save(redis_key, result,
                      self.COLLECTION_INSTRUMENT_CATEGORY_EXPIRY)
            return result

        return json.loads(result.decode("utf-8"))
Ejemplo n.º 3
0
 def from_session_key(cls, session_key):
     # Redis client throws an error if you try to .get(None)
     if session_key is None:
         encoded_jwt_token = None
     else:
         encoded_jwt_token = redis.get(session_key)
     session = cls(session_key, encoded_jwt_token)
     session.persisted = True
     return session
    def test_delete_session(self):
        # Create session and get session key
        session = Session.from_party_id("party")
        session.save()
        session_key = session.session_key
        session.delete_session()

        session = redis.get(session_key)

        self.assertEqual(session, None)
Ejemplo n.º 5
0
    def test_delete_session(self):
        # Create session and get session key
        session = SessionHandler()
        session.create_session(encoded_jwt='test_jwt')
        session_key = session.session_key
        session.delete_session(session_key)

        session = redis.get(session_key)

        self.assertEqual(session, None)
Ejemplo n.º 6
0
 def from_session_key(cls, session_key):
     encoded_jwt_token = redis.get(session_key)
     session = cls(session_key, encoded_jwt_token)
     session.persisted = True
     return session
Ejemplo n.º 7
0
 def get_encoded_jwt(self, session_key):
     self.session_key = session_key
     self.encoded_jwt = redis.get(self.session_key)
     return self.encoded_jwt