示例#1
0
def record_create(project_id):
    logTraffic(CLOUD_URL, endpoint='/private/record/create/<project_id>')
    hash_session = basicAuthSession(fk.request)
    if fk.request.method == 'POST':
        access_resp = access_manager.check_cloud(hash_session, ACC_SEC, CNT_SEC)
        current_user = access_resp[1]
        if current_user is None:
            return fk.Response('Unauthorized action on this endpoint.', status.HTTP_401_UNAUTHORIZED)
        else:
            logAccess(fk, access_resp[1], CLOUD_URL, 'cloud', '/private/record/create/<project_id>')
            if current_user.quota >= current_user.max_quota*1024*1024*1024:
                return fk.Response('You have exceeded your allowed maximum quota.', status.HTTP_401_UNAUTHORIZED)
            try:
                project = ProjectModel.objects.with_id(project_id)
            except:
                print(str(traceback.print_exc()))
            if project is None:
                return fk.Response('Unable to find the referenced project.', status.HTTP_404_NOT_FOUND)
            else:
                if project.owner == current_user  or current_user.group == "admin":
                    if fk.request.data:
                            data = json.loads(fk.request.data)
                            try:
                                record = RecordModel(created_at=str(datetime.datetime.utcnow()), project=project)
                                tags = data.get("tags", "")
                                rationels = data.get("rationels", "")
                                status = data.get("status", "unknown")
                                content = data.get("content", "no content")
                                access = data.get("access", project.access)
                                record.tags = [tags]
                                record.rationels = [rationels]
                                record.status = status
                                record.access = access
                                record.extend = {"uploaded":content}
                                record.save()
                                if len(project.history) > 0:
                                    head = project.history[-1]
                                    env = EnvironmentModel.objects.with_id(head)
                                    if env:
                                        record.environment = env
                                        record.save()
                                # project_content = {"project":json.loads(project.summary_json())}
                                # records = []
                                # for r in RecordModel.objects(project=project):
                                #     records.append(r)
                                # project_content["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]}
                                return cloud_response(201, 'Record successfully created.', json.loads(project.summary_json()))
                            except:
                                print(str(traceback.print_exc()))
                                return fk.Response('Failure to process. Contact admin if it persists.', status.HTTP_500_INTERNAL_SERVER_ERROR)
                    else:
                        return fk.Response('No content provided for the creation.', status.HTTP_204_NO_CONTENT)
                else:
                    return fk.Response('Unauthorized action on this record.', status.HTTP_401_UNAUTHORIZED)
    else:
        return fk.Response('Endpoint does not support this HTTP method.', status.HTTP_405_METHOD_NOT_ALLOWED)
示例#2
0
def record_create(hash_session, project_id):
    logTraffic(CLOUD_URL,
               endpoint='/private/<hash_session>/record/create/<project_id>')
    if fk.request.method == 'POST':
        access_resp = access_manager.check_cloud(hash_session)
        current_user = access_resp[1]
        if current_user is None:
            return fk.Response('Unauthorized action on this endpoint.',
                               status.HTTP_401_UNAUTHORIZED)
        else:
            logAccess(CLOUD_URL, 'cloud',
                      '/private/<hash_session>/record/create/<project_id>')
            try:
                project = ProjectModel.objects.with_id(project_id)
            except:
                print(str(traceback.print_exc()))
            if project is None:
                return fk.Response('Unable to find the referenced project.',
                                   status.HTTP_404_NOT_FOUND)
            else:
                if project.owner == current_user:
                    if fk.request.data:
                        data = json.loads(fk.request.data)
                        try:
                            record = RecordModel(created_at=str(
                                datetime.datetime.utcnow()),
                                                 project=project)
                            tags = data.get("tags", "")
                            rationels = data.get("rationels", "")
                            status = data.get("status", "unknown")
                            content = data.get("content", "no content")
                            access = data.get("access", "public")
                            record.tags = [tags]
                            record.rationels = [rationels]
                            record.status = status
                            record.access = access
                            record.extend = {"uploaded": content}
                            record.save()
                            return cloud_response(
                                201, 'Record successfully created.',
                                "The record was created.")
                        except:
                            print(str(traceback.print_exc()))
                            return fk.Response(
                                str(traceback.print_exc()),
                                status.HTTP_500_INTERNAL_SERVER_ERROR)
                    else:
                        return fk.Response(
                            'No content provided for the creation.',
                            status.HTTP_204_NO_CONTENT)
                else:
                    return fk.Response('Unauthorized action on this record.',
                                       status.HTTP_401_UNAUTHORIZED)
    else:
        return fk.Response('Endpoint does not support this HTTP method.',
                           status.HTTP_405_METHOD_NOT_ALLOWED)
示例#3
0
def record_create(project_id):
    logTraffic(CLOUD_URL, endpoint='/private/record/create/<project_id>')
    hash_session = basicAuthSession(fk.request)
    if fk.request.method == 'POST':
        access_resp = access_manager.check_cloud(hash_session, ACC_SEC,
                                                 CNT_SEC)
        current_user = access_resp[1]
        if current_user is None:
            return fk.Response('Unauthorized action on this endpoint.',
                               status.HTTP_401_UNAUTHORIZED)
        else:
            logAccess(CLOUD_URL, 'cloud',
                      '/private/record/create/<project_id>')
            try:
                project = ProjectModel.objects.with_id(project_id)
            except:
                print(str(traceback.print_exc()))
            if project is None:
                return fk.Response('Unable to find the referenced project.',
                                   status.HTTP_404_NOT_FOUND)
            else:
                if project.owner == current_user or current_user.group == "admin":
                    if fk.request.data:
                        data = json.loads(fk.request.data)
                        try:
                            record = RecordModel(created_at=str(
                                datetime.datetime.utcnow()),
                                                 project=project)
                            tags = data.get("tags", "")
                            rationels = data.get("rationels", "")
                            status = data.get("status", "unknown")
                            content = data.get("content", "no content")
                            access = data.get("access", "public")
                            record.tags = [tags]
                            record.rationels = [rationels]
                            record.status = status
                            record.access = access
                            record.extend = {"uploaded": content}
                            record.save()
                            if len(project.history) > 0:
                                head = project.history[-1]
                                env = EnvironmentModel.objects.with_id(head)
                                if env:
                                    record.environment = env
                                    record.save()
                            # project_content = {"project":json.loads(project.summary_json())}
                            # records = []
                            # for r in RecordModel.objects(project=project):
                            #     records.append(r)
                            # project_content["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]}
                            return cloud_response(
                                201, 'Record successfully created.',
                                json.loads(project.summary_json()))
                        except:
                            print(str(traceback.print_exc()))
                            return fk.Response(
                                str(traceback.print_exc()),
                                status.HTTP_500_INTERNAL_SERVER_ERROR)
                    else:
                        return fk.Response(
                            'No content provided for the creation.',
                            status.HTTP_204_NO_CONTENT)
                else:
                    return fk.Response('Unauthorized action on this record.',
                                       status.HTTP_401_UNAUTHORIZED)
    else:
        return fk.Response('Endpoint does not support this HTTP method.',
                           status.HTTP_405_METHOD_NOT_ALLOWED)