| OLD | NEW |
| 1 # Copyright 2014 The Swarming Authors. All rights reserved. | 1 # Copyright 2014 The Swarming Authors. All rights reserved. |
| 2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed by the Apache v2.0 license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """This module defines Auth Server frontend url handlers.""" | 5 """This module defines Auth Server frontend url handlers.""" |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 | 8 |
| 9 import webapp2 | 9 import webapp2 |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 expiration_sec = 24 * 3600 | 87 expiration_sec = 24 * 3600 |
| 88 secret_key = auth.SecretKey('link_ticket_token', scope='local') | 88 secret_key = auth.SecretKey('link_ticket_token', scope='local') |
| 89 version = 1 | 89 version = 1 |
| 90 | 90 |
| 91 | 91 |
| 92 class ImporterConfigHandler(auth.ApiHandler): | 92 class ImporterConfigHandler(auth.ApiHandler): |
| 93 """Reads and sets configuration of the group importer.""" | 93 """Reads and sets configuration of the group importer.""" |
| 94 | 94 |
| 95 @auth.require(auth.is_admin) | 95 @auth.require(auth.is_admin) |
| 96 def get(self): | 96 def get(self): |
| 97 self.send_response({'config': importer.read_config()}) | 97 self.send_response({'config': importer.read_config_text()}) |
| 98 | 98 |
| 99 @auth.require(auth.is_admin) | 99 @auth.require(auth.is_admin) |
| 100 def post(self): | 100 def post(self): |
| 101 if config.is_remote_configured(): | 101 if config.is_remote_configured(): |
| 102 self.abort_with_error(409, text='The configuration is managed elsewhere') | 102 self.abort_with_error(409, text='The configuration is managed elsewhere') |
| 103 conf = self.parse_body().get('config') | 103 try: |
| 104 if not importer.is_valid_config(conf): | 104 importer.write_config_text(self.parse_body().get('config')) |
| 105 self.abort_with_error(400, text='Invalid config format.') | 105 except ValueError as ex: |
| 106 importer.write_config(conf) | 106 self.abort_with_error(400, text=str(ex)) |
| 107 self.send_response({'ok': True}) | 107 self.send_response({'ok': True}) |
| 108 | 108 |
| 109 | 109 |
| 110 class ServiceListingHandler(auth.ApiHandler): | 110 class ServiceListingHandler(auth.ApiHandler): |
| 111 """Lists registered replicas with their state.""" | 111 """Lists registered replicas with their state.""" |
| 112 | 112 |
| 113 @auth.require(auth.is_admin) | 113 @auth.require(auth.is_admin) |
| 114 def get(self): | 114 def get(self): |
| 115 services = sorted( | 115 services = sorted( |
| 116 replication.AuthReplicaState.query( | 116 replication.AuthReplicaState.query( |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 env_callback=get_additional_ui_environment) | 275 env_callback=get_additional_ui_environment) |
| 276 template.bootstrap({'auth_service': TEMPLATES_DIR}) | 276 template.bootstrap({'auth_service': TEMPLATES_DIR}) |
| 277 | 277 |
| 278 # Add a fake admin for local dev server. | 278 # Add a fake admin for local dev server. |
| 279 if utils.is_local_dev_server(): | 279 if utils.is_local_dev_server(): |
| 280 auth.bootstrap_group( | 280 auth.bootstrap_group( |
| 281 auth.ADMIN_GROUP, | 281 auth.ADMIN_GROUP, |
| 282 [auth.Identity(auth.IDENTITY_USER, 'test@example.com')], | 282 [auth.Identity(auth.IDENTITY_USER, 'test@example.com')], |
| 283 'Users that can manage groups') | 283 'Users that can manage groups') |
| 284 return webapp2.WSGIApplication(get_routes(), debug=debug) | 284 return webapp2.WSGIApplication(get_routes(), debug=debug) |
| OLD | NEW |