| OLD | NEW |
| 1 # Copyright 2015 The Swarming Authors. All rights reserved. | 1 # Copyright 2015 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 """Adapter between luci-config client and the rest of auth_service.""" | 5 """Adapter between config service client and the rest of auth_service.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 | 8 |
| 9 from components import config | 9 from components import config |
| 10 | 10 |
| 11 | 11 |
| 12 def is_remote_configured(): | 12 def is_remote_configured(): |
| 13 """True if luci-config backend URL is defined. | 13 """True if config service backend URL is defined. |
| 14 | 14 |
| 15 If luci-config backend URL is not set auth_service will use datastore | 15 If config service backend URL is not set auth_service will use datastore |
| 16 as source of truth for configuration (with some simple web UI to change it). | 16 as source of truth for configuration (with some simple web UI to change it). |
| 17 | 17 |
| 18 If luci-config backend URL is set, UI for config management will be read only | 18 If config service backend URL is set, UI for config management will be read |
| 19 and all config changes must be performed through luci-config. | 19 only and all config changes must be performed through the config service. |
| 20 """ | 20 """ |
| 21 return bool(get_remote_url()) | 21 return bool(get_remote_url()) |
| 22 | 22 |
| 23 | 23 |
| 24 def get_remote_url(): | 24 def get_remote_url(): |
| 25 """Returns URL of luci-config service if configured, to display in UI.""" | 25 """Returns URL of a config service if configured, to display in UI.""" |
| 26 settings = config.ConfigSettings.cached() | 26 settings = config.ConfigSettings.cached() |
| 27 if settings and settings.service_hostname: | 27 if settings and settings.service_hostname: |
| 28 return 'https://%s' % settings.service_hostname | 28 return 'https://%s' % settings.service_hostname |
| 29 return None | 29 return None |
| 30 | 30 |
| 31 | 31 |
| 32 def refetch_config(): | 32 def refetch_config(): |
| 33 """Refetches all configs from luci-config (if enabled). | 33 """Refetches all configs from a config service (if enabled). |
| 34 | 34 |
| 35 Called as a cron job. | 35 Called as a cron job. |
| 36 """ | 36 """ |
| 37 if not is_remote_configured(): | 37 if not is_remote_configured(): |
| 38 logging.info('Remote is not configured') | 38 logging.info('Remote is not configured') |
| 39 return | 39 return |
| 40 # TODO(vadimsh): Implement, add to cron.yaml when implemented. | 40 # TODO(vadimsh): Implement, add to cron.yaml when implemented. |
| OLD | NEW |