zuul/zuul/lib/capabilities.py
Matthieu Huin b001fa8fa3 OIDCAuthenticator: add capabilities, scope option
The OIDC Authenticator can be configured to specify scope(s).
By default, use scopes "openid profile", the smallest subset of scopes
supported by all OpenID Connect Identity Providers.

Add a basic capability register for the web service. This is simply
meant to expose configuration details that can be public, so that
other services (namely zuul web-app) can access them through the REST
API.

Fix capability 'job_history' by setting it to True if a SQL driver is
active.

Change-Id: I6ec0338cc0f7c0756c0cb26d6e5b3732c3ca655c
2020-03-27 16:47:21 +00:00

52 lines
1.6 KiB
Python

# Copyright 2020 OpenStack Foundation
# Copyright 2020 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
"""Simple Capabilities registry, to be used by Zuul Web."""
class CapabilitiesRegistry(object):
log = logging.getLogger("Zuul.CapabilitiesRegistry")
def __init__(self):
self.capabilities = {}
self.set_default_capabilities()
def set_default_capabilities(self):
self.capabilities['job_history'] = False
self.capabilities['auth'] = {
'realms': {},
'default_realm': None,
}
def register_capabilities(self, capability_name, capabilities):
is_set = self.capabilities.setdefault(capability_name, None)
if is_set is None:
action = 'registered'
else:
action = 'updated'
if isinstance(is_set, dict) and isinstance(capabilities, dict):
self.capabilities[capability_name].update(capabilities)
else:
self.capabilities[capability_name] = capabilities
self.log.debug('Capabilities "%s" %s' % (capability_name, action))
capabilities_registry = CapabilitiesRegistry()