def start_services(self): # HTTPS server sockets = tornado.netutil.bind_sockets( self.port, address=Settings['main_app']['servername']) redir_sockets = tornado.netutil.bind_sockets( self.redir_port, address=Settings['main_app']['servername']) tornado.process.fork_processes(0) server = tornado.httpserver.HTTPServer( self.main_app, ssl_options={ 'certfile': Settings['main_app']['ssl_certfile'], # This really should be read into a string so we can drop privileges # after reading the key but before starting the server, but Python # doesn't let us use strings for keys until Python 3.2 :( 'keyfile': Settings['main_app']['ssl_keyfile'], }) server.add_sockets(sockets) # HTTP server (to redirect to HTTPS) redir_server = tornado.httpserver.HTTPServer(self.redir_app) redir_server.add_sockets(redir_sockets) # Start the mail, git, reviewboard and XMPP queue handlers MailQueue.start_worker() GitQueue.start_worker() RBQueue.start_worker() XMPPQueue.start_worker()
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, _, req = db_results req = req.first() if req['state'] != 'delayed': # We didn't actually discard the record, for whatever reason return self.redirect("/requests?user=%s" % self.current_user) msg = ( """ <p> Your request has been marked as delayed by %(pushmaster)s, and will not be accepted into pushes until you mark it as requested again: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': req['user'], 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (req['user'], req['title']) MailQueue.enqueue_user_email([req['user']], msg, subject) self.redirect("/requests?user=%s" % self.current_user)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) for req in db_results[-1]: msg = (""" <p> %(pushmaster)s has accepted your request into a push: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': req['user'], 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (req['user'], req['title']) MailQueue.enqueue_user_email([req['user']], msg, subject) msg = '%(pushmaster)s has accepted your request "%(title)s" into a push:\nhttps://%(pushmanager_servername)s/push?id=%(pushid)s' % { 'pushmanager_servername': Settings['main_app']['servername'], 'pushmaster': self.current_user, 'title': req['title'], 'pushid': self.pushid, } XMPPQueue.enqueue_user_xmpp([req['user']], msg)
def start_services(self): # HTTPS server sockets = tornado.netutil.bind_sockets(self.port, address=Settings["main_app"]["servername"]) redir_sockets = tornado.netutil.bind_sockets(self.redir_port, address=Settings["main_app"]["servername"]) tornado.process.fork_processes(0) server = tornado.httpserver.HTTPServer( self.main_app, ssl_options={ "certfile": Settings["main_app"]["ssl_certfile"], # This really should be read into a string so we can drop privileges # after reading the key but before starting the server, but Python # doesn't let us use strings for keys until Python 3.2 :( "keyfile": Settings["main_app"]["ssl_keyfile"], }, ) server.add_sockets(sockets) # HTTP server (to redirect to HTTPS) redir_server = tornado.httpserver.HTTPServer(self.redir_app) redir_server.add_sockets(redir_sockets) # Start the mail, git, reviewboard and XMPP queue handlers MailQueue.start_worker() GitQueue.start_worker() RBQueue.start_worker() XMPPQueue.start_worker()
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) for req in db_results[-1]: msg = ( """ <p> %(pushmaster)s has accepted your request into a push: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': req['user'], 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (req['user'], req['title']) MailQueue.enqueue_user_email([req['user']], msg, subject) msg = '%(pushmaster)s has accepted your request "%(title)s" into a push:\nhttps://%(pushmanager_servername)s/push?id=%(pushid)s' % { 'pushmanager_servername': Settings['main_app']['servername'], 'pushmaster': self.current_user, 'title': req['title'], 'pushid': self.pushid, } XMPPQueue.enqueue_user_xmpp([req['user']], msg)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, req = db_results req = req.first() if req['state'] != 'discarded': # We didn't actually discard the record, for whatever reason return self.redirect("/requests?user=%s" % self.current_user) msg = (""" <p> Your request has been discarded: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': req['user'], 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (req['user'], req['title']) MailQueue.enqueue_user_email([req['user']], msg, subject) self.redirect("/requests?user=%s" % self.current_user)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, staged_requests, push_result = db_results push = push_result.fetchone() for req in staged_requests: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = ( """ <p> %(pushmaster)s has deployed request for %(user)s to %(pushstage)s: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Once you've checked that it works, mark it as verified here: <a href="https://%(pushmanager_servername)s/push?id=%(pushid)s"> https://%(pushmanager_servername)s/push?id=%(pushid)s </a> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'pushmanager_servername': Settings['main_app']['servername'], 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], 'pushid': self.pushid, 'pushstage': push['stageenv'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has deployed request "%(title)s" for %(user)s to %(pushstage)s.\nPlease verify it at https://%(pushmanager_servername)s/push?id=%(pushid)s' % { 'pushmaster': self.current_user, 'pushmanager_servername': Settings['main_app']['servername'], 'title': req['title'], 'pushid': self.pushid, 'user': user_string, 'pushstage': push['stageenv'], } XMPPQueue.enqueue_user_xmpp(users, msg) if push['extra_pings']: for user in push['extra_pings'].split(','): XMPPQueue.enqueue_user_xmpp([user], '%s has deployed a push to stage.' % self.current_user)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, staged_requests, push_result = db_results for req in staged_requests: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = (""" <p> %(pushmaster)s has deployed request for %(user)s to stage: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Once you've checked that it works, mark it as verified here: <a href="https://%(pushmanager_servername)s/push?id=%(pushid)s"> https://%(pushmanager_servername)s/push?id=%(pushid)s </a> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict( { 'pushmaster': self.current_user, 'pushmanager_servername': Settings['main_app']['servername'], 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], 'pushid': self.pushid, }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has deployed request "%(title)s" for %(user)s to stage.\nPlease verify it at https://%(pushmanager_servername)s/push?id=%(pushid)s' % { 'pushmaster': self.current_user, 'pushmanager_servername': Settings['main_app']['servername'], 'title': req['title'], 'pushid': self.pushid, 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) push = push_result.fetchone() if push['extra_pings']: for user in push['extra_pings'].split(','): XMPPQueue.enqueue_user_xmpp( [user], '%s has deployed a push to stage.' % self.current_user)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) reqs, _, _ = db_results removal_dicts = [] for req in reqs: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = (""" <p> %(pushmaster)s has removed request for %(user)s from a push: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has removed request "%(title)s" for %(user)s from a push' % { 'pushmaster': self.current_user, 'title': req['title'], 'pushid': self.pushid, 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) removal_dicts.append({ 'request': req['id'], 'push': self.pushid, 'reason': 'removal after %s' % req['state'], 'pushmaster': self._current_user, 'timestamp': int(time.time()), }) removal_queries = [ db.push_removals.insert(removal) for removal in removal_dicts ] db.execute_transaction_cb(removal_queries, self.on_db_insert_complete)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) reqs, _, _ = db_results removal_dicts = [] for req in reqs: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = ( """ <p> %(pushmaster)s has removed request for %(user)s from a push: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has removed request "%(title)s" for %(user)s from a push' % { 'pushmaster': self.current_user, 'title': req['title'], 'pushid': self.pushid, 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) removal_dicts.append({ 'request': req['id'], 'push': self.pushid, 'reason': 'removal after %s' % req['state'], 'pushmaster': self._current_user, 'timestamp': int(time.time()), }) removal_queries = [db.push_removals.insert(removal) for removal in removal_dicts] db.execute_transaction_cb(removal_queries, self.on_db_insert_complete)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, blessed_requests, push_results = db_results for req in blessed_requests: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = ( """ <p> %(pushmaster)s has deployed request for %(user)s to production: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has deployed request "%(title)s" for %(user)s to production.' % { 'pushmaster': self.current_user, 'title': req['title'], 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) push = push_results.fetchone() if push['extra_pings']: for user in push['extra_pings'].split(','): XMPPQueue.enqueue_user_xmpp([user], '%s has deployed a push to production.' % self.current_user) self.finish()
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, blessed_requests, push_results = db_results for req in blessed_requests: if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = (""" <p> %(pushmaster)s has deployed request for %(user)s to production: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) msg = '%(pushmaster)s has deployed request "%(title)s" for %(user)s to production.' % { 'pushmaster': self.current_user, 'title': req['title'], 'user': user_string, } XMPPQueue.enqueue_user_xmpp(users, msg) push = push_results.fetchone() if push['extra_pings']: for user in push['extra_pings'].split(','): XMPPQueue.enqueue_user_xmpp( [user], '%s has deployed a push to production.' % self.current_user) self.finish()
def send_notifications(people, pushtype, pushurl): pushmanager_servername = Settings["main_app"]["servername"] pushmanager_servername = pushmanager_servername.rstrip("/") pushurl = pushurl.lstrip("/") pushmanager_url = "https://%s/%s" % (pushmanager_servername, pushurl) if people: msg = "%s: %s push starting! %s" % (", ".join(people), pushtype, pushmanager_url) XMPPQueue.enqueue_user_xmpp(people, "Push starting! %s" % pushmanager_url) elif pushtype == "morning": msg = "Morning push opened. %s" % pushmanager_servername else: msg = "push starting. %s" % pushmanager_url subprocess.call(["/nail/sys/bin/nodebot", "-i", Settings["irc"]["nickname"], Settings["irc"]["channel"], msg]) subject = "New push notification" MailQueue.enqueue_user_email(Settings["mail"]["notifyall"], msg, subject)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, req = db_results req = req.first() if req['state'] != 'discarded': # We didn't actually discard the record, for whatever reason return self.redirect("/requests?user=%s" % self.current_user) if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = ( """ <p> Request for %(user)s has been discarded: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) self.redirect("/requests?user=%s" % self.current_user)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) if db_results: req = db_results[1].first() msg = ( """ <p> %(pushmaster)s has commented on your request: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <pre> %(comment)s </pre> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': req['user'], 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], 'comment': self.comment, }) subject = "[push comment] %s - %s" % (req['user'], req['title']) MailQueue.enqueue_user_email([req['user']], msg, subject) msg = '%(pushmaster)s has commented on your request "%(title)s":\n%(comment)s' % { 'pushmaster': self.current_user, 'title': req['title'], 'comment': self.comment, } XMPPQueue.enqueue_user_xmpp([req['user']], msg) newcomments = req[db.push_requests.c.comments] self.write(xhtml_escape(newcomments))
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, _, _, _, live_requests = db_results for req in live_requests: if req['reviewid']: review_id = int(req['reviewid']) RBQueue.enqueue_review(review_id) if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = ( """ <p> %(pushmaster)s has certified request for %(user)s as stable in production: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, _, req = db_results req = req.first() if req['state'] != 'delayed': # We didn't actually discard the record, for whatever reason return self.redirect("/requests?user=%s" % self.current_user) if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = (""" <p> Request for %(user)s has been marked as delayed by %(pushmaster)s, and will not be accepted into pushes until you mark it as requested again: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject) self.redirect("/requests?user=%s" % self.current_user)
def send_notifications(people, pushtype, pushurl): pushmanager_servername = Settings['main_app']['servername'] pushmanager_servername = pushmanager_servername.rstrip('/') pushurl = pushurl.lstrip('/') pushmanager_url = "https://%s/%s" % (pushmanager_servername, pushurl) if people: msg = '%s: %s push starting! %s' % (', '.join(people), pushtype, pushmanager_url) XMPPQueue.enqueue_user_xmpp(people, 'Push starting! %s' % pushmanager_url) elif pushtype == 'morning': msg = 'Morning push opened. %s' % pushmanager_servername else: msg = 'push starting. %s' % pushmanager_url subprocess.call([ '/nail/sys/bin/nodebot', '-i', Settings['irc']['nickname'], Settings['irc']['channel'], msg ]) subject = "New push notification" MailQueue.enqueue_user_email(Settings['mail']['notifyall'], msg, subject)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, _, _, _, live_requests = db_results for req in live_requests: if req["reviewid"]: review_id = int(req["reviewid"]) RBQueue.enqueue_review(review_id) msg = ( ( """ <p> %(pushmaster)s has certified your request as stable in production: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""" ) % core.util.EscapedDict( { "pushmaster": self.current_user, "user": req["user"], "title": req["title"], "repo": req["repo"], "branch": req["branch"], } ) ) subject = "[push] %s - %s" % (req["user"], req["title"]) MailQueue.enqueue_user_email([req["user"]], msg, subject)
def on_db_complete(self, success, db_results): self.check_db_results(success, db_results) _, _, _, _, live_requests = db_results for req in live_requests: if req['reviewid']: review_id = int(req['reviewid']) RBQueue.enqueue_review(review_id) if req['watchers']: user_string = '%s (%s)' % (req['user'], req['watchers']) users = [req['user']] + req['watchers'].split(',') else: user_string = req['user'] users = [req['user']] msg = (""" <p> %(pushmaster)s has certified request for %(user)s as stable in production: </p> <p> <strong>%(user)s - %(title)s</strong><br /> <em>%(repo)s/%(branch)s</em> </p> <p> Regards,<br /> PushManager </p>""") % core.util.EscapedDict({ 'pushmaster': self.current_user, 'user': user_string, 'title': req['title'], 'repo': req['repo'], 'branch': req['branch'], }) subject = "[push] %s - %s" % (user_string, req['title']) MailQueue.enqueue_user_email(users, msg, subject)