当前位置: 首页>>代码示例>>Python>>正文


Python KeyValuePair.get_by_scope_and_name方法代码示例

本文整理汇总了Python中st2common.persistence.keyvalue.KeyValuePair.get_by_scope_and_name方法的典型用法代码示例。如果您正苦于以下问题:Python KeyValuePair.get_by_scope_and_name方法的具体用法?Python KeyValuePair.get_by_scope_and_name怎么用?Python KeyValuePair.get_by_scope_and_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.persistence.keyvalue.KeyValuePair的用法示例。


在下文中一共展示了KeyValuePair.get_by_scope_and_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_kv

# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_scope_and_name [as 别名]
 def _get_kv(self, key):
     scope = self._scope
     LOG.debug('Lookup system kv: scope: %s and key: %s', scope, key)
     kvp = KeyValuePair.get_by_scope_and_name(scope=scope, name=key)
     if kvp:
         LOG.debug('Got value %s from datastore.', kvp.value)
     return kvp.value if kvp else ''
开发者ID:mahak,项目名称:st2,代码行数:9,代码来源:keyvalues.py

示例2: _get_kv

# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_scope_and_name [as 别名]
    def _get_kv(self, key):
        scope = self._scope

        try:
            kvp = KeyValuePair.get_by_scope_and_name(scope=scope, name=key)
        except StackStormDBObjectNotFoundError:
            kvp = None

        return kvp.value if kvp else ''
开发者ID:StackStorm,项目名称:st2,代码行数:11,代码来源:keyvalues.py

示例3: set_datastore_value_for_config_key

# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_scope_and_name [as 别名]
def set_datastore_value_for_config_key(pack_name, key_name, value, secret=False, user=None):
    """
    Set config value in the datastore.

    This function takes care of correctly encoding the key name, serializing the
    value, etc.

    :param pack_name: Pack name.
    :type pack_name: ``str``

    :param key_name: Config key name.
    :type key_name: ``str``

    :param secret: True if this value is a secret.
    :type secret: ``bool``

    :param user: Optional username if working on a user-scoped config item.
    :type user: ``str``

    :rtype: :class:`KeyValuePairDB`
    """

    if user:
        scope = USER_SCOPE
    else:
        scope = SYSTEM_SCOPE

    name = get_key_reference(scope=scope, name=key_name, user=user)

    kvp_api = KeyValuePairAPI(name=name, value=value, scope=scope, secret=secret)
    kvp_db = KeyValuePairAPI.to_model(kvp_api)

    # TODO: Obtain a lock
    existing_kvp_db = KeyValuePair.get_by_scope_and_name(scope=scope, name=name)
    if existing_kvp_db:
        kvp_db.id = existing_kvp_db.id

    kvp_db = KeyValuePair.add_or_update(kvp_db)
    return kvp_db
开发者ID:Bala96,项目名称:st2,代码行数:41,代码来源:config.py

示例4: get_key

# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_scope_and_name [as 别名]
def get_key(key=None, user_db=None, scope=None, decrypt=False):
    """
    Retrieve key from KVP store
    """
    if not isinstance(key, six.string_types):
        raise TypeError('Given key is not typeof string.')

    if not isinstance(decrypt, bool):
        raise TypeError('Decrypt parameter is not typeof bool.')

    if not user_db:
        # Use system user
        user_db = UserDB(cfg.CONF.system_user.user)

    scope, key_id = _derive_scope_and_key(key=key, user=user_db.name, scope=scope)
    scope = get_datastore_full_scope(scope)

    LOG.debug('get_key key_id: %s, scope: %s, user: %s, decrypt: %s' % (key_id, scope,
                                                                        str(user_db.name),
                                                                        decrypt))

    _validate_scope(scope=scope)

    rbac_utils = get_rbac_backend().get_utils_class()
    is_admin = rbac_utils.user_is_admin(user_db=user_db)

    # User needs to be either admin or requesting item for itself
    _validate_decrypt_query_parameter(decrypt=decrypt, scope=scope, is_admin=is_admin,
                                      user_db=user_db)

    # Get the key value pair by scope and name.
    kvp = KeyValuePair.get_by_scope_and_name(scope, key_id)

    # Decrypt in deserialize_key_value cannot handle NoneType.
    if kvp.value is None:
        return kvp.value

    return deserialize_key_value(kvp.value, decrypt)
开发者ID:StackStorm,项目名称:st2,代码行数:40,代码来源:keyvalue.py


注:本文中的st2common.persistence.keyvalue.KeyValuePair.get_by_scope_and_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。