def delete_value(self, name, local=True): """ Delete the provided key. By default, value is deleted from a namespace local to the pack/class. If you want to delete a global value, pass local=False to this method. :param name: Name of the key to delete. :type name: ``str`` :param local: Delete a value in a namespace local to the pack/class. Defaults to True. :type: local: ``bool`` :return: ``True`` on success, ``False`` otherwise. :rtype: ``bool`` """ name = self._get_full_key_name(name=name, local=local) client = self._get_api_client() instance = KeyValuePair() instance.id = name instance.name = name self._logger.audit('Deleting value from the datastore (name=%s)', name) try: client.keys.delete(instance=instance) except Exception: return False return True
def set_value(self, name, value, ttl=None, local=True, scope=SYSTEM_SCOPE, encrypt=False): """ Set a value for the provided key. By default, value is set in a namespace local to the pack/class. If you want to set a global value, pass local=False to this method. :param name: Key name. :type name: ``str`` :param value: Key value. :type value: ``str`` :param ttl: Optional TTL (in seconds). :type ttl: ``int`` :param local: Set value in a namespace local to the pack/class. Defaults to True. :type: local: ``bool`` :param scope: Scope under which to place the item. Defaults to system scope. :type: local: ``str`` :param encrypt: Encrypt the value when saving. Defaults to False. :type: local: ``bool`` :return: ``True`` on success, ``False`` otherwise. :rtype: ``bool`` """ if scope != SYSTEM_SCOPE: raise ValueError('Scope %s is unsupported.', scope) name = self._get_full_key_name(name=name, local=local) value = str(value) client = self._get_api_client() self._logger.audit('Setting value in the datastore (name=%s)', name) instance = KeyValuePair() instance.id = name instance.name = name instance.value = value instance.scope = scope if encrypt: instance.secret = True if ttl: instance.ttl = ttl client.keys.update(instance=instance) return True
def set_value(self, name, value, ttl=None, local=True, scope=SYSTEM_SCOPE, encrypt=False): """ Set a value for the provided key. By default, value is set in a namespace local to the pack/class. If you want to set a global value, pass local=False to this method. :param name: Key name. :type name: ``str`` :param value: Key value. :type value: ``str`` :param ttl: Optional TTL (in seconds). :type ttl: ``int`` :param local: Set value in a namespace local to the pack/class. Defaults to True. :type: local: ``bool`` :param scope: Scope under which to place the item. Defaults to system scope. :type: local: ``str`` :param encrypt: Encrypt the value when saving. Defaults to False. :type: local: ``bool`` :return: ``True`` on success, ``False`` otherwise. :rtype: ``bool`` """ if scope != SYSTEM_SCOPE: raise ValueError('Scope %s is unsupported.' % scope) name = self._get_full_key_name(name=name, local=local) value = str(value) client = self.get_api_client() self._logger.debug('Setting value in the datastore (name=%s)', name) instance = KeyValuePair() instance.id = name instance.name = name instance.value = value instance.scope = scope if encrypt: instance.secret = True if ttl: instance.ttl = ttl client.keys.update(instance=instance) return True
def delete_value(self, name, local=True, scope=SYSTEM_SCOPE): """ Delete the provided key. By default, value is deleted from a namespace local to the pack/class. If you want to delete a global value, pass local=False to this method. :param name: Name of the key to delete. :type name: ``str`` :param local: Delete a value in a namespace local to the pack/class. Defaults to True. :type: local: ``bool`` :param scope: Scope under which item is saved. Defaults to system scope. :type: local: ``str`` :return: ``True`` on success, ``False`` otherwise. :rtype: ``bool`` """ if scope != SYSTEM_SCOPE: raise ValueError('Scope %s is unsupported.' % scope) name = self._get_full_key_name(name=name, local=local) client = self.get_api_client() instance = KeyValuePair() instance.id = name instance.name = name self._logger.debug('Deleting value from the datastore (name=%s)', name) try: params = {'scope': scope} client.keys.delete(instance=instance, params=params) except Exception as e: self._logger.exception( 'Exception deleting value from datastore (name=%s): %s', name, e ) return False return True
def set_value(self, name, value, ttl=None, local=True): """ Set a value for the provided key. By default, value is set in a namespace local to the pack/class. If you want to set a global value, pass local=False to this method. :param name: Key name. :type name: ``str`` :param value: Key value. :type value: ``str`` :param ttl: Optional TTL (in seconds). :type ttl: ``int`` :param local: Set value in a namespace local to the pack/class. Defaults to True. :type: local: ``bool`` :return: ``True`` on success, ``False`` otherwise. :rtype: ``bool`` """ name = self._get_full_key_name(name=name, local=local) value = str(value) client = self._get_api_client() self._logger.audit('Setting value in the datastore (name=%s)', name) instance = KeyValuePair() instance.id = name instance.name = name instance.value = value if ttl: instance.ttl = ttl client.keys.update(instance=instance) return True