Exemplo n.º 1
0
def edit_mirror(mirror_id: int):
    mirror_detail = PushMirror.query.filter_by(
        id=mirror_id, user=current_user).first_or_404()
    form = EditForm(flask.request.form,
                    id=mirror_detail.id,
                    project_mirror=mirror_detail.project_mirror,
                    note=mirror_detail.note,
                    is_force_update=mirror_detail.is_force_update,
                    is_prune_mirrors=mirror_detail.is_prune_mirrors,
                    project=mirror_detail.project.gitlab_id)
    if flask.request.method == 'POST' and form.validate():
        project_mirror_str = form.project_mirror.data.strip()
        project_mirror = GitRemote(project_mirror_str)
        target = GitRemote(project_mirror_str)
        if target.vcs_protocol == ProtocolEnum.SSH:
            # If protocol is SSH we need to convert URL to use USER RSA pair
            target = GitRemote(
                convert_url_for_user(project_mirror_str, current_user))

        # PullMirror
        mirror_detail.project_mirror = project_mirror_str
        mirror_detail.project = process_project(form.project.data)

        # Mirror
        mirror_detail.is_force_update = form.is_force_update.data
        mirror_detail.is_prune_mirrors = form.is_prune_mirrors.data
        mirror_detail.is_deleted = False
        mirror_detail.user = current_user
        mirror_detail.foreign_vcs_type = target.vcs_type
        mirror_detail.note = form.note.data
        mirror_detail.target = target
        mirror_detail.source = None  # We are getting source wia gitlab API

        db.session.add(mirror_detail)
        db.session.commit()
        if target.vcs_protocol == ProtocolEnum.SSH:
            # If source is SSH, create SSH Config for it also

            task_result = chain(
                create_ssh_config.si(current_user.id, target.hostname,
                                     project_mirror.hostname),
                save_push_mirror.si(mirror_detail.id)).apply_async()

            parent = log_task_pending(task_result.parent, mirror_detail,
                                      create_ssh_config, InvokedByEnum.MANUAL)
            log_task_pending(task_result, mirror_detail, save_push_mirror,
                             InvokedByEnum.MANUAL, parent)
        else:
            task = save_push_mirror.delay(mirror_detail.id)
            log_task_pending(task, mirror_detail, save_push_mirror,
                             InvokedByEnum.MANUAL)

        flask.flash('Push mirror was saved successfully.', 'success')
        return flask.redirect(flask.url_for('push_mirror.index.get_mirror'))

    return flask.render_template('push_mirror.index.edit.html',
                                 form=form,
                                 mirror_detail=mirror_detail)
Exemplo n.º 2
0
def new_mirror():
    form = NewForm(flask.request.form,
                   is_force_update=False,
                   is_prune_mirrors=False)
    if flask.request.method == 'POST' and form.validate():
        project_mirror_str = form.project_mirror.data.strip()
        project_mirror = GitRemote(project_mirror_str)
        target = GitRemote(project_mirror_str)
        if target.vcs_protocol == ProtocolEnum.SSH:
            # If protocol is SSH we need to convert URL to use USER RSA pair
            target = GitRemote(
                convert_url_for_user(project_mirror_str, current_user))

        mirror_new = PushMirror()
        # PushMirror
        mirror_new.project_mirror = project_mirror_str
        mirror_new.project = process_project(form.project.data)

        # Mirror
        mirror_new.is_force_update = form.is_force_update.data
        mirror_new.is_prune_mirrors = form.is_prune_mirrors.data
        mirror_new.is_deleted = False
        mirror_new.user = current_user
        mirror_new.foreign_vcs_type = target.vcs_type
        mirror_new.note = form.note.data
        mirror_new.target = target.url
        mirror_new.source = None  # We are getting source wia gitlab API
        mirror_new.last_sync = None
        mirror_new.hook_token = random_password()

        db.session.add(mirror_new)
        db.session.commit()

        if target.vcs_protocol == ProtocolEnum.SSH:
            # If target is SSH, create SSH Config for it also
            task_result = chain(
                create_ssh_config.si(current_user.id, target.hostname,
                                     project_mirror.hostname),
                save_push_mirror.si(mirror_new.id)).apply_async()

            parent = log_task_pending(task_result.parent, mirror_new,
                                      create_ssh_config, InvokedByEnum.MANUAL)
            log_task_pending(task_result, mirror_new, save_push_mirror,
                             InvokedByEnum.MANUAL, parent)
        else:
            task = save_push_mirror.delay(mirror_new.id)
            log_task_pending(task, mirror_new, save_push_mirror,
                             InvokedByEnum.MANUAL)

        flask.flash('New push mirror item was added successfully.', 'success')
        return flask.redirect(flask.url_for('push_mirror.index.get_mirror'))

    return flask.render_template('push_mirror.index.new.html', form=form)
Exemplo n.º 3
0
def edit_mirror(mirror_id: int):
    mirror_detail = PullMirror.query.filter_by(id=mirror_id, user=current_user).first_or_404()
    form = EditForm(
        flask.request.form,
        id=mirror_detail.id,
        project_name=mirror_detail.project_name,
        project_mirror=mirror_detail.project_mirror,
        note=mirror_detail.note,
        is_no_create=mirror_detail.is_no_create,
        is_force_create=mirror_detail.is_force_create,
        is_no_remote=mirror_detail.is_no_remote,
        is_issues_enabled=mirror_detail.is_issues_enabled,
        is_wall_enabled=mirror_detail.is_wall_enabled,
        is_wiki_enabled=mirror_detail.is_wiki_enabled,
        is_snippets_enabled=mirror_detail.is_snippets_enabled,
        is_merge_requests_enabled=mirror_detail.is_merge_requests_enabled,
        visibility=mirror_detail.visibility,
        is_force_update=mirror_detail.is_force_update,
        is_prune_mirrors=mirror_detail.is_prune_mirrors,
        group=mirror_detail.group.gitlab_id,
        periodic_sync=mirror_detail.periodic_sync,
        is_jobs_enabled=mirror_detail.is_jobs_enabled
    )
    if flask.request.method == 'POST' and form.validate():
        project_mirror_str = form.project_mirror.data.strip()
        project_mirror = GitRemote(project_mirror_str)
        source = GitRemote(project_mirror_str)
        if source.vcs_protocol == ProtocolEnum.SSH:
            # If protocol is SSH we need to convert URL to use USER RSA pair
            source = GitRemote(convert_url_for_user(project_mirror_str, current_user))

        # PullMirror
        mirror_detail.project_name = form.project_name.data
        mirror_detail.project_mirror = project_mirror_str
        mirror_detail.is_no_create = form.is_no_create.data
        mirror_detail.is_force_create = form.is_force_create.data
        mirror_detail.is_no_remote = form.is_no_remote.data
        mirror_detail.is_issues_enabled = form.is_issues_enabled.data
        mirror_detail.is_wall_enabled = form.is_wall_enabled.data
        mirror_detail.is_wiki_enabled = form.is_wiki_enabled.data
        mirror_detail.is_snippets_enabled = form.is_snippets_enabled.data
        mirror_detail.is_jobs_enabled = form.is_jobs_enabled.data
        mirror_detail.is_merge_requests_enabled = form.is_merge_requests_enabled.data
        mirror_detail.visibility = form.visibility.data
        mirror_detail.group = process_group(form.group.data)
        mirror_detail.periodic_sync = form.periodic_sync.data

        # Mirror
        mirror_detail.is_force_update = form.is_force_update.data
        mirror_detail.is_prune_mirrors = form.is_prune_mirrors.data
        mirror_detail.is_deleted = False
        mirror_detail.user = current_user
        mirror_detail.foreign_vcs_type = source.vcs_type
        mirror_detail.note = form.note.data
        mirror_detail.target = None  # We are getting target wia gitlab API
        mirror_detail.source = source.url

        if process_cron_expression(mirror_detail):
            PeriodicTasks.changed()

        db.session.add(mirror_detail)
        db.session.flush()
        db.session.commit()

        if source.vcs_protocol == ProtocolEnum.SSH:
            # If source is SSH, create SSH Config for it also
            task_result = chain(
                create_ssh_config.si(
                    current_user.id,
                    source.hostname,
                    project_mirror.hostname
                ),
                save_pull_mirror.si(
                    mirror_detail.id
                )
            ).apply_async()

            parent = log_task_pending(task_result.parent, mirror_detail, create_ssh_config, InvokedByEnum.MANUAL)
            log_task_pending(task_result, mirror_detail, save_pull_mirror, InvokedByEnum.MANUAL, parent)
        else:
            task = save_pull_mirror.delay(mirror_detail.id)
            log_task_pending(task, mirror_detail, save_pull_mirror, InvokedByEnum.MANUAL)

        flask.flash('Pull mirror was saved successfully.', 'success')
        return flask.redirect(flask.url_for('pull_mirror.index.get_mirror'))

    return flask.render_template('pull_mirror.index.edit.html', form=form, mirror_detail=mirror_detail)
Exemplo n.º 4
0
def new_mirror():
    form = NewForm(
        flask.request.form,
        is_no_create=False,
        is_force_create=False,
        is_no_remote=False,
        is_issues_enabled=False,
        is_wall_enabled=False,
        is_wiki_enabled=False,
        is_snippets_enabled=False,
        is_merge_requests_enabled=False,
        visibility=PullMirror.VISIBILITY_PRIVATE,
        is_force_update=False,
        is_prune_mirrors=False,
        is_jobs_enabled=True
    )
    if flask.request.method == 'POST' and form.validate():
        project_mirror_str = form.project_mirror.data.strip()
        project_mirror = GitRemote(project_mirror_str)
        source = GitRemote(project_mirror_str)
        if source.vcs_protocol == ProtocolEnum.SSH:
            # If protocol is SSH we need to convert URL to use USER RSA pair
            source = GitRemote(convert_url_for_user(project_mirror_str, current_user))

        mirror_new = PullMirror()
        # PullMirror
        mirror_new.project_name = form.project_name.data
        mirror_new.project_mirror = project_mirror_str
        mirror_new.is_no_create = form.is_no_create.data
        mirror_new.is_force_create = form.is_force_create.data
        mirror_new.is_no_remote = form.is_no_remote.data
        mirror_new.is_issues_enabled = form.is_issues_enabled.data
        mirror_new.is_wall_enabled = form.is_wall_enabled.data
        mirror_new.is_wiki_enabled = form.is_wiki_enabled.data
        mirror_new.is_snippets_enabled = form.is_snippets_enabled.data
        mirror_new.is_jobs_enabled = form.is_jobs_enabled.data
        mirror_new.is_merge_requests_enabled = form.is_merge_requests_enabled.data
        mirror_new.visibility = form.visibility.data
        mirror_new.group = process_group(form.group.data)
        mirror_new.periodic_sync = form.periodic_sync.data

        # Mirror
        mirror_new.is_force_update = form.is_force_update.data
        mirror_new.is_prune_mirrors = form.is_prune_mirrors.data
        mirror_new.is_deleted = False
        mirror_new.user = current_user
        mirror_new.foreign_vcs_type = source.vcs_type
        mirror_new.note = form.note.data
        mirror_new.target = None  # We are getting target wia gitlab API
        mirror_new.source = source.url
        mirror_new.last_sync = None
        mirror_new.hook_token = random_password()

        if process_cron_expression(mirror_new):
            PeriodicTasks.changed()

        db.session.add(mirror_new)
        db.session.commit()

        if source.vcs_protocol == ProtocolEnum.SSH:
            # If source is SSH, create SSH Config for it also
            task_result = chain(
                create_ssh_config.si(
                    current_user.id,
                    source.hostname,
                    project_mirror.hostname
                ),
                save_pull_mirror.si(
                    mirror_new.id
                )
            ).apply_async()

            parent = log_task_pending(task_result.parent, mirror_new, create_ssh_config, InvokedByEnum.MANUAL)
            log_task_pending(task_result, mirror_new, save_pull_mirror, InvokedByEnum.MANUAL, parent)
        else:
            task = save_pull_mirror.delay(mirror_new.id)
            log_task_pending(task, mirror_new, save_pull_mirror, InvokedByEnum.MANUAL)

        flask.flash('New pull mirror item was added successfully.', 'success')
        return flask.redirect(flask.url_for('pull_mirror.index.get_mirror'))

    return flask.render_template('pull_mirror.index.new.html', form=form)