Exemplo n.º 1
0
    def cancel(self, parent, uuid):
        """
        Invoked to cancel a running publication
        Double invocation (this means, invoking cancel twice) will mean that is a "forced cancelation"
        :param parent: Parent service pool
        :param uuid: uuid of the publication
        """
        if permissions.checkPermissions(
                self._user, parent,
                permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug('Management Permission failed for user {}'.format(
                self._user))
            self.accessDenied()

        try:
            ds = DeployedServicePublication.objects.get(uuid=processUuid(uuid))
            ds.cancel()
        except Exception as e:
            raise ResponseError("{}".format(e))

        log.doLog(
            parent, log.INFO, "Canceled publication v{} by {}".format(
                parent.current_pub_revision, self._user.pretty_name),
            log.ADMIN)

        return self.success()
Exemplo n.º 2
0
    def processDetail(self):
        logger.debug('Processing detail {} for user {}'.format(
            self._path, self._user))
        try:
            item = self.model.objects.filter(uuid=self._args[0])[0]
            # If we do not have access to parent to, at least, read...

            if self._operation in ('put', 'post', 'delete'):
                requiredPermission = permissions.PERMISSION_MANAGEMENT
            else:
                requiredPermission = permissions.PERMISSION_READ

            if permissions.checkPermissions(self._user, item,
                                            requiredPermission) is False:
                logger.debug(
                    'Permission for user {} does not comply with {}'.format(
                        self._user, requiredPermission))
                self.accessDenied()

            detailCls = self.detail[self._args[1]]
            args = list(self._args[2:])
            path = self._path + '/'.join(args[:2])
            detail = detailCls(self,
                               path,
                               self._params,
                               *args,
                               parent=item,
                               user=self._user)
            method = getattr(detail, self._operation)
        except KeyError:
            self.invalidMethodException()
        except AttributeError:
            self.invalidMethodException()

        return method()
Exemplo n.º 3
0
    def processDetail(self):
        logger.debug('Processing detail {} for with params {}'.format(self._path, self._params))
        try:
            item = self.model.objects.filter(uuid=self._args[0])[0]
            # If we do not have access to parent to, at least, read...

            if self._operation in ('put', 'post', 'delete'):
                requiredPermission = permissions.PERMISSION_MANAGEMENT
            else:
                requiredPermission = permissions.PERMISSION_READ

            if permissions.checkPermissions(self._user, item, requiredPermission) is False:
                logger.debug('Permission for user {} does not comply with {}'.format(self._user, requiredPermission))
                self.accessDenied()

            detailCls = self.detail[self._args[1]]
            args = list(self._args[2:])
            path = self._path + '/'.join(args[:2])
            detail = detailCls(self, path, self._params, *args, parent=item, user=self._user)
            method = getattr(detail, self._operation)

            return method()
        except KeyError:
            self.invalidMethodException()
        except AttributeError:
            self.invalidMethodException()

        raise Exception('Invalid code executed on processDetail')
Exemplo n.º 4
0
    def publish(self, parent):
        """
        Custom method "publish", provided to initiate a publication of a deployed service
        :param parent: Parent service pool
        """
        changeLog = self._params[
            'changelog'] if 'changelog' in self._params else None

        if permissions.checkPermissions(
                self._user, parent,
                permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug('Management Permission failed for user {}'.format(
                self._user))
            self.accessDenied()

        logger.debug('Custom "publish" invoked for {}'.format(parent))
        parent.publish(
            changeLog
        )  # Can raise exceptions that will be processed on response

        log.doLog(
            parent, log.INFO, "Initated publication v{} by {}".format(
                parent.current_pub_revision, self._user.pretty_name),
            log.ADMIN)

        return self.success()
Exemplo n.º 5
0
    def getItems(self, *args, **kwargs) -> typing.Generator[typing.Dict[str, typing.Any], None, None]:
        if 'overview' in kwargs:
            overview = kwargs['overview']
            del kwargs['overview']
        else:
            overview = True

        if 'prefetch' in kwargs:
            prefetch = kwargs['prefetch']
            logger.debug('Prefetching %s', prefetch)
            del kwargs['prefetch']
        else:
            prefetch = []

        if 'query' in kwargs:
            query = kwargs['query']
            logger.debug('Got query: %s', query)
            del kwargs['query']
        else:
            logger.debug('Args: %s, kwargs: %s', args, kwargs)
            query = self.model.objects.filter(*args, **kwargs).prefetch_related(*prefetch)

        for item in query:
            try:
                if permissions.checkPermissions(typing.cast('User', self._user), item, permissions.PERMISSION_READ) is False:
                    continue
                if kwargs.get('overview', True):
                    yield self.item_as_dict_overview(item)
                else:
                    res = self.item_as_dict(item)
                    self.fillIntanceFields(item, res)
                    yield res
            except Exception:  # maybe an exception is thrown to skip an item
                # logger.exception('Exception getting item from {0}'.format(self.model))
                pass
Exemplo n.º 6
0
    def processDetail(self):
        logger.debug('Processing detail %s for with params %s', self._path, self._params)
        try:
            item: models.Model = self.model.objects.filter(uuid=self._args[0])[0]
            # If we do not have access to parent to, at least, read...

            if self._operation in ('put', 'post', 'delete'):
                requiredPermission = permissions.PERMISSION_MANAGEMENT
            else:
                requiredPermission = permissions.PERMISSION_READ

            if permissions.checkPermissions(self._user, item, requiredPermission) is False:
                logger.debug('Permission for user %s does not comply with %s', self._user, requiredPermission)
                raise self.accessDenied()

            detailCls = self.detail[self._args[1]]  # pylint: disable=unsubscriptable-object
            args = list(self._args[2:])
            path = self._path + '/'.join(args[:2])
            detail = detailCls(self, path, self._params, *args, parent=item, user=self._user)
            method = getattr(detail, self._operation)

            return method()
        except KeyError:
            raise self.invalidMethodException()
        except AttributeError:
            raise self.invalidMethodException()

        raise Exception('Invalid code executed on processDetail')
Exemplo n.º 7
0
    def publish(self, parent):
        '''
        Custom method "publish", provided to initiate a publication of a deployed service
        :param parent: Parent service pool
        '''
        if permissions.checkPermissions(self._user, parent, permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug('Management Permission failed for user {}'.format(self._user))
            self.accessDenied()

        logger.debug('Custom "publish" invoked for {}'.format(parent))
        parent.publish()  # Can raise exceptions that will be processed on response
        return self.success()
Exemplo n.º 8
0
 def getItems(self, overview=True, *args, **kwargs):
     for item in self.model.objects.filter(*args, **kwargs):
         try:
             if permissions.checkPermissions(self._user, item, permissions.PERMISSION_READ) is False:
                 continue
             if overview:
                 yield self.item_as_dict_overview(item)
             else:
                 res = self.item_as_dict(item)
                 self.fillIntanceFields(item, res)
                 yield res
         except Exception:  # maybe an exception is thrown to skip an item
             # logger.exception('Exception getting item from {0}'.format(self.model))
             pass
Exemplo n.º 9
0
 def getItems(self, overview=True, *args, **kwargs):
     for item in self.model.objects.filter(*args, **kwargs):
         try:
             if permissions.checkPermissions(self._user, item, permissions.PERMISSION_READ) is False:
                 continue
             if overview:
                 yield self.item_as_dict_overview(item)
             else:
                 res = self.item_as_dict(item)
                 self.fillIntanceFields(item, res)
                 yield res
         except Exception:  # maybe an exception is thrown to skip an item
             # logger.exception('Exception getting item from {0}'.format(self.model))
             pass
Exemplo n.º 10
0
    def publish(self, parent):
        '''
        Custom method "publish", provided to initiate a publication of a deployed service
        :param parent: Parent service pool
        '''
        if permissions.checkPermissions(
                self._user, parent,
                permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug('Management Permission failed for user {}'.format(
                self._user))
            self.accessDenied()

        logger.debug('Custom "publish" invoked for {}'.format(parent))
        parent.publish(
        )  # Can raise exceptions that will be processed on response
        return self.success()
Exemplo n.º 11
0
    def publish(self, parent):
        """
        Custom method "publish", provided to initiate a publication of a deployed service
        :param parent: Parent service pool
        """
        changeLog = self._params['changelog'] if 'changelog' in self._params else None

        if permissions.checkPermissions(self._user, parent, permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug('Management Permission failed for user {}'.format(self._user))
            self.accessDenied()

        logger.debug('Custom "publish" invoked for {}'.format(parent))
        parent.publish(changeLog)  # Can raise exceptions that will be processed on response

        log.doLog(parent, log.INFO, "Initated publication v{} by {}".format(parent.current_pub_revision, self._user.pretty_name), log.ADMIN)

        return self.success()
Exemplo n.º 12
0
    def cancel(self, parent, uuid):
        """
        Invoked to cancel a running publication
        Double invocation (this means, invoking cancel twice) will mean that is a "forced cancelation"
        :param parent: Parent service pool
        :param uuid: uuid of the publication
        """
        if permissions.checkPermissions(self._user, parent, permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug("Management Permission failed for user {}".format(self._user))
            self.accessDenied()

        try:
            ds = DeployedServicePublication.objects.get(uuid=processUuid(uuid))
            ds.cancel()
        except Exception as e:
            raise ResponseError(unicode(e))

        return self.success()
Exemplo n.º 13
0
 def getItems(
     self, *args, **kwargs
 ) -> typing.Generator[typing.Dict[str, typing.Any], None, None]:
     for item in self.model.objects.filter(*args, **kwargs):
         try:
             if permissions.checkPermissions(
                     typing.cast('User', self._user), item,
                     permissions.PERMISSION_READ) is False:
                 continue
             if kwargs.get('overview', True):
                 yield self.item_as_dict_overview(item)
             else:
                 res = self.item_as_dict(item)
                 self.fillIntanceFields(item, res)
                 yield res
         except Exception:  # maybe an exception is thrown to skip an item
             # logger.exception('Exception getting item from {0}'.format(self.model))
             pass
Exemplo n.º 14
0
    def cancel(self, parent, uuid):
        """
        Invoked to cancel a running publication
        Double invocation (this means, invoking cancel twice) will mean that is a "forced cancelation"
        :param parent: Parent service pool
        :param uuid: uuid of the publication
        """
        if permissions.checkPermissions(self._user, parent, permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug('Management Permission failed for user {}'.format(self._user))
            self.accessDenied()

        try:
            ds = DeployedServicePublication.objects.get(uuid=processUuid(uuid))
            ds.cancel()
        except Exception as e:
            raise ResponseError("{}".format(e))

        log.doLog(parent, log.INFO, "Canceled publication v{} by {}".format(parent.current_pub_revision, self._user.pretty_name), log.ADMIN)

        return self.success()
Exemplo n.º 15
0
    def cancel(self, parent, uuid):
        """
        Invoked to cancel a running publication
        Double invocation (this means, invoking cancel twice) will mean that is a "forced cancelation"
        :param parent: Parent service pool
        :param uuid: uuid of the publication
        """
        if permissions.checkPermissions(
                self._user, parent,
                permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug('Management Permission failed for user {}'.format(
                self._user))
            self.accessDenied()

        try:
            ds = DeployedServicePublication.objects.get(uuid=processUuid(uuid))
            ds.cancel()
        except Exception as e:
            raise ResponseError(six.text_type(e))

        return self.success()