예제 #1
0
파일: keyvalues.py 프로젝트: wingiti/st2
    def _get(self, name):
        # get the value for this key and save in value_cache
        if self._key_prefix:
            key = "%s.%s" % (self._key_prefix, name)
        else:
            key = UserKeyReference(name=name, user=self._user).ref

        if self._prefix:
            kvp_key = DATASTORE_KEY_SEPARATOR.join([self._prefix, key])
        else:
            kvp_key = key

        value = self._get_kv(kvp_key)
        self._value_cache[key] = value
        # return a KeyValueLookup as response since the lookup may not be complete e.g. if
        # the lookup is for 'key_base.key_value' it is likely that the calling code, e.g. Jinja,
        # will expect to do a dictionary style lookup for key_base and key_value as subsequent
        # calls. Saving the value in cache avoids extra DB calls.
        return UserKeyValueLookup(
            prefix=self._prefix,
            user=self._user,
            key_prefix=key,
            cache=self._value_cache,
            scope=self._scope,
        )
예제 #2
0
파일: keyvalues.py 프로젝트: mahak/st2
    def _get(self, name):
        # get the value for this key and save in value_cache
        if self._key_prefix:
            key = '%s.%s' % (self._key_prefix, name)
        else:
            key = UserKeyReference(name=name, user=self._user).ref

        if self._prefix:
            kvp_key = DATASTORE_KEY_SEPARATOR.join([self._prefix, key])
        else:
            kvp_key = key

        value = self._get_kv(kvp_key)
        self._value_cache[key] = value
        # return a KeyValueLookup as response since the lookup may not be complete e.g. if
        # the lookup is for 'key_base.key_value' it is likely that the calling code, e.g. Jinja,
        # will expect to do a dictionary style lookup for key_base and key_value as subsequent
        # calls. Saving the value in cache avoids extra DB calls.
        return UserKeyValueLookup(prefix=self._prefix, user=self._user, key_prefix=key,
                                  cache=self._value_cache, scope=self._scope)