Exemplo n.º 1
0
    def on_post(self, req, resp, tenant_id, validated_body):
        """
        This method resets a token when an HTTP POST is received.  There is
        a minimum time limit that must be reached before resetting a token,
        unless the call is made  with the "invalidate_now: true" option.
        """

        body = validated_body['token']

        #verify the tenant exists
        tenant = tenant_util.find_tenant(tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        invalidate_now = body['invalidate_now']

        if invalidate_now:
            #immediately invalidate the token
            tenant.token.reset_token_now()

        else:
            self._validate_token_min_time_limit_reached(tenant.token)
            tenant.token.reset_token()

        #save the tenant document
        tenant_util.save_tenant(tenant)

        resp.status = falcon.HTTP_203
        resp.set_header('Location', '/v1/{0}/token'.format(tenant_id))
Exemplo n.º 2
0
 def test_save_tenant(self):
     self.ds_handler.update = MagicMock()
     with patch('meniscus.data.model.tenant_util._db_handler',
                self.ds_handler):
         tenant_util.save_tenant(self.tenant_obj)
         self.ds_handler.update.assert_called_once_with(
             'tenant', self.tenant_obj.format_for_save())
Exemplo n.º 3
0
 def test_save_tenant(self):
     self.ds_handler.update = MagicMock()
     with patch('meniscus.data.model.tenant_util._db_handler',
                self.ds_handler):
         tenant_util.save_tenant(self.tenant_obj)
         self.ds_handler.update.assert_called_once_with(
             'tenant', self.tenant_obj.format_for_save())
Exemplo n.º 4
0
    def on_post(self, req, resp, tenant_id, validated_body):
        """
        This method resets a token when an HTTP POST is received.  There is
        a minimum time limit that must be reached before resetting a token,
        unless the call is made  with the "invalidate_now: true" option.
        """

        body = validated_body['token']

        #verify the tenant exists
        tenant = tenant_util.find_tenant(tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        invalidate_now = body['invalidate_now']

        if invalidate_now:
            #immediately invalidate the token
            tenant.token.reset_token_now()

        else:
            self._validate_token_min_time_limit_reached(tenant.token)
            tenant.token.reset_token()

        #save the tenant document
        tenant_util.save_tenant(tenant)

        resp.status = falcon.HTTP_203
        resp.set_header('Location', '/v1/{0}/token'.format(tenant_id))
Exemplo n.º 5
0
    def on_put(self, req, resp, tenant_id, event_producer_id, validated_body):
        """
        Make an update to a specified Event Producer's configuration
        when an HTTP PUT is received
        """

        body = validated_body['event_producer']

        #verify the tenant exists
        tenant = tenant_util.find_tenant(tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = tenant_util.find_event_producer(
            tenant, producer_id=event_producer_id)
        if not event_producer:
            _producer_not_found()

        #if a key is present, update the event_producer with the value
        if 'name' in body.keys() and event_producer.name != body['name']:
            #if the tenant already has a profile with this name then abort
            duplicate_producer = tenant_util.find_event_producer(
                tenant,  producer_name=body['name'])
            if duplicate_producer:
                api.abort(
                    falcon.HTTP_400,
                    'EventProducer with name {0} already exists with id={1}.'
                    .format(duplicate_producer.name,
                            duplicate_producer.get_id()))
            event_producer.name = body['name']

        if 'pattern' in body:
            event_producer.pattern = str(body['pattern'])

        if 'durable' in body:
            event_producer.durable = body['durable']

        if 'encrypted' in body:
            event_producer.encrypted = body['encrypted']

        if 'sinks' in body:
            event_producer.sinks = body['sinks']

        #save the tenant document
        tenant_util.save_tenant(tenant)

        resp.status = falcon.HTTP_200
Exemplo n.º 6
0
    def on_put(self, req, resp, tenant_id, event_producer_id, validated_body):
        """
        Make an update to a specified Event Producer's configuration
        when an HTTP PUT is received
        """

        body = validated_body['event_producer']

        #verify the tenant exists
        tenant = tenant_util.find_tenant(tenant_id=tenant_id)

        if not tenant:
            _tenant_not_found()

        #verify the event_producer exists and belongs to the tenant
        event_producer = tenant_util.find_event_producer(
            tenant, producer_id=event_producer_id)
        if not event_producer:
            _producer_not_found()

        #if a key is present, update the event_producer with the value
        if 'name' in body.keys() and event_producer.name != body['name']:
            #if the tenant already has a profile with this name then abort
            duplicate_producer = tenant_util.find_event_producer(
                tenant, producer_name=body['name'])
            if duplicate_producer:
                api.abort(
                    falcon.HTTP_400,
                    'EventProducer with name {0} already exists with id={1}.'.
                    format(duplicate_producer.name,
                           duplicate_producer.get_id()))
            event_producer.name = body['name']

        if 'pattern' in body:
            event_producer.pattern = str(body['pattern'])

        if 'durable' in body:
            event_producer.durable = body['durable']

        if 'encrypted' in body:
            event_producer.encrypted = body['encrypted']

        if 'sinks' in body:
            event_producer.sinks = body['sinks']

        #save the tenant document
        tenant_util.save_tenant(tenant)

        resp.status = falcon.HTTP_200