Skip to content

Commit

Permalink
remove extra fileds
Browse files Browse the repository at this point in the history
  • Loading branch information
ksripathi committed Nov 30, 2016
1 parent 07676c6 commit f46b955
Showing 1 changed file with 2 additions and 146 deletions.
148 changes: 2 additions & 146 deletions src/controller_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from utils.envsetup import EnvSetUp
from controller import Controller
from config.adapters import base_config

import json

define("port", default=8000, help="run on the given port", type=int)

Expand All @@ -39,151 +39,7 @@ def get_current_user(self):


class MainHandler(BaseHandler):
"""
Main Handler is to handle the index page for ControllerServer
"""
def get(self):
if not self.current_user:
self.redirect('/login')
else:
self.render('index.html')

def post(self):
key = base_config.SECRET_KEY
post_data = json.loads(self.request.body.decode('utf-8'))
if post_data['key'] != key:
raise tornado.web.HTTPError(401, "Unauthorized_error")
c = Controller()
# log the user who is deploying the lab..
logger.debug("Lab Deployment: deployed by: %s, lab id: %s, URL: %s" %
(self.current_user,
post_data['lab_id'],
post_data['lab_src_url']))

self.write(c.test_lab(self.current_user, post_data['lab_id'],
post_data['lab_src_url'],
post_data.get('version', None)))

class LoginHandler(BaseHandler):
"""
LoginHandler will handle logins at /login
"""

def get(self):
self.render('login.html')

def post(self):
msg = "LoginHandler: Authenticating and authorizing using Persona.."
logger.debug(msg)
assertion = self.get_argument("assertion")

if not assertion:
logger.debug("Assertion not passed by the client. Aborting.")
self.write_error(400)
return

data = {'assertion': assertion,
'audience': config_spec["CONTROLLER_CONFIG"]["APP_URL"]}

# make the auth request to persona
resp = requests.post(
config_spec["CONTROLLER_CONFIG"]["PERSONA_VERIFIER"],
data=data, verify=True)

if not resp.ok:
logger.debug("Response from Persona is malformed. Aborting auth.")
self.write_error(500)
return

verified_data = json.loads(resp.content)
logger.debug("Verified data from Persona: %s" % verified_data)

if verified_data['status'] != 'okay':
logger.debug("Persona returned error. Aborting authentication.")
self.write_error(500)
return

user_email = verified_data['email']
# user exists in our set of authorized users
if user_email in authorized_users.users:
logger.debug("Authentication and authorization successful!")
self.set_secure_cookie('user', user_email)
self.write({'status': 'okay', 'msg': "Successful login"})
# user does not exist. Send unauthorized error.
else:
logger.debug("User: %s is not authorized. Aborting." % user_email)
msg = "<b>Oops!</b> You are not authorized to deploy a lab. <br>"
msg += "<small>Please contact <some> admin for details.</small>"
self.write({'status': 'error', 'msg': msg})


class LogoutHandler(BaseHandler):
"""
LogoutHandler will handle logouts at /logout
"""

def post(self):
self.clear_cookie('user')
self.write({'status': 'okay', 'msg': 'logged out'})


if __name__ == "__main__":
env = EnvSetUp.Instance()
config_spec = env.get_config_spec()
tornado.options.parse_command_line()
app = tornado.web.Application(
handlers=[
(r"/", MainHandler),
(r"/login", LoginHandler),
(r"/logout", LogoutHandler)
],
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
cookie_secret=config_spec["CONTROLLER_CONFIG"]["COOKIE_SECRET"],
debug=True)

http_server = tornado.httpserver.HTTPServer(app)
options.port = config_spec["CONTROLLER_CONFIG"]["SERVER_PORT"]
logger.debug("ControllerServer: It will run on port : " + str(options.port))
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
#!/bin/python

# Services exposed by the VM Manager
# The REST url :
# http://host-name/api/1.0/disk-usage
# http://host-name/api/1.0/running-time
# http://host-name/api/1.0/mem-usage
# http://host-name/api/1.0/running-processes
# http://host-name/api/1.0/cpu-load
# http://host-name/api/1.0/execute/<command>

import urlparse
import os
import os.path
import json
import requests

# tornado imports
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options

# ADS imports
from __init__ import *
from httplogging.http_logger import logger
from utils.envsetup import EnvSetUp
from controller import Controller
from config.adapters import base_config
import json

define("port", default=8000, help="run on the given port", type=int)


class MainHandler():


def post(self):
key = base_config.SECRET_KEY
post_data = json.loads(self.request.body.decode('utf-8'))
Expand Down

0 comments on commit f46b955

Please sign in to comment.