def save_settings(file_path, record_details, overwrite=False, secret_key=''):
    """ a method to save dictionary typed data to a local file

    :param file_path: string with path to settings file
    :param record_details: dictionary with record details
    :param overwrite: [optional] boolean to overwrite existing file data
    :param secret_key: [optional] string with key to decrypt drep file
    :return: string with file path
    """
    title = 'save_settings'
    try:
        _path_arg = '%s(file_path=%s)' % (title, str(file_path))
    except:
        raise ValueError('%s(file_path=...) must be a string.' % title)
    _details_arg = '%s(record_details={...})' % title
    if not isinstance(record_details, dict):
        raise ValueError('%s must be a dictionary.' % _details_arg)
    if secret_key:
        try:
            _secret_arg = '%s(secret_key=%s)' % (title, str(secret_key))
        except:
            raise ValueError('%s(secret_key=...) must be a string.' % title)
    ext_map = {}
    file_extensions = {'json': '.+\\.json$', 'json.gz': '.+\\.json\\.gz$',
        'yaml': '.+\\.ya?ml$', 'yaml.gz': '.+\\.ya?ml\\.gz$', 'drep':
        '.+\\.drep$'}
    import re
    for key, value in file_extensions.items():
        file_pattern = re.compile(value)
        if file_pattern.findall(file_path):
            ext_map[key] = True
        else:
            ext_map[key] = False
    file_time = 0
    file_data = ''.encode('utf-8')
    if ext_map['json']:
        import json
        file_data = json.dumps(record_details, indent=2).encode('utf-8')
    elif ext_map['yaml']:
        import yaml
        file_data = yaml.dump(record_details).encode('utf-8')
    elif ext_map['json.gz']:
        import json
        import gzip
        file_bytes = json.dumps(record_details).encode('utf-8')
        file_data = gzip.compress(file_bytes)
    elif ext_map['yaml.gz']:
        import yaml
        import gzip
        file_bytes = yaml.dump(record_details).encode('utf-8')
        file_data = gzip.compress(file_bytes)
    elif ext_map['drep']:
        from labpack.compilers import drep
        file_data = drep.dump(record_details, secret_key)
        file_time = 1
    else:
        raise ValueError('%s must be one of %s file types.' % (_path_arg,
            list(ext_map.keys())))
    import os
    if not overwrite:
        if os.path.exists(file_path):
            raise Exception(
                '%s already exists. To overwrite %s, set overwrite=True' %
                (_path_arg, _path_arg))
    dir_path = os.path.split(file_path)
    if dir_path[0]:
        if not os.path.exists(dir_path[0]):
            os.makedirs(dir_path[0])
    with open(file_path, 'wb') as f:
        f.write(file_data)
        f.close()
    if file_time:
        os.utime(file_path, times=(file_time, file_time))
    return file_path
