示例#1
0
def index(project: Project):
    bucket_name = request.args.get("q", None)
    minio_client = MinioClient(project=project)
    buckets_list = minio_client.list_bucket()
    if not bucket_name or bucket_name not in buckets_list:
        return redirect(url_for("artifacts.index", q=buckets_list[0]))
    return render_template("artifacts/files.html",
                           files=minio_client.list_files(bucket_name),
                           buckets=buckets_list,
                           bucket=bucket_name)
示例#2
0
    def to_json(self, exclude_fields: tuple = ()) -> dict:
        json_dict = super().to_json()

        project = Project.query.get_or_404(json_dict["project_id"])
        minio_client = MinioClient(project=project)
        buckets_list = minio_client.list_bucket()
        storage_space = 0
        for bucket in buckets_list:
            for file in minio_client.list_files(bucket):
                storage_space += file["size"]
        json_dict["storage_space"] = round(storage_space/1000000, 2)

        tasks = Task.query.filter_by(project_id=json_dict["project_id"]).all()
        json_dict["tasks_count"] = len(tasks)

        return json_dict
示例#3
0
    def apply_full_delete_by_pk(cls, pk: int) -> None:
        import docker
        import psycopg2

        from galloper.processors.minio import MinioClient
        from galloper.dal.influx_results import delete_test_data

        from galloper.database.models.task_results import Results
        from galloper.database.models.task import Task
        from galloper.database.models.security_results import SecurityResults
        from galloper.database.models.security_reports import SecurityReport
        from galloper.database.models.security_details import SecurityDetails
        from galloper.database.models.api_reports import APIReport
        from galloper.database.models.api_release import APIRelease
        from galloper.database.models.performance_tests import PerformanceTests
        from galloper.database.models.ui_report import UIReport
        from galloper.database.models.ui_result import UIResult
        from galloper.database.models.statistic import Statistic
        from galloper.database.models.project_quota import ProjectQuota

        _logger = logging.getLogger(cls.__name__.lower())
        _logger.info("Start deleting entire project within transaction")

        project = cls.query.get_or_404(pk)
        minio_client = MinioClient(project=project)
        docker_client = docker.from_env()
        buckets_for_removal = minio_client.list_bucket()

        db_session.query(Project).filter_by(id=pk).delete()
        for model_class in (Results, SecurityResults, SecurityReport,
                            SecurityDetails, APIRelease):
            db_session.query(model_class).filter_by(project_id=pk).delete()

        influx_result_data = []
        for api_report in APIReport.query.filter_by(project_id=pk).all():
            influx_result_data.append(
                (api_report.build_id, api_report.name, api_report.lg_type))
            api_report.delete(commit=False)

        task_ids = []
        for task in Task.query.filter_by(project_id=pk).all():
            task_ids.append(task.task_id)
            task.delete(commit=False)

        for test in PerformanceTests.query.filter_by(project_id=pk).all():
            test.delete(commit=False)

        for result in UIResult.query.filter_by(project_id=pk).all():
            result.delete(commit=False)

        for result in UIReport.query.filter_by(project_id=pk).all():
            result.delete(commit=False)

        for stats in Statistic.query.filter_by(project_id=pk).all():
            stats.delete(commit=False)

        for quota in ProjectQuota.query.filter_by(project_id=pk).all():
            quota.delete(commit=False)

        try:
            db_session.flush()
        except (psycopg2.DatabaseError, psycopg2.DataError,
                psycopg2.ProgrammingError, psycopg2.OperationalError,
                psycopg2.IntegrityError, psycopg2.InterfaceError,
                psycopg2.InternalError, psycopg2.Error) as exc:
            db_session.rollback()
            _logger.error(str(exc))
        else:
            db_session.commit()
            for bucket in buckets_for_removal:
                minio_client.remove_bucket(bucket=bucket)
            for influx_item_data in influx_result_data:
                delete_test_data(*influx_item_data)
            for task_id in task_ids:
                try:
                    volume = docker_client.volumes.get(task_id)
                except docker.errors.NotFound as docker_exc:
                    _logger.info(str(docker_exc))
                else:
                    volume.remove(force=True)
            _logger.info("Project successfully deleted!")

        selected_project_id = SessionProject.get()
        if pk == selected_project_id:
            SessionProject.pop()