コード例 #1
0
def http_bulk_view(request):
    ''' This is a view which handles messages sent by a Django logging
    framework HttpHandler and dispatches them to Django signals. To
    subscribe, write a function similar to: 

    @receiver(djeventstream.signals.event_received)
    def f(sender, **kwargs):
       print kwargs['msg']

    '''
    if False:  # Useful code path, but untested
        message = False
        if 'message' in request.POST or 'msg' in request.POST:
            message = request.POST['message']
            message = request.POST['msg']
        if message:
            event_received.send(sender=http_bulk_view, msg=message.split("\n"))
            #for line in message.split("\n"):
            #    event_received.send(sender = http_bulk_view, msg = message)
            return HttpResponse("Success")

    event_received.send(sender=http_bulk_view, msg=request.readlines())

    #for line in request.readlines():
    #    event_received.send(sender = http_bulk_view, msg = line)

    return HttpResponse("Success")
コード例 #2
0
ファイル: views.py プロジェクト: bharatmooc/djeventstream
def http_bulk_view(request):
    ''' This is a view which handles messages sent by a Django logging
    framework HttpHandler and dispatches them to Django signals. To
    subscribe, write a function similar to: 

    @receiver(djeventstream.signals.event_received)
    def f(sender, **kwargs):
       print kwargs['msg']

    '''
    if False: # Useful code path, but untested
        message = False
        if 'message' in request.POST or 'msg' in request.POST:
            message = request.POST['message']
            message = request.POST['msg']
        if message: 
            event_received.send(sender = http_bulk_view, msg = message.split("\n"))
            #for line in message.split("\n"):
            #    event_received.send(sender = http_bulk_view, msg = message)
            return HttpResponse( "Success" )

    event_received.send(sender = http_bulk_view, msg = request.readlines())

    #for line in request.readlines():
    #    event_received.send(sender = http_bulk_view, msg = line)

    return HttpResponse( "Success" )
コード例 #3
0
ファイル: views.py プロジェクト: imclab/djeventstream
def sns_view(request):
    ''' This view handles SNS requests, and forwards them along to the
    event handler. Valid ARNs for the subscribed SNS channels should
    be specified in settings.py. 

    WARNING: This does not verify SNS signatures. It relies on the
    server sitting behind a firewall where SNS signatures cannot be
    spoofed, or having a secret token in the message, or otherwise.
    '''
    body = json.loads(request.raw_post_data)
    # If we receive an attempt to subscribe to SNS, we confirm it is
    # one we'd like to subscribe to, and that the URL is an Amazon SNS
    # URL. We don't know if this is full-proof (probably not); we
    # still count on a firewall to make sure we don't get random
    # requests from the Internet.
    #
    # We really should verify the signature. This is slightly complex.
    if not settings.SNS_PUBLIC and body[
            'TopicArn'] not in settings.SNS_SUBSCRIPTIONS:
        raise Exception("Invalid topic ARN; check settings.py")

    if body['Type'] == 'SubscriptionConfirmation':
        url = body['SubscribeURL']
        if not re.compile(
                "^https://sns\.[a-z0-9\-]+\.amazonaws.com/\?Action=ConfirmSubscription\&TopicArn=arn"
        ).match(url):
            raise Exception("Invalid SNS URL")
        r = requests.get(url)
    elif body['Type'] == 'Notification':
        message = body['Message']
        if "Subject" in body:
            subject = body['Subject']
        else:
            subject = None
        event_received.send(sender=sns_view, msg=message)
    else:
        raise Exception("Unknown message type")

    return HttpResponse("All Good.")
コード例 #4
0
ファイル: views.py プロジェクト: DeathscytheH/djeventstream
def http_view(request):
    ''' This is a view which handles messages sent by a Django logging
    framework HttpHandler and dispatches them to Django signals. To
    subscribe, write a function similar to: 

    @receiver(djeventstream.signals.event_received)
    def f(sender, **kwargs):
       print kwargs['msg']

    '''
    if request.GET:
        try: # Not sure why this is necessary, but on some systems it is 'msg', and on others, 'message'
            message = request.GET['message']
        except MultiValueDictKeyError:
            message = request.GET['msg']
    else:
        try:
            message = request.POST['message']
        except:
            message = request.POST['msg']

    event_received.send(sender = http_view, msg = message)

    return HttpResponse( "Success" )
コード例 #5
0
ファイル: views.py プロジェクト: DeathscytheH/djeventstream
def sns_view(request):
    ''' This view handles SNS requests, and forwards them along to the
    event handler. Valid ARNs for the subscribed SNS channels should
    be specified in settings.py. 

    WARNING: This does not verify SNS signatures. It relies on the
    server sitting behind a firewall where SNS signatures cannot be
    spoofed, or having a secret token in the message, or otherwise.
    '''
    body = json.loads(request.raw_post_data)
    # If we receive an attempt to subscribe to SNS, we confirm it is
    # one we'd like to subscribe to, and that the URL is an Amazon SNS
    # URL. We don't know if this is full-proof (probably not); we
    # still count on a firewall to make sure we don't get random
    # requests from the Internet. 
    #
    # We really should verify the signature. This is slightly complex. 
    if not settings.SNS_PUBLIC and body['TopicArn'] not in settings.SNS_SUBSCRIPTIONS:
        raise Exception("Invalid topic ARN; check settings.py")

    if body['Type'] == 'SubscriptionConfirmation':
        url = body['SubscribeURL']
        if not re.compile("^https://sns\.[a-z0-9\-]+\.amazonaws.com/\?Action=ConfirmSubscription\&TopicArn=arn").match(url):
            raise Exception("Invalid SNS URL")
        r = requests.get(url)
    elif body['Type'] == 'Notification':
        message = body['Message']
        if "Subject" in body: 
            subject = body['Subject']
        else: 
            subject = None
        event_received.send(sender = sns_view, msg = message)
    else:
        raise Exception("Unknown message type")
        
    return HttpResponse("All Good.")
コード例 #6
0
def http_view(request):
    ''' This is a view which handles messages sent by a Django logging
    framework HttpHandler and dispatches them to Django signals. To
    subscribe, write a function similar to: 

    @receiver(djeventstream.signals.event_received)
    def f(sender, **kwargs):
       print kwargs['msg']

    '''
    if request.GET:
        try:  # Not sure why this is necessary, but on some systems it is 'msg', and on others, 'message'
            message = request.GET['message']
        except MultiValueDictKeyError:
            message = request.GET['msg']
    else:
        try:
            message = request.POST['message']
        except:
            message = request.POST['msg']

    event_received.send(sender=http_view, msg=message)

    return HttpResponse("Success")