Beispiel #1
0
def build_mysql_config(mysql_config):
    """Given a standard Holland [mysql:client] section build an in-memory
    config that represents the auth parameters, including those merged in from
    *defaults-extra-files*

    :param mysql_config: required.  This should be a dict object with the
                         zero or more of the following keys:
                           user (string)
                           password (string)
                           host (string)
                           socket (string)
                           port (integer)
                           defaults-extra-file (list)
    :type mysql_config: dict
    """
    defaults_config = ConfigObj()
    defaults_config['client'] = {}
    for config in mysql_config['defaults-extra-file']:
        LOG.info("Loading %s [%s]", config, os.path.expanduser(config))
        _my_config = load_options(config)
        defaults_config.update(_my_config)

    for key in ('user', 'password', 'socket', 'host', 'port'):
        if key in mysql_config and mysql_config[key]:
            defaults_config['client'][key] = mysql_config[key]
    return defaults_config
Beispiel #2
0
def write_options(config, filename):
    quoted_config = ConfigObj(list_values=False)
    quoted_config.update(config)

    if isinstance(filename, basestring):
        filename = codecs.open(filename, 'w', 'utf8')
    quoted_config.write(filename)
    filename.close()
Beispiel #3
0
def merge_options(path,
                  *defaults_files,
                  **kwargs):
    defaults_config = ConfigObj(list_values=False)
    defaults_config['client'] = {}
    for config in defaults_files:
        _my_config = load_options(config)
        defaults_config.update(_my_config)

    for key in ('user', 'password', 'socket', 'host', 'port'):
        if kwargs.get(key) is not None:
            defaults_config['client'][key] = kwargs[key]
    write_options(defaults_config, path)
Beispiel #4
0
def client_keys(config):
    """Create a copy of option_section with non-authentication options
    stripped out.

    Authentication options supported are:
    user, password, host, port, and socket
    """
    clean_namespace = ConfigObj(list_values=False)
    clean_namespace.update(config)
    valid_keys = ['user', 'password', 'host', 'port', 'socket']
    for key in config:
        if key not in valid_keys:
            del clean_namespace[key]
        else:
            clean_namespace[key] = unquote(config[key])
    return clean_namespace