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 | """ |
Congbin Guo | 31bd1a1 | 2020-06-02 17:47:13 -0700 | [diff] [blame] | 10 | from __future__ import print_function |
| 11 | |
Sanika Kulkarni | 92f96a4 | 2020-06-16 11:31:14 -0700 | [diff] [blame] | 12 | import cherrypy # pylint: disable=import-error |
| 13 | import nebraska_wrapper |
Congbin Guo | 31bd1a1 | 2020-06-02 17:47:13 -0700 | [diff] [blame] | 14 | |
| 15 | |
| 16 | def 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 |
| 26 | class 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 Kulkarni | 92f96a4 | 2020-06-16 11:31:14 -0700 | [diff] [blame] | 30 | label = '/'.join(args) |
Amin Hassani | 34f2861 | 2020-12-15 10:31:39 -0800 | [diff] [blame] | 31 | full_update = kwargs.pop('full_payload', 'unspecified') |
Sanika Kulkarni | c1f9804 | 2020-07-10 14:15:37 -0700 | [diff] [blame] | 32 | server_addr, _ = cherrypy.request.headers.get('X-Forwarded-Host').split(':') |
Congbin Guo | 31bd1a1 | 2020-06-02 17:47:13 -0700 | [diff] [blame] | 33 | body_length = int(cherrypy.request.headers.get('Content-Length', 0)) |
| 34 | data = cherrypy.request.rfile.read(body_length) |
Sanika Kulkarni | 92f96a4 | 2020-06-16 11:31:14 -0700 | [diff] [blame] | 35 | with nebraska_wrapper.NebraskaWrapper(label, server_addr, |
| 36 | full_update) as nb: |
| 37 | return nb.HandleUpdatePing(data, **kwargs) |