| OLD | NEW |
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """This module defines Swarming Server endpoints handlers.""" | 5 """This module defines Swarming Server endpoints handlers.""" |
| 6 | 6 |
| 7 import datetime | 7 import datetime |
| 8 import logging | 8 import logging |
| 9 import os |
| 9 | 10 |
| 10 from google.appengine.api import datastore_errors | 11 from google.appengine.api import datastore_errors |
| 11 from google.appengine.ext import ndb | 12 from google.appengine.ext import ndb |
| 12 import endpoints | 13 import endpoints |
| 13 import gae_ts_mon | 14 import gae_ts_mon |
| 14 from protorpc import messages | 15 from protorpc import messages |
| 15 from protorpc import message_types | 16 from protorpc import message_types |
| 16 from protorpc import protojson | 17 from protorpc import protojson |
| 17 from protorpc import remote | 18 from protorpc import remote |
| 18 | 19 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 127 |
| 127 @swarming_api.api_class(resource_name='server', path='server') | 128 @swarming_api.api_class(resource_name='server', path='server') |
| 128 class SwarmingServerService(remote.Service): | 129 class SwarmingServerService(remote.Service): |
| 129 @gae_ts_mon.instrument_endpoint() | 130 @gae_ts_mon.instrument_endpoint() |
| 130 @auth.endpoints_method( | 131 @auth.endpoints_method( |
| 131 message_types.VoidMessage, swarming_rpcs.ServerDetails, | 132 message_types.VoidMessage, swarming_rpcs.ServerDetails, |
| 132 http_method='GET') | 133 http_method='GET') |
| 133 @auth.require(acl.is_bot_or_user) | 134 @auth.require(acl.is_bot_or_user) |
| 134 def details(self, _request): | 135 def details(self, _request): |
| 135 """Returns information about the server.""" | 136 """Returns information about the server.""" |
| 136 return swarming_rpcs.ServerDetails(server_version=utils.get_app_version()) | 137 host = 'https://' + os.environ['HTTP_HOST'] |
| 138 return swarming_rpcs.ServerDetails( |
| 139 bot_version = bot_code.get_bot_version(host), |
| 140 server_version = utils.get_app_version()) |
| 137 | 141 |
| 138 @gae_ts_mon.instrument_endpoint() | 142 @gae_ts_mon.instrument_endpoint() |
| 139 @auth.endpoints_method( | 143 @auth.endpoints_method( |
| 144 message_types.VoidMessage, swarming_rpcs.BootstrapToken) |
| 145 @auth.require(acl.is_bootstrapper) |
| 146 def token(self, _request): |
| 147 """Returns a token to bootstrap a new bot.""" |
| 148 return swarming_rpcs.BootstrapToken( |
| 149 bootstrap_token = bot_code.generate_bootstrap_token(), |
| 150 ) |
| 151 |
| 152 @gae_ts_mon.instrument_endpoint() |
| 153 @auth.endpoints_method( |
| 140 message_types.VoidMessage, swarming_rpcs.ClientPermissions, | 154 message_types.VoidMessage, swarming_rpcs.ClientPermissions, |
| 141 http_method='GET') | 155 http_method='GET') |
| 142 @auth.public | 156 @auth.public |
| 143 def permissions(self, _request): | 157 def permissions(self, _request): |
| 144 """Returns the caller's permissions.""" | 158 """Returns the caller's permissions.""" |
| 145 return swarming_rpcs.ClientPermissions( | 159 return swarming_rpcs.ClientPermissions( |
| 146 delete_bot = acl.is_admin(), | 160 delete_bot = acl.is_admin(), |
| 147 terminate_bot = acl.is_privileged_user(), | 161 terminate_bot = acl.is_privileged_user(), |
| 148 get_configs = acl.is_user(), | 162 get_configs = acl.is_user(), |
| 149 put_configs = acl.is_admin(), | 163 put_configs = acl.is_admin(), |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 def get_routes(): | 729 def get_routes(): |
| 716 return ( | 730 return ( |
| 717 endpoints_webapp2.api_routes(SwarmingServerService) + | 731 endpoints_webapp2.api_routes(SwarmingServerService) + |
| 718 endpoints_webapp2.api_routes(SwarmingTaskService) + | 732 endpoints_webapp2.api_routes(SwarmingTaskService) + |
| 719 endpoints_webapp2.api_routes(SwarmingTasksService) + | 733 endpoints_webapp2.api_routes(SwarmingTasksService) + |
| 720 endpoints_webapp2.api_routes(SwarmingBotService) + | 734 endpoints_webapp2.api_routes(SwarmingBotService) + |
| 721 endpoints_webapp2.api_routes(SwarmingBotsService) + | 735 endpoints_webapp2.api_routes(SwarmingBotsService) + |
| 722 # components.config endpoints for validation and configuring of luci-config | 736 # components.config endpoints for validation and configuring of luci-config |
| 723 # service URL. | 737 # service URL. |
| 724 endpoints_webapp2.api_routes(config.ConfigApi)) | 738 endpoints_webapp2.api_routes(config.ConfigApi)) |
| OLD | NEW |