Return a jira.client.JIRA.__init__() compatible dictionary from data in the Flask config.

    Generate a dictionary compatible with jira.client.JIRA.__init__() keyword arguments from data in the Flask
    application's configuration values relevant to JIRA. If both basic and OAuth settings are specified, OAuth
    authentication takes precedence.

    Usage:
    config = read_config(app.config, prefix)
    jira = JIRA(**config)

    Positional arguments:
    config -- Flask application config dictionary.
    prefix -- Prefix used in config key names in the Flask app's configuration.

    Returns:
    Dictionary with parsed data, compatible with jira.client.JIRA.__init__() keyword arguments.

def read_config(config, prefix):
    """Return a jira.client.JIRA.__init__() compatible dictionary from data in the Flask config.

    Generate a dictionary compatible with jira.client.JIRA.__init__() keyword arguments from data in the Flask
    application's configuration values relevant to JIRA. If both basic and OAuth settings are specified, OAuth
    authentication takes precedence.

    Usage:
    config = read_config(app.config, prefix)
    jira = JIRA(**config)

    Positional arguments:
    config -- Flask application config dictionary.
    prefix -- Prefix used in config key names in the Flask app's configuration.

    Returns:
    Dictionary with parsed data, compatible with jira.client.JIRA.__init__() keyword arguments.
    """
    # Get all relevant config values from Flask application.
    suffixes = ('SERVER', 'USER', 'PASSWORD', 'TOKEN', 'SECRET', 'CONSUMER', 'CERT')
    config_server, config_user, config_password, config_token, config_secret, config_consumer, config_cert = [
        config.get('{0}_{1}'.format(prefix, suffix)) for suffix in suffixes
    ]
    result = dict(options=dict(server=config_server))
    # Gather authentication data.
    basic = (config_user, config_password)
    oauth = dict(
        access_token=config_token,
        access_token_secret=config_secret,
        consumer_key=config_consumer,
        key_cert=config_cert,
    )
    # Apply authentication data.
    if any(oauth.values()):
        result['oauth'] = oauth
    elif all(basic):
        result['basic_auth'] = basic
    else:
        raise ValueError('No/incomplete JIRA authentication settings specified in the Flask config.')
    # Done.
    return result