| 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 import os |
| 10 | 10 |
| 11 from google.appengine.api import datastore_errors | 11 from google.appengine.api import datastore_errors |
| 12 from google.appengine.ext import ndb | 12 from google.appengine.ext import ndb |
| 13 import endpoints | 13 import endpoints |
| 14 import gae_ts_mon | 14 import gae_ts_mon |
| 15 from protorpc import messages | 15 from protorpc import messages |
| 16 from protorpc import message_types | 16 from protorpc import message_types |
| 17 from protorpc import protojson | 17 from protorpc import protojson |
| 18 from protorpc import remote | 18 from protorpc import remote |
| 19 | 19 |
| 20 from components import auth | 20 from components import auth |
| 21 from components import datastore_utils | 21 from components import datastore_utils |
| 22 from components import endpoints_webapp2 | 22 from components import endpoints_webapp2 |
| 23 from components import machine_provider |
| 23 from components import utils | 24 from components import utils |
| 24 | 25 |
| 25 import message_conversion | 26 import message_conversion |
| 26 import swarming_rpcs | 27 import swarming_rpcs |
| 27 from server import acl | 28 from server import acl |
| 28 from server import bot_code | 29 from server import bot_code |
| 29 from server import bot_management | 30 from server import bot_management |
| 30 from server import config | 31 from server import config |
| 31 from server import task_pack | 32 from server import task_pack |
| 32 from server import task_request | 33 from server import task_request |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 @swarming_api.api_class(resource_name='server', path='server') | 129 @swarming_api.api_class(resource_name='server', path='server') |
| 129 class SwarmingServerService(remote.Service): | 130 class SwarmingServerService(remote.Service): |
| 130 @gae_ts_mon.instrument_endpoint() | 131 @gae_ts_mon.instrument_endpoint() |
| 131 @auth.endpoints_method( | 132 @auth.endpoints_method( |
| 132 message_types.VoidMessage, swarming_rpcs.ServerDetails, | 133 message_types.VoidMessage, swarming_rpcs.ServerDetails, |
| 133 http_method='GET') | 134 http_method='GET') |
| 134 @auth.require(acl.is_bot_or_user) | 135 @auth.require(acl.is_bot_or_user) |
| 135 def details(self, _request): | 136 def details(self, _request): |
| 136 """Returns information about the server.""" | 137 """Returns information about the server.""" |
| 137 host = 'https://' + os.environ['HTTP_HOST'] | 138 host = 'https://' + os.environ['HTTP_HOST'] |
| 139 |
| 140 mpp = '' |
| 141 if config.settings().mp and config.settings().mp.server: |
| 142 mpp = config.settings().mp.server |
| 143 # as a fallback, try pulling from datastore |
| 144 if not mpp: |
| 145 mpp = machine_provider.MachineProviderConfiguration.get_instance_url() |
| 146 if mpp: |
| 147 mpp = mpp + '/leases/%s' |
| 148 |
| 138 return swarming_rpcs.ServerDetails( | 149 return swarming_rpcs.ServerDetails( |
| 139 bot_version = bot_code.get_bot_version(host), | 150 bot_version = bot_code.get_bot_version(host), |
| 140 server_version = utils.get_app_version()) | 151 server_version = utils.get_app_version(), |
| 152 machine_provider_template = mpp, |
| 153 display_server_url_template = |
| 154 config.settings().display_server_url_template) |
| 141 | 155 |
| 142 @gae_ts_mon.instrument_endpoint() | 156 @gae_ts_mon.instrument_endpoint() |
| 143 @auth.endpoints_method( | 157 @auth.endpoints_method( |
| 144 message_types.VoidMessage, swarming_rpcs.BootstrapToken) | 158 message_types.VoidMessage, swarming_rpcs.BootstrapToken) |
| 145 @auth.require(acl.is_bootstrapper) | 159 @auth.require(acl.is_bootstrapper) |
| 146 def token(self, _request): | 160 def token(self, _request): |
| 147 """Returns a token to bootstrap a new bot.""" | 161 """Returns a token to bootstrap a new bot.""" |
| 148 return swarming_rpcs.BootstrapToken( | 162 return swarming_rpcs.BootstrapToken( |
| 149 bootstrap_token = bot_code.generate_bootstrap_token(), | 163 bootstrap_token = bot_code.generate_bootstrap_token(), |
| 150 ) | 164 ) |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 def get_routes(): | 743 def get_routes(): |
| 730 return ( | 744 return ( |
| 731 endpoints_webapp2.api_routes(SwarmingServerService) + | 745 endpoints_webapp2.api_routes(SwarmingServerService) + |
| 732 endpoints_webapp2.api_routes(SwarmingTaskService) + | 746 endpoints_webapp2.api_routes(SwarmingTaskService) + |
| 733 endpoints_webapp2.api_routes(SwarmingTasksService) + | 747 endpoints_webapp2.api_routes(SwarmingTasksService) + |
| 734 endpoints_webapp2.api_routes(SwarmingBotService) + | 748 endpoints_webapp2.api_routes(SwarmingBotService) + |
| 735 endpoints_webapp2.api_routes(SwarmingBotsService) + | 749 endpoints_webapp2.api_routes(SwarmingBotsService) + |
| 736 # components.config endpoints for validation and configuring of luci-config | 750 # components.config endpoints for validation and configuring of luci-config |
| 737 # service URL. | 751 # service URL. |
| 738 endpoints_webapp2.api_routes(config.ConfigApi)) | 752 endpoints_webapp2.api_routes(config.ConfigApi)) |
| OLD | NEW |