def proxy_get(request, *args, **kwargs):
    logmsg = " ".join("proxying request", request.path, args, kwargs)
    print logmsg
    url = settings.PROXY_BASE + request.path    
    try:
        ret = url_request(url, "GET", {})
        return rdf_response(ret)
    except URLFetchException as e:
    
        if (settings.PROXY_ERROR_NOTIFICATION):
            me = settings.PROXY_NOTIFICATION_FROM
            you = settings.PROXY_NOTIFICATION_TO

            msg = MIMEText(logmsg + "\n" + e.body)
            msg['Subject'] = settings.PROXY_NOTIFICATION_SUBJECT
            msg['From'] = me
            msg['To'] = you

            s = smtplib.SMTP(settings.PROXY_NOTIFICATION_SMTP_SERVER)
            s.sendmail(me, [you], msg.as_string())
            s.close()
            
            return HttpResponse(content=settings.PROXY_ERROR_MESSAGE_OVERRIDE, status=e.status)
        else:
            return HttpResponse(content=e.body, status=e.status)
Exemplo n.º 2
0
def proxy_get(request, *args, **kwargs):
    print "proxying request", request.path, args, kwargs
    url = settings.PROXY_BASE + request.path    
    try:
        ret = url_request(url, "GET", {})
        return rdf_response(ret)
    except URLFetchException as e:
        return HttpResponse(content=e.body, status=e.status)
Exemplo n.º 3
0
def do_webhook(request, webhook_name):
    hook = None
    headers = {}

    # Find the preferred app for this webhook...
    try:
        hook = AppWebHook.objects.filter(name=webhook_name)[0]
    except:
        raise Exception("No hook exists with name:  '%s'" % webhook_name)

    data = request.raw_post_data
    if (request.method == 'GET'): data = request.META['QUERY_STRING']

    print "requesting web hook", hook.url, request.method, data

    hook_req = utils.url_request_build(hook.url, request.method, headers, data)

    # If the web hook needs patient context, we've got to generate + pass along tokens
    if (hook.requires_patient_context):
        app = hook.app
        record = request.principal.share.record
        account = request.principal.share.authorized_by
        # Create a new token for the webhook to access the in-context patient record
        token = HELPER_APP_SERVER.generate_and_preauthorize_access_token(
            app, record=record, account=account)

        # And supply the token details as part of the Authorization header, 2-legged signed
        # Using the helper app's consumer token + secret
        # (the 2nd parameter =None --> 2-legged OAuth request)
        oauth_request = OAuthRequest(app,
                                     None,
                                     hook_req,
                                     oauth_parameters=token.passalong_params)
        oauth_request.sign()
        for (hname, hval) in oauth_request.to_header().iteritems():
            hook_req.headers[hname] = hval

    response = utils.url_request(hook.url, request.method, headers, data)
    print "GOT,", response
    return utils.x_domain(
        HttpResponse(response, mimetype='application/rdf+xml'))
Exemplo n.º 4
0
def do_webhook(request, webhook_name):
    hook = None
    headers = {}
    
    # Find the preferred app for this webhook...
    try:
        hook = AppWebHook.objects.filter(name=webhook_name)[0]
    except:
        raise Exception("No hook exists with name:  '%s'"%webhook_name)
    
    data = request.raw_post_data
    if (request.method == 'GET'): data = request.META['QUERY_STRING']    
    
    print "requesting web hook", hook.url, request.method, data

    hook_req = utils.url_request_build(hook.url, request.method, headers, data)
    
    # If the web hook needs patient context, we've got to generate + pass along tokens
    if (hook.requires_patient_context):        
        app = hook.app
        record = request.principal.share.record
        account = request.principal.share.authorized_by
        # Create a new token for the webhook to access the in-context patient record
        token = HELPER_APP_SERVER.generate_and_preauthorize_access_token(app, record=record, account=account)
        
        # And supply the token details as part of the Authorization header, 2-legged signed
        # Using the helper app's consumer token + secret
        # (the 2nd parameter =None --> 2-legged OAuth request)
        oauth_request = OAuthRequest(app, None, hook_req, oauth_parameters=token.passalong_params)
        oauth_request.sign()        
        for (hname, hval) in oauth_request.to_header().iteritems():
            hook_req.headers[hname] = hval 
    
    response = utils.url_request(hook.url, request.method, headers, data)
    print "GOT,", response
    return utils.x_domain(HttpResponse(response, mimetype='application/rdf+xml'))
Exemplo n.º 5
0
 def request(self, url, method, headers, data=None):
     return utils.url_request(url, method, headers, data)
Exemplo n.º 6
0
def proxy_get(request, *args, **kwargs):
    print "proxying request", request.path, args, kwargs
    url = PROXY_BASE + request.path    
    ret = url_request(url, "GET", {})
    return rdf_response(ret)
Exemplo n.º 7
0
def proxy_get(request, *args, **kwargs):
    print "proxying request", request.path, args, kwargs
    url = settings.PROXY_BASE + request.path    
    ret = url_request(url, "GET", {})
    return rdf_response(ret)
Exemplo n.º 8
0
 def request(self, url, method, headers, data=None):
     return utils.url_request(url, method, headers, data)