Package ganeti :: Module serializer
[hide private]
[frames] | no frames]

Module serializer

source code

Serializer abstraction module

This module introduces a simple abstraction over the serialization backend (currently json).

Classes [hide private]
  Private
Wrap a value so it is hard to leak it accidentally.
  PrivateDict
A dictionary that turns its values to private fields.
Functions [hide private]
 
DumpJson(data, private_encoder=None)
Serialize a given object.
source code
 
LoadJson(txt)
Unserialize data from a string.
source code
 
WrapPrivateValues(json)
Crawl a JSON decoded structure for private values and wrap them.
source code
 
DumpSignedJson(data, key, salt=None, key_selector=None, private_encoder=None)
Serialize a given object and authenticate it.
source code
tuple of original data, string
LoadSignedJson(txt, key)
Verify that a given message was signed with the given key, and load it.
source code
 
LoadAndVerifyJson(raw, verify_fn)
Parses and verifies JSON data.
source code
 
Dump(data, private_encoder=None)
Serialize a given object.
source code
 
Load(txt)
Unserialize data from a string.
source code
 
DumpSigned(data, key, salt=None, key_selector=None, private_encoder=None)
Serialize a given object and authenticate it.
source code
tuple of original data, string
LoadSigned(txt, key)
Verify that a given message was signed with the given key, and load it.
source code
 
EncodeWithoutPrivateFields(obj) source code
 
EncodeWithPrivateFields(obj) source code
Variables [hide private]
  _RE_EOLSP = re.compile("[ \t]+$", re.MULTILINE)

Imports: re, simplejson, errors, utils, constants


Function Details [hide private]

DumpJson(data, private_encoder=None)

source code 

Serialize a given object.

Parameters:
  • data - the data to serialize
  • private_encoder - specify serializer.EncodeWithPrivateFields if you require the produced JSON to also contain private parameters. Otherwise, they will encode to null.
Returns:
the string representation of data

LoadJson(txt)

source code 

Unserialize data from a string.

Parameters:
  • txt - the json-encoded form
Returns:
the original data
Raises:
  • JSONDecodeError - if txt is not a valid JSON document

WrapPrivateValues(json)

source code 

Crawl a JSON decoded structure for private values and wrap them.

Parameters:
  • json - the json-decoded value to protect.

DumpSignedJson(data, key, salt=None, key_selector=None, private_encoder=None)

source code 

Serialize a given object and authenticate it.

Parameters:
  • data - the data to serialize
  • key - shared hmac key
  • key_selector - name/id that identifies the key (in case there are multiple keys in use, e.g. in a multi-cluster environment)
  • private_encoder - see DumpJson
Returns:
the string representation of data signed by the hmac key

LoadSignedJson(txt, key)

source code 

Verify that a given message was signed with the given key, and load it.

Parameters:
  • txt - json-encoded hmac-signed message
  • key - the shared hmac key or a callable taking one argument (the key selector), which returns the hmac key belonging to the key selector. Typical usage is to pass a reference to the get method of a dict.
Returns: tuple of original data, string
original data, salt
Raises:

LoadAndVerifyJson(raw, verify_fn)

source code 

Parses and verifies JSON data.

Parameters:
  • raw (string) - Input data in JSON format
  • verify_fn (callable) - Verification function, usually from ht
Returns:
De-serialized data

Dump(data, private_encoder=None)

source code 

Serialize a given object.

Parameters:
  • data - the data to serialize
  • private_encoder - specify serializer.EncodeWithPrivateFields if you require the produced JSON to also contain private parameters. Otherwise, they will encode to null.
Returns:
the string representation of data

Load(txt)

source code 

Unserialize data from a string.

Parameters:
  • txt - the json-encoded form
Returns:
the original data
Raises:
  • JSONDecodeError - if txt is not a valid JSON document

DumpSigned(data, key, salt=None, key_selector=None, private_encoder=None)

source code 

Serialize a given object and authenticate it.

Parameters:
  • data - the data to serialize
  • key - shared hmac key
  • key_selector - name/id that identifies the key (in case there are multiple keys in use, e.g. in a multi-cluster environment)
  • private_encoder - see DumpJson
Returns:
the string representation of data signed by the hmac key

LoadSigned(txt, key)

source code 

Verify that a given message was signed with the given key, and load it.

Parameters:
  • txt - json-encoded hmac-signed message
  • key - the shared hmac key or a callable taking one argument (the key selector), which returns the hmac key belonging to the key selector. Typical usage is to pass a reference to the get method of a dict.
Returns: tuple of original data, string
original data, salt
Raises: