Exemplo n.º 1
0
def remove_auth_apt_repo(repo_filename,
                         repo_url,
                         keyring_file=None,
                         fingerprint=None):
    """Remove an authenticated apt repo and credentials to the system"""
    logging.info('Removing authenticated apt repo: %s', repo_url)
    util.del_file(repo_filename)
    if keyring_file:
        util.del_file(keyring_file)
    elif fingerprint:
        util.subp(['apt-key', 'del', fingerprint], capture=True)
    _protocol, repo_path = repo_url.split('://')
    if repo_path.endswith('/'):  # strip trailing slash
        repo_path = repo_path[:-1]
    apt_auth_file = get_apt_auth_file_from_apt_config()
    if os.path.exists(apt_auth_file):
        apt_auth = util.load_file(apt_auth_file)
        auth_prefix = 'machine {repo_path}/ login'.format(repo_path=repo_path)
        content = '\n'.join([
            line for line in apt_auth.splitlines() if auth_prefix not in line
        ])
        if not content:
            os.unlink(apt_auth_file)
        else:
            util.write_file(apt_auth_file, content, mode=0o600)
Exemplo n.º 2
0
def remove_auth_apt_repo(repo_filename: str, repo_url: str,
                         keyring_file: str = None) -> None:
    """Remove an authenticated apt repo and credentials to the system"""
    logging.info('Removing authenticated apt repo: %s', repo_url)
    util.del_file(repo_filename)
    if keyring_file:
        util.del_file(keyring_file)
    remove_repo_from_apt_auth_file(repo_url)
Exemplo n.º 3
0
def remove_auth_apt_repo(repo_filename: str,
                         repo_url: str,
                         keyring_file: str = None) -> None:
    """Remove an authenticated apt repo and credentials to the system"""
    util.del_file(repo_filename)
    if keyring_file:
        keyring_file = os.path.join(APT_KEYS_DIR, keyring_file)
        util.del_file(keyring_file)
    remove_repo_from_apt_auth_file(repo_url)