ConfigurationMixin#

class ConfigurationMixin#

Bases: object

Methods Summary

delete_project_configuration(project_id, key)

Delete the given configuration key from the project namespace.

delete_server_configuration(key)

Deletes the given configuration key from the server namespace.

get_project_configuration(project_id[, ...])

Return all configuration service values from the project namespace.

get_server_configuration()

Return all configuration service values from the server namespace.

interpolate_project_configuration(...)

Return project configuration values for the given config references.

set_project_configuration(project_id, key, value)

Set the given configuration key to the provided value in the project namespace.

set_server_configuration(key, value[, type])

Sets the given configuration key to the provided value in the server namespace.

Methods Documentation

delete_project_configuration(project_id, key)#

Delete the given configuration key from the project namespace.

For built-in values, the value will be reset to the default. In that case the newly valid configuration dictionary is returned.

For custom values, the value will be deleted irrevocably. Empty dictionary is returned for this.

Parameters
  • project_id (str) – Project ID.

  • key (str) – The key of the setting to delete.

Returns

Empty dictionary for custom values, new entry with default values for built-in values.

Example:

>>> c.delete_project_configuration(project_id='d_GZJjMiVgKHHf6-pFWzNQ', key='topic.typeahead.popular.scope')
{
    'key': 'topic.typeahead.popular.scope',
    'value': 'user',
    'default_value': 'user,
    'type': 'string',
    'help': 'A scope for popular queries (user/project).',
    'delete': 'noop',
    'schema': None,
    'schema_model': None
}
delete_server_configuration(key)#

Deletes the given configuration key from the server namespace.

For built-in values, the value will be reset to the default. In that case the newly valid configuration dictionary is returned.

For custom values, the value will be deleted irrevocably. None is returned for this.

Parameters

key – The key of the setting to delete.

Returns

None for custom values, new entry with default values for built-in values.

Example:

>>> c.delete_server_configuration('topic.custom-locator')
{
    'key': 'topic.custom-locator',
    'value': False,
    'default_value': False,
    'type': 'boolean',
    'help': 'Whether custom index locators can be defined on Squirro projects.',
    'delete': 'noop',
    'schema': None,
    'schema_model': None
}

>>> c.set_server_configuration(key='user.create', value=False)
{
    'namespace': 'server',
    'scope': None,
    'key': 'user.create',
    'value': False,
    'default_value': True,
    'type': 'boolean',
    'help': 'Whether new users can be created on this system.',
    'delete': 'reset',
    'schema': None,
    'schema_model': None
}
get_project_configuration(project_id, exclude_read_only_and_license=False)#

Return all configuration service values from the project namespace.

Parameters
  • project_id (str) – Project ID.

  • exclude_read_only_and_license (bool) – Whether to exclude read-only and license settings from the response. Defaults to False.

Returns

Returns a dictionary with the returned data and configuration. The relevant keys in the returned dictionary are:

  • cache_ttl: The number of seconds this response can be cached. This can be changed by modifying the value of the config.cache-ttl key.

  • namespace: Always set to project.

  • scope: Project ID

  • config: A dictionary mapping the configuration keys to their data. The keys in this sub-dictionary are:

    • value: The current value of the setting.

    • default_value: The original default value of the setting. This is None for all user-defined settings.

    • type: The type. Can be boolean, string, numeric, or dictionary.

    • delete: What will happen when the deletion is called on this method.

      • reset: The project default value will be restored.

      • noop: Nothing will happen, as the value is equivalent to the project default.

      • delete: The setting will be removed, meaning it was a user-defined setting.

    • help: The help text displayed to the user on config editing.

Example:

>>> client.get_project_configuration(project_id='d_GZJjMiVgKHHf6-pFWzNQ')
{
    'cache_ttl': 60,
    'namespace': 'project',
    'scope': 'd_GZJjMiVgKHHf6-pFWzNQ',
    'config': {
        'topic.typeahead.popular.scope': {
            'value': 'user',
            'default_value': 'user',
            'type': 'string',
            'delete': 'reset',
            'help': 'A scope for popular queries (user/project).',
            'schema': None,
            'schema_model': None
        },
    },
    # …
}
get_server_configuration()#

Return all configuration service values from the server namespace.

Returns

Returns a dictionary with the returned data and configuration. The relevant keys in the returned dictionary are:

  • cache_ttl: the number of seconds this response can be cached. This can be changed by modifying the value of the config.cache-ttl key.

  • namespace: always set to server.

  • scope: always empty (None)

  • config: a dictionary mapping the configuration keys to their data. The keys in this sub-dictionary are:

    • value: the current value of the setting.

    • default_value: the original default value of the setting. This is None for all user-defined settings.

    • type: The type. Can be boolean, string, numeric, or dictionary.

    • delete: what will happen when the deletion is called on this method.

      • reset: the server default value will be restored.

      • noop: nothing will happen, as the value is equivalent to the server default.

      • delete: the setting will be removed, meaning it was a user-defined setting.

    • help: The help text displayed to the user on config editing.

Example:

>>> client.get_server_configuration()
{
    'cache_ttl': 60,
    'namespace': 'server',
    'scope': None,
    'config': {
        'user.create': {
            'value': False,
            'default_value': True,
            'type': 'boolean',
            'delete': 'reset',
            'help': 'Whether new users can be created on this sytemn.',
            'schema': None,
            'schema_model': None
        },
    },
    # …
}
interpolate_project_configuration(project_id, value)#

Return project configuration values for the given config references.

Parameters
  • project_id (str) – Project ID.

  • value (Any) – Value to interpolate.

Returns

Returns a dictionary contains an interpolated value.

Example:

>>> client.interpolate_project_configuration(
      project_id='d_GZJjMiVgKHHf6-pFWzNQ',
      value='${topic.snow-url}'
    )
{
    'value': 'https://mysnow.com',
}
set_project_configuration(project_id, key, value, type=None)#

Set the given configuration key to the provided value in the project namespace.

Parameters
  • project_id (str) – Project ID.

  • key (str) – The key of the setting to overwrite or define. If the key exists, the existing value is changed. Otherwise a new one is created.

  • value (Union[str, int, bool, dict]) – The value of the setting. Can be a string, number (int), boolean, or dictionary.

  • type (Optional[str]) – The type of the value. If this is not provided, the type is automatically inferred from the value. If provided, the type must be the same as the value type, and for built-in settings must be the same as the default type. Valid types are: boolean, string, numeric, dictionary.

Returns

Returns a dictionary with the new data of the setting. The keys are:

  • namespace: Always set to project.

  • scope: Project ID

  • value: The current value of the setting.

  • default_value: The original default value of the setting. This is None for all user-defined settings.

  • type: The type. Can be boolean, string, numeric, or dictionary.

  • delete: What will happen when the deletion is called on this method.

    • reset: The project default value will be restored.

    • noop: Nothing will happen, as the value is equivalent to the project default.

    • delete: The setting will be removed, meaning it was a user-defined setting.

  • help: The help text displayed to the user on config editing.

Example:

>>> c.set_project_configuration(project_id='d_GZJjMiVgKHHf6-pFWzNQ', key='topic.typeahead.popular.scope', value='project')
{
    'namespace': 'project',
    'scope': 'd_GZJjMiVgKHHf6-pFWzNQ',
    'key': 'topic.typeahead.popular.scope',
    'value': 'project',
    'default_value': 'user',
    'type': 'string',
    'help': 'A scope for popular queries (user/project).',
    'delete': 'reset',
    'schema': None,
    'schema_model': None
}
set_server_configuration(key, value, type=None)#

Sets the given configuration key to the provided value in the server namespace.

Parameters
  • key – The key of the setting to overwrite or define. If the key exists, the existing value is changed. Otherwise a new one is created.

  • value – The value of the value. Can be a string, number (int), boolean, or dictionary.

  • type

    The type of the value. If this is not provided, the type is automatically inferred from the value. If provided, the type must be the same as the value type, and for built-in settings but be the same as the default type.

    Valid types are: boolean, string, numeric, dictionary.

Returns

Returns a dictionary with the new data of the setting. The keys are:

  • namespace: always set to server.

  • scope: always empty (None)

  • value: the current value of the setting.

  • default_value: the original default value of the setting. This is None for all user-defined settings.

  • type: The type. Can be boolean, string, numeric, or dictionary.

  • delete: what will happen when the deletion is called on this method.

    • reset: the server default value will be restored.

    • noop: nothing will happen, as the value is equivalent to the server default.

    • delete: the setting will be removed, meaning it was a user-defined setting.

  • help: The help text displayed to the user on config editing.

Example:

>>> c.set_server_configuration(key='user.create', value=False)
{
    'namespace': 'server',
    'scope': None,
    'key': 'user.create',
    'value': False,
    'default_value': True,
    'type': 'boolean',
    'help': 'Whether new users can be created on this system.',
    'delete': 'reset',
    'schema': None,
    'schema_model': None
}