The keystone.common.utils Module

class keystone.common.utils.LimitingReader(data, limit)

Bases: object

Reader to limit the size of an incoming request.

read()
class keystone.common.utils.SmarterEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)

Bases: json.encoder.JSONEncoder

Help for JSON encoding dict-like objects.

default(obj)
keystone.common.utils.auth_str_equal(provided, known)

Constant-time string comparison.

Params provided:
 the first string
Params known:the second string
Returns:True if the strings are equal.

This function takes two strings and compares them. It is intended to be used when doing a comparison for authentication purposes to help guard against timing attacks. When using the function for this purpose, always provide the user-provided password as the first argument. The time this function will take is always a factor of the length of this string.

keystone.common.utils.check_output(*popenargs, **kwargs)

Run command with arguments and return its output as a byte string.

If the exit code was non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and output in the output attribute.

The arguments are the same as for the Popen constructor. Example:

>>> check_output(['ls', '-l', '/dev/null'])
'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'

The stdout argument is not allowed as it is used internally. To capture standard error in the result, use stderr=STDOUT.

>>> check_output(['/bin/sh', '-c',
...               'ls -l non_existent_file ; exit 0'],
...              stderr=STDOUT)
'ls: non_existent_file: No such file or directory\n'
keystone.common.utils.check_password(password, hashed)

Check that a plaintext password matches hashed.

hashpw returns the salt value concatenated with the actual hash value. It extracts the actual salt if this value is then passed as the salt.

keystone.common.utils.git(*args)
keystone.common.utils.hash_ldap_user_password(user)

Hash a user dict’s password without modifying the passed-in dict

keystone.common.utils.hash_password(password)

Hash a password. Hard.

keystone.common.utils.hash_signed_token(signed_text)
keystone.common.utils.hash_user_password(user)

Hash a user dict’s password without modifying the passed-in dict

keystone.common.utils.ldap_check_password(password, hashed)
keystone.common.utils.ldap_hash_password(password)

Hash a password. Hard.

keystone.common.utils.read_cached_file(filename, cache_info, reload_func=None)

Read from a file if it has been modified.

Parameters:
  • cache_info – dictionary to hold opaque cache.
  • reload_func – optional function to be called with data when file is reloaded due to a modification.
Returns:

data from file.

keystone.common.utils.setup_remote_pydev_debug()
keystone.common.utils.trunc_password(password)

Truncate passwords to the MAX_PASSWORD_LENGTH.

keystone.common.utils.unixtime(dt_obj)

Format datetime object as unix timestamp

Parameters:dt_obj – datetime.datetime object
Returns:float

Previous topic

The keystone.common.systemd Module

Next topic

The keystone.common.wsgi Module

This Page