Beispiel #1
0
def mirror_project(self, session, username, namespace, name):
    """ Does the actual mirroring of the specified project.
    """
    plugin = pagure.lib.plugins.get_plugin("Mirroring")
    plugin.db_object()

    project = pagure.lib.query._get_project(session,
                                            namespace=namespace,
                                            name=name,
                                            user=username)

    repofolder = pagure_config["GIT_FOLDER"]
    repopath = os.path.join(repofolder, project.path)
    if not os.path.exists(repopath):
        _log.info("Git folder not found at: %s, bailing", repopath)
        return

    ssh_folder = pagure_config["MIRROR_SSHKEYS_FOLDER"]
    public_key_name = werkzeug.secure_filename(project.fullname)
    private_key_file = os.path.join(ssh_folder, public_key_name)

    # Add the utility script allowing this feature to work on old(er) git.
    here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
    script_file = os.path.join(here, "ssh_script.sh")

    # Get the list of remotes
    remotes = [
        remote.strip() for remote in project.mirror_hook.target.split("\n")
        if project.mirror_hook and remote.strip()
        and ssh_urlpattern.match(remote.strip())
    ]

    # Push
    logs = []
    for remote in remotes:
        _log.info("Pushing to remote %s using key: %s", remote,
                  private_key_file)
        (stdout, stderr) = pagure.lib.git.read_git_lines(
            ["push", "--mirror", remote],
            abspath=repopath,
            error=True,
            env={
                "SSHKEY": private_key_file,
                "GIT_SSH": script_file
            },
        )
        log = "Output from the push:\n  stdout: %s\n  stderr: %s" % (
            stdout,
            stderr,
        )
        logs.append(log)

    if logs:
        project.mirror_hook.last_log = "\n".join(logs)
        session.add(project.mirror_hook)
        session.commit()
        _log.info("\n".join(logs))
Beispiel #2
0
 def test_ssh_pattern_valid(self):
     """ Test the ssh_urlpattern with valid patterns. """
     patterns = [
         'ssh://[email protected]/repo.git',
         'git+ssh://[email protected]/repo.git',
         'ssh://[email protected]:/path/to/repo.git',
         '[email protected]:user/project.git',
         'ssh://[email protected]/target',
         'git+ssh://[email protected]/target',
         'git+ssh://[email protected]:/path/to/repo.git',
     ]
     for pattern in patterns:
         print(pattern)
         self.assertIsNotNone(ssh_urlpattern.match(pattern))
 def test_ssh_pattern_valid(self):
     """ Test the ssh_urlpattern with valid patterns. """
     patterns = [
         "ssh://[email protected]/repo.git",
         "git+ssh://[email protected]/repo.git",
         "ssh://[email protected]:/path/to/repo.git",
         "[email protected]:user/project.git",
         "ssh://[email protected]/target",
         "git+ssh://[email protected]/target",
         "git+ssh://[email protected]:/path/to/repo.git",
     ]
     for pattern in patterns:
         print(pattern)
         self.assertIsNotNone(ssh_urlpattern.match(pattern))
Beispiel #4
0
 def test_ssh_pattern_invalid(self):
     """ Test the ssh_urlpattern with invalid patterns. """
     patterns = [
         'http://[email protected]/repo.git',
         'git+http://[email protected]/repo.git',
         'https://[email protected]/repo.git',
         'git+https://[email protected]/repo.git',
         'ssh://localhost/repo.git',
         'ssh://host.com/repo.git',
         'git+ssh://localhost/repo.git',
         'ssh://0.0.0.0/repo.git',
         'git+ssh://0.0.0.0/repo.git',
         'git+ssh://host.com/repo.git',
         'ssh://127.0.0.1/repo.git',
         'git+ssh://127.0.0.1/repo.git',
     ]
     for pattern in patterns:
         print(pattern)
         self.assertIsNone(ssh_urlpattern.match(pattern))
 def test_ssh_pattern_invalid(self):
     """ Test the ssh_urlpattern with invalid patterns. """
     patterns = [
         "http://[email protected]/repo.git",
         "git+http://[email protected]/repo.git",
         "https://[email protected]/repo.git",
         "git+https://[email protected]/repo.git",
         "ssh://localhost/repo.git",
         "ssh://host.com/repo.git",
         "git+ssh://localhost/repo.git",
         "ssh://0.0.0.0/repo.git",
         "git+ssh://0.0.0.0/repo.git",
         "git+ssh://host.com/repo.git",
         "ssh://127.0.0.1/repo.git",
         "git+ssh://127.0.0.1/repo.git",
     ]
     for pattern in patterns:
         print(pattern)
         self.assertIsNone(ssh_urlpattern.match(pattern))
Beispiel #6
0
def mirror_project(self, session, username, namespace, name):
    """ Does the actual mirroring of the specified project.
    """
    plugin = pagure.lib.plugins.get_plugin("Mirroring")
    plugin.db_object()

    project = pagure.lib.query._get_project(
        session, namespace=namespace, name=name, user=username
    )

    repofolder = pagure_config["GIT_FOLDER"]
    repopath = os.path.join(repofolder, project.path)
    if not os.path.exists(repopath):
        _log.warning("Git folder not found at: %s, bailing", repopath)
        return

    ssh_folder = pagure_config["MIRROR_SSHKEYS_FOLDER"]
    public_key_name = werkzeug.secure_filename(project.fullname)
    private_key_file = os.path.join(ssh_folder, public_key_name)

    if not os.path.exists(private_key_file):
        _log.warning("No %s key found, bailing", private_key_file)
        project.mirror_hook.last_log = "Private key not found on disk, bailing"
        session.add(project.mirror_hook)
        session.commit()
        return

    # Add the utility script allowing this feature to work on old(er) git.
    here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
    script_file = os.path.join(here, "ssh_script.sh")

    # Get the list of remotes
    remotes = [
        remote.strip()
        for remote in project.mirror_hook.target.split("\n")
        if project.mirror_hook
        and remote.strip()
        and ssh_urlpattern.match(remote.strip())
    ]

    # Push
    logs = []
    for remote in remotes:
        _log.info(
            "Pushing to remote %s using key: %s", remote, private_key_file
        )
        (stdout, stderr) = pagure.lib.git.read_git_lines(
            ["push", "--mirror", remote],
            abspath=repopath,
            error=True,
            env={"SSHKEY": private_key_file, "GIT_SSH": script_file},
        )
        log = "Output from the push:\n  stdout: %s\n  stderr: %s" % (
            stdout,
            stderr,
        )
        logs.append(log)

    if logs:
        project.mirror_hook.last_log = "\n".join(logs)
        session.add(project.mirror_hook)
        session.commit()
        _log.info("\n".join(logs))