blob: c0968d033614584f2b860f2f13e5a795eb29092e [file] [log] [blame]
Congbin Guo31bd1a12020-06-02 17:47:13 -07001# -*- coding: utf-8 -*-
2# Copyright 2020 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""An cherry app to play as a fake Omaha service.
7
8This is a short term solution in order to deprecation devserver.py from labs.
9"""
Congbin Guo31bd1a12020-06-02 17:47:13 -070010from __future__ import print_function
11
Sanika Kulkarni92f96a42020-06-16 11:31:14 -070012import cherrypy # pylint: disable=import-error
13import nebraska_wrapper
Congbin Guo31bd1a12020-06-02 17:47:13 -070014
15
16def get_config():
17 """Get cherrypy config for this application."""
18 return {
19 '/': {
20 'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
21 }
22 }
23
24
25@cherrypy.expose
26class FakeOmaha(object):
27 """An application to handle fake Omaha requests."""
28 def POST(self, *args, **kwargs):
29 """A URL handler to handle update check ping."""
Sanika Kulkarni92f96a42020-06-16 11:31:14 -070030 label = '/'.join(args)
Amin Hassani34f28612020-12-15 10:31:39 -080031 full_update = kwargs.pop('full_payload', 'unspecified')
Sanika Kulkarnic1f98042020-07-10 14:15:37 -070032 server_addr, _ = cherrypy.request.headers.get('X-Forwarded-Host').split(':')
Congbin Guo31bd1a12020-06-02 17:47:13 -070033 body_length = int(cherrypy.request.headers.get('Content-Length', 0))
34 data = cherrypy.request.rfile.read(body_length)
Sanika Kulkarni92f96a42020-06-16 11:31:14 -070035 with nebraska_wrapper.NebraskaWrapper(label, server_addr,
36 full_update) as nb:
37 return nb.HandleUpdatePing(data, **kwargs)