Table Of Contents

Previous topic

9. Plugin SDK services

Next topic

9.2. Logging

9.1. PluginConfiguration

The PluginConfiguration service implements parsing and accessing the textual configuration set for plugin instances. The API is built on Python configparser.ConfigParser module with some additional functionality.

class safeguard.sessions.plugin.plugin_configuration.PluginConfiguration(configuration, defaults=None)

The PluginConfiguration class represents the plugin configuration service.

Parameters
  • configuration (str) – runtime configuration

  • defaults (str) – design time configuration defaults

get(section, option, default=None, required=False)

The get() method returns a configuration option as a string value. If the value of the option is $ the secret identified by the section and option pair is retrieved from the configured credential store

Parameters
  • section (str) – which [section] to search

  • option (str) – which option to get

  • default – return value if section or option is not present

  • required (boolean) – whether to throw an exception on missing option

Returns

the value of the option or None

Return type

str

Raises

RequiredConfigurationSettingNotFound

get_key(section, option, required=False)

The get_key() method returns a configuration option as string value. If the value of the option is $ the certificate identified by the section and option pair is retrieved from the configured credential store When the private key is given in the configuration it should be in PEM format and key should not be encrypted and all the new lines must be indentet with one whitespace

Example configuration:

[foo]
private_key = -----BEGIN RSA PRIVATE KEY-----
 key
 identified
 -----END RSA PRIVATE KEY-----
Parameters
  • section (str) – which [section] to search

  • option (str) – which option to get

  • required (boolean) – whether to throw an exception on missing option

Returns

private key and type parsed as dict

Return type

dict

Raises

RequiredConfigurationSettingNotFound

Raises

Pluginsdkvalueerror

get_certificate(section, option, required=False)

The get_certificate() method returns a configuration option as a dict value. If the value of the option is $ the certificate identified by the section and option pair is retrieved from the configured credential store When the certificate and private key is given in the configuration it should be in PEM format and all the new lines must be indentet with one whitespace

Example configuration:

[foo]
certificate = -----BEGIN CERTIFICATE-----
 cert
 -----END CERTIFICATE-----
 -----BEGIN RSA PRIVATE KEY-----
 key
 -----END RSA PRIVATE KEY-----
Parameters
  • section (str) – which [section] to search

  • option (str) – which option to get

  • required (boolean) – whether to throw an exception on missing option

Returns

private key, certificate and type parsed as dict

Return type

dict

Raises

RequiredConfigurationSettingNotFound

Raises

Pluginsdkvalueerror

getboolean(section, option, default=None, required=False)

The getboolean() method returns the boolean value of a configuration option. The configuration option may have the values “yes” and “no” or their upper case variants. In case of invalid value, a PluginSDKValueError exception is raised.

Parameters
  • section (str) – which [section] to search

  • option (str) – which option to get

  • default – value if section or option is not present

  • required (boolean) – whether to throw exception on missing option

Returns

the value of the option or None

Return type

boolean

Raises

RequiredConfigurationSettingNotFound

Raises

PluginSDKValueError

getint(section, option, default=None, required=False)

The getint() method returns the integer value of a configuration option. If the configuration option cannot be converted to an integer value, then a PluginSDKValueError exception is raised.

Parameters
  • section (str) – which [section] to search

  • option (str) – which option to get

  • default – value if section or option is not present

  • required (boolean) – whether to throw exception on missing option

Returns

the value of the option or None

Return type

int

Raises

RequiredConfigurationSettingNotFound

Raises

PluginSDKValueError

getfloat(section, option, default=None, required=False)

The getfloat() method returns the floating point value of a configuration option. If the configuration option cannot be converted to a floating point value, then a PluginSDKValueError exception is raised.

Parameters
  • section (str) – which [section] to search

  • option (str) – which option to get

  • default – value if section or option is not present

  • required (boolean) – whether to throw exception on missing option

Returns

the value of the option or None

Return type

float

Raises

RequiredConfigurationSettingNotFound

Raises

PluginSDKValueError

getienum(section, option, value_set, default=None, required=False)

The getienum() method returns the value of an option that may only assume certain lower case string values. In other words the lower case value of the configuration option is checked against a list of possible values. In case the configuration value is not one of the allowed values, then a PluginSDKValueError exception is raised.

from safeguard.sessions.plugin import PluginConfiguration

config = PluginConfiguration("""
                      [foobar]
                      color1 = LightGreen
                      color2 = LightBlue
                       """)

# next line is ok, returns 'lightgreen'
config.getienum('foobar', 'color1', ('green', 'lightgreen'))

# next line throws PluginSDKValueError exception
config.getienum('foobar', 'color2', ('green', 'lightgreen'))
Parameters
  • section (str) – which [section] to search

  • option (str) – which option to get

  • value_set (seq) – a container of possible lower case values (the container should implement the in operator)

  • default (str) – value if section or option is not present

  • required (boolean) – whether to throw exception on missing option

Returns

the value of the option or None

Return type

str

Raises

RequiredConfigurationSettingNotFound

Raises

PluginSDKValueError

9.1.1. Exceptions

exception safeguard.sessions.plugin.plugin_configuration_exceptions.RequiredConfigurationSettingNotFound(message, variables=None)

The RequiredConfigurationSettingNotFound excpetion is raised when a required configuration option is not present when requested by the plugin.