Congbin Guo | 31bd1a1 | 2020-06-02 17:47:13 -0700 | [diff] [blame] | 1 | # -*- 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 | |
| 8 | This is a short term solution in order to deprecation devserver.py from labs. |
| 9 | """ |
| 10 | from __future__ import absolute_import |
| 11 | from __future__ import division |
| 12 | from __future__ import print_function |
| 13 | |
Sanika Kulkarni | 92f96a4 | 2020-06-16 11:31:14 -0700 | [diff] [blame^] | 14 | import cherrypy # pylint: disable=import-error |
| 15 | import nebraska_wrapper |
Congbin Guo | 31bd1a1 | 2020-06-02 17:47:13 -0700 | [diff] [blame] | 16 | |
| 17 | |
| 18 | def 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 |
| 28 | class 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 Kulkarni | 92f96a4 | 2020-06-16 11:31:14 -0700 | [diff] [blame^] | 32 | label = '/'.join(args) |
| 33 | full_update = kwargs.pop('full_update', 'unspecified') |
| 34 | server_addr = cherrypy.request.headers.get('X-Server-Addr') |
Congbin Guo | 31bd1a1 | 2020-06-02 17:47:13 -0700 | [diff] [blame] | 35 | body_length = int(cherrypy.request.headers.get('Content-Length', 0)) |
| 36 | data = cherrypy.request.rfile.read(body_length) |
Sanika Kulkarni | 92f96a4 | 2020-06-16 11:31:14 -0700 | [diff] [blame^] | 37 | with nebraska_wrapper.NebraskaWrapper(label, server_addr, |
| 38 | full_update) as nb: |
| 39 | return nb.HandleUpdatePing(data, **kwargs) |