blob: 8660fcab9ed3ce5b1c8df35373ad7960838c6a43 [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"""
10from __future__ import absolute_import
11from __future__ import division
12from __future__ import print_function
13
Sanika Kulkarni92f96a42020-06-16 11:31:14 -070014import cherrypy # pylint: disable=import-error
15import nebraska_wrapper
Congbin Guo31bd1a12020-06-02 17:47:13 -070016
17
18def get_config():
19 """Get cherrypy config for this application."""
20 return {
21 '/': {
22 'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
23 }
24 }
25
26
27@cherrypy.expose
28class FakeOmaha(object):
29 """An application to handle fake Omaha requests."""
30 def POST(self, *args, **kwargs):
31 """A URL handler to handle update check ping."""
Sanika Kulkarni92f96a42020-06-16 11:31:14 -070032 label = '/'.join(args)
33 full_update = kwargs.pop('full_update', 'unspecified')
34 server_addr = cherrypy.request.headers.get('X-Server-Addr')
Congbin Guo31bd1a12020-06-02 17:47:13 -070035 body_length = int(cherrypy.request.headers.get('Content-Length', 0))
36 data = cherrypy.request.rfile.read(body_length)
Sanika Kulkarni92f96a42020-06-16 11:31:14 -070037 with nebraska_wrapper.NebraskaWrapper(label, server_addr,
38 full_update) as nb:
39 return nb.HandleUpdatePing(data, **kwargs)