def _update_application(self, request, app, **kwargs):
     data = request.DATA
     user = request.user
     data = request.DATA
     app_owner = app.created_by
     app_members = app.get_members()
     if user != app_owner and not Group.check_membership(user, app_members):
         return failure_response(status.HTTP_403_FORBIDDEN,
                                 "You are not the Application owner. "
                                 "This incident will be reported")
         #Or it wont.. Up to operations..
     partial_update = True if request.method == 'PATCH' else False
     serializer = ApplicationSerializer(app, data=data,
                                        context={'request': request},
                                        partial=partial_update)
     if serializer.is_valid():
         logger.info('metadata = %s' % data)
         #TODO: Update application metadata on each machine?
         #update_machine_metadata(esh_driver, esh_machine, data)
         serializer.save()
         if 'created_by_identity' in data:
             identity = serializer.object.created_by_identity
             update_application_owner(serializer.object, identity)
         if 'boot_scripts' in data:
             _save_scripts_to_application(serializer.object,
                                          data.get('boot_scripts',[]))
         return Response(serializer.data)
     return failure_response(
         status.HTTP_400_BAD_REQUEST,
         serializer.errors)
Exemple #2
0
 def _update_application(self, request, app, **kwargs):
     data = request.DATA
     user = request.user
     data = request.DATA
     app_owner = app.created_by
     app_members = app.get_members()
     if user != app_owner and not Group.check_membership(user, app_members):
         return failure_response(
             status.HTTP_403_FORBIDDEN,
             "You are not the Application owner. "
             "This incident will be reported")
         #Or it wont.. Up to operations..
     partial_update = True if request.method == 'PATCH' else False
     serializer = ApplicationSerializer(app,
                                        data=data,
                                        context={'request': request},
                                        partial=partial_update)
     if serializer.is_valid():
         logger.info('metadata = %s' % data)
         #TODO: Update application metadata on each machine?
         #update_machine_metadata(esh_driver, esh_machine, data)
         serializer.save()
         if 'created_by_identity' in data:
             identity = serializer.object.created_by_identity
             update_application_owner(serializer.object, identity)
         if 'boot_scripts' in data:
             _save_scripts_to_application(serializer.object,
                                          data.get('boot_scripts', []))
         return Response(serializer.data)
     return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)
Exemple #3
0
    def _update_machine(self, request, provider_uuid, identity_uuid, machine_id):
        # TODO: Determine who is allowed to edit machines besides
        # core_machine.owner
        user = request.user
        data = request.DATA
        esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
        if not esh_driver:
            return invalid_creds(provider_uuid, identity_uuid)
        esh_machine = esh_driver.get_machine(machine_id)
        core_machine = convert_esh_machine(esh_driver, esh_machine, provider_uuid, user)
        if not user.is_staff and user is not core_machine.application_version.application.created_by:
            logger.warn("%s is Non-staff/non-owner trying to update a machine" % (user.username))
            return failure_response(
                status.HTTP_401_UNAUTHORIZED, "Only Staff and the machine Owner " "are allowed to change machine info."
            )

        partial_update = True if request.method == "PATCH" else False
        serializer = ProviderMachineSerializer(
            core_machine, request_user=request.user, data=data, partial=partial_update
        )
        if serializer.is_valid():
            logger.info("metadata = %s" % data)
            update_machine_metadata(esh_driver, esh_machine, data)
            machine = serializer.save()
            if "created_by_identity" in request.DATA:
                identity = machine.created_by_identity
                update_application_owner(core_machine.application_version.application, identity)
            logger.info(serializer.data)
            return Response(serializer.data)
        return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)
Exemple #4
0
    def _update_machine(
        self, request, provider_uuid, identity_uuid, machine_id
    ):
        # TODO: Determine who is allowed to edit machines besides
        # core_machine.owner
        user = request.user
        data = request.data
        try:
            esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
        except ProviderNotActive as pna:
            return inactive_provider(pna)
        except Exception as e:
            return failure_response(status.HTTP_409_CONFLICT, e.message)

        if not esh_driver:
            return invalid_creds(provider_uuid, identity_uuid)
        esh_machine = esh_driver.get_machine(machine_id)
        core_machine = convert_esh_machine(
            esh_driver, esh_machine, provider_uuid, user
        )
        if not user.is_staff and user is not core_machine.application_version.application.created_by:
            logger.warn(
                '%s is Non-staff/non-owner trying to update a machine' %
                (user.username)
            )
            return failure_response(
                status.HTTP_401_UNAUTHORIZED,
                "Only Staff and the machine Owner "
                "are allowed to change machine info."
            )

        partial_update = True if request.method == 'PATCH' else False
        serializer = ProviderMachineSerializer(
            core_machine,
            request_user=request.user,
            data=data,
            partial=partial_update
        )
        if serializer.is_valid():
            logger.info('metadata = %s' % data)
            update_machine_metadata(esh_driver, esh_machine, data)
            machine = serializer.save()
            if 'created_by_identity' in request.data:
                identity = machine.created_by_identity
                update_application_owner(
                    core_machine.application_version.application, identity
                )
            logger.info(serializer.data)
            return Response(serializer.data)
        return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)