Example #1
0
def overrides_list(path):
  if not request.user.can_manage:
    return abort(403)

  separator = "/"
  errors = []
  errors = errors + session.pop('errors', [])
  context = {}

  repo_path, context['overrides_path'] = file_utils.split_url_path(path)
  context['repo'] = get_target_for(repo_path)
  context['list_path'] = url_for('overrides_list', path = path)
  context['edit_path'] = url_for('overrides_edit', path = path)
  context['delete_path'] = url_for('overrides_delete', path = path)
  context['download_path'] = url_for('overrides_download', path = path)
  context['upload_path'] = url_for('overrides_upload', path = path)
  if context['overrides_path'] != '' and context['overrides_path'] != None:
    context['parent_name'] = separator.join(context['overrides_path'].split(separator)[:-1])
    context['parent_path'] = url_for('overrides_list', path = separator.join(path.split(separator)[:-1]))

  if not isinstance(context['repo'], Repository):
    return abort(404)

  try:
    cwd = os.path.join(utils.get_override_path(context['repo']), context['overrides_path'].replace('/', os.sep))
    utils.makedirs(os.path.dirname(cwd))
    context['files'] = file_utils.list_folder(cwd)
  except BaseException as exc:
    app.logger.info(exc)
    errors.append('Could not read overrides for this repository.')

  return render_template('overrides_list.html', user=request.user, **context, errors=errors)
Example #2
0
def generate_keypair(path):
    if not request.user.can_manage:
        return abort(403)

    repo = get_target_for(path)
    if not isinstance(repo, Repository):
        return abort(404)

    session['errors'] = []

    utils.makedirs(utils.get_customs_path(repo))

    try:
        private_key, public_key = utils.generate_ssh_keypair(repo.name +
                                                             '@FluxCI')
        private_key_path = utils.get_repo_private_key_path(repo)
        public_key_path = utils.get_repo_public_key_path(repo)

        try:
            file_utils.create_file_path(private_key_path)
            file_utils.create_file_path(public_key_path)

            file_utils.write_file(private_key_path, private_key)
            file_utils.write_file(public_key_path, public_key)

            try:
                os.chmod(private_key_path, 0o600)
                utils.flash('SSH keypair generated.')
            except BaseException as exc:
                app.logger.info(exc)
                session['errors'].append(
                    'Could not set permissions to newly generated private key.'
                )
        except BaseException as exc:
            app.logger.info(exc)
            session['errors'].append('Could not save generated SSH keypair.')
    except BaseException as exc:
        app.logger.info(exc)
        session['errors'].append('Could not generate new SSH keypair.')

    return redirect(url_for('edit_repo', repo_id=repo.id))
Example #3
0
def do_build(build_id, terminate_event):
    """
  Performs the build step for the build in the database with the specified
  *build_id*.
  """

    logfile = None
    logger = None
    status = None

    with contextlib.ExitStack() as stack:
        try:
            try:
                # Retrieve the current build information.
                with models.session():
                    build = Build.get(id=build_id)
                    app.logger.info('Build {}#{} started.'.format(
                        build.repo.name, build.num))

                    build.status = Build.Status_Building
                    build.date_started = datetime.now()

                    build_path = build.path()
                    override_path = build.path(Build.Data_OverrideDir)
                    utils.makedirs(os.path.dirname(build_path))
                    logfile = stack.enter_context(
                        open(build.path(build.Data_Log), 'w'))
                    logger = utils.create_logger(logfile)

                    # Prefetch the repository member as it is required in do_build_().
                    build.repo

                # Execute the actual build process (must not perform writes to the
                # 'build' object as the DB session is over).
                if do_build_(build, build_path, override_path, logger, logfile,
                             terminate_event):
                    status = Build.Status_Success
                else:
                    if terminate_event.is_set():
                        status = Build.Status_Stopped
                    else:
                        status = Build.Status_Error

            finally:
                # Create a ZIP from the build directory.
                if os.path.isdir(build_path):
                    logger.info('[Flux]: Zipping build directory...')
                    utils.zipdir(build_path, build_path + '.zip')
                    utils.rmtree(build_path, remove_write_protection=True)
                    logger.info('[Flux]: Done')

        except BaseException as exc:
            with models.session():
                build = Build.get(id=build_id)
                build.status = Build.Status_Error
                if logger:
                    logger.exception(exc)
                else:
                    app.logger.exception(exc)

        finally:
            with models.session():
                build = Build.get(id=build_id)
                if status is not None:
                    build.status = status
                build.date_finished = datetime.now()

    return status == Build.Status_Success