diff --git a/confluent/httpapi.py b/confluent/httpapi.py
index d30a7d74..abdf5d2a 100644
--- a/confluent/httpapi.py
+++ b/confluent/httpapi.py
@@ -14,8 +14,6 @@ import confluent.pluginapi as pluginapi
import confluent.util as util
import eventlet
import json
-import os
-import string
import traceback
import time
import urlparse
@@ -32,23 +30,25 @@ opmap = {
'DELETE': 'delete',
}
+
def node_creation_resources():
yield confluent.messages.Attributes(
- kv={ 'name': None}, desc="Name of the node").html() + '
'
+ kv={'name': None}, desc="Name of the node").html() + '
'
for attr in sorted(attribs.node.iterkeys()):
if attr.startswith("secret."):
yield confluent.messages.CryptedAttributes(
- kv={ attr: None }, desc=attribs.node[attr]['description']).html() + \
- '
'
+ kv={attr: None},
+ desc=attribs.node[attr]['description']).html() + '
'
else:
yield confluent.messages.Attributes(
- kv={ attr: None }, desc=attribs.node[attr]['description']).html() + \
- '
'
+ kv={attr: None},
+ desc=attribs.node[attr]['description']).html() + '
'
create_resource_functions = {
'/node/': node_creation_resources,
}
+
def _sessioncleaner():
while (1):
currtime = time.time()
@@ -110,13 +110,13 @@ def _authorize_request(env):
authdata = auth.authorize(name, element=None)
if authdata is False and 'HTTP_AUTHORIZATION' in env:
name, passphrase = base64.b64decode(
- env['HTTP_AUTHORIZATION'].replace('Basic ','')).split(':',1)
+ env['HTTP_AUTHORIZATION'].replace('Basic ', '')).split(':', 1)
authdata = auth.check_user_passphrase(name, passphrase, element=None)
sessid = util.randomstring(32)
while sessid in httpsessions:
sessid = util.randomstring(32)
httpsessions[sessid] = {'name': name, 'expiry': time.time() + 90}
- cookie['confluentsessionid']=sessid
+ cookie['confluentsessionid'] = sessid
cookie['confluentsessionid']['secure'] = 1
cookie['confluentsessionid']['httponly'] = 1
cookie['confluentsessionid']['path'] = '/'
@@ -160,9 +160,10 @@ def _assign_consessionid(consolesession):
while sessid in consolesessions.keys():
sessid = util.randomstring(32)
consolesessions[sessid] = {'session': consolesession,
- 'expiry': time.time() + 60}
+ 'expiry': time.time() + 60}
return sessid
+
def resourcehandler(env, start_response):
"""Function to handle new wsgi requests
"""
@@ -179,22 +180,25 @@ def resourcehandler(env, start_response):
del querydict['restexplorerop']
authorized = _authorize_request(env)
if authorized['code'] == 401:
- start_response('401 Authentication Required',
+ start_response(
+ '401 Authentication Required',
[('Content-type', 'text/plain'),
- ('WWW-Authenticate', 'Basic realm="confluent"')])
+ ('WWW-Authenticate', 'Basic realm="confluent"')])
yield 'authentication required'
return
if authorized['code'] == 403:
- start_response('403 Forbidden',
+ start_response(
+ '403 Forbidden',
[('Content-type', 'text/plain'),
- ('WWW-Authenticate', 'Basic realm="confluent"')])
+ ('WWW-Authenticate', 'Basic realm="confluent"')])
yield 'authorization failed'
return
if authorized['code'] != 200:
raise Exception("Unrecognized code from auth engine")
- headers = [('Content-Type', mimetype) ]
- headers.extend(("Set-Cookie", m.OutputString())
- for m in authorized['cookie'].values())
+ headers = [('Content-Type', mimetype)]
+ headers.extend(
+ ("Set-Cookie", m.OutputString())
+ for m in authorized['cookie'].values())
cfgmgr = authorized['cfgmgr']
if '/console/session' in env['PATH_INFO']:
#hard bake JSON into this path, do not support other incarnations
@@ -203,7 +207,7 @@ def resourcehandler(env, start_response):
if 'session' not in querydict.keys() or not querydict['session']:
# Request for new session
consession = consoleserver.ConsoleSession(node=nodename,
- configmanager=cfgmgr)
+ configmanager=cfgmgr)
if not consession:
start_response("500 Internal Server Error", headers)
return
@@ -215,7 +219,7 @@ def resourcehandler(env, start_response):
# client wishes to push some keys into the remote console
input = ""
for idx in xrange(0, len(querydict['keys']), 2):
- input += chr(int(querydict['keys'][idx:idx+2],16))
+ input += chr(int(querydict['keys'][idx:idx+2], 16))
sessid = querydict['session']
if sessid not in consolesessions:
start_response('400 Expired Session', headers)
@@ -223,20 +227,24 @@ def resourcehandler(env, start_response):
consolesessions[sessid]['expiry'] = time.time() + 90
consolesessions[sessid]['session'].write(input)
start_response('200 OK', headers)
- return # client has requests to send or receive, not both...
- else: #no keys, but a session, means it's hooking to receive data
+ return # client has requests to send or receive, not both...
+ else: # no keys, but a session, means it's hooking to receive data
sessid = querydict['session']
if sessid not in consolesessions:
start_response('400 Expired Session', headers)
return
consolesessions[sessid]['expiry'] = time.time() + 90
- outdata = consolesessions[sessid]['session'].get_next_output(timeout=45)
+ outdata = consolesessions[sessid]['session'].get_next_output(
+ timeout=45)
try:
- rsp = json.dumps({'session': querydict['session'], 'data': outdata})
+ rsp = json.dumps({'session': querydict['session'],
+ 'data': outdata})
except UnicodeDecodeError:
- rsp = json.dumps({'session': querydict['session'], 'data': outdata}, encoding='cp437')
+ rsp = json.dumps({'session': querydict['session'],
+ 'data': outdata}, encoding='cp437')
except UnicodeDecodeError:
- rsp = json.dumps({'session': querydict['session'], 'data': 'DECODEERROR'})
+ rsp = json.dumps({'session': querydict['session'],
+ 'data': 'DECODEERROR'})
start_response('200 OK', headers)
yield rsp
return
@@ -297,9 +305,9 @@ def _assemble_html(responses, resource, querydict, url):
else:
pendingrsp.append(rsp)
for rsp in pendingrsp:
- yield rsp.html()+ "
"
+ yield rsp.html() + "
"
if iscollection:
- localpath = url[:-2]
+ # localpath = url[:-2] (why was this here??)
try:
firstpass = True
for y in create_resource_functions[url]():
@@ -307,11 +315,13 @@ def _assemble_html(responses, resource, querydict, url):
yield "