From c913b972b71fcd3d987b1d28473eb1075af31e43 Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Thu, 10 Jan 2019 17:26:44 +0000 Subject: [PATCH] Expose privsep options for config-generator We were missing the oslo-config-generator entrypoint in this library, which meant there was no way to include the privsep opts in a service's sample config file. One complication is that it is possible to override the group name for the opts. I assume this was done to allow services to run multiple privsep daemons with different levels of permission, but it means that the service will have to document any additional or different group names that it may use. Change-Id: I1ef30cb14d365f4bbfa580e75afc3580910d6fcf --- oslo_privsep/priv_context.py | 29 ++++++++++++++++++++++++++++- setup.cfg | 3 +++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/oslo_privsep/priv_context.py b/oslo_privsep/priv_context.py index 1b44861..0261b08 100644 --- a/oslo_privsep/priv_context.py +++ b/oslo_privsep/priv_context.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. - +import copy import enum import functools import logging @@ -69,6 +69,33 @@ _ENTRYPOINT_ATTR = 'privsep_entrypoint' _HELPER_COMMAND_PREFIX = ['sudo'] +def _list_opts(): + """Returns a list of oslo.config options available in the library. + + The returned list includes all oslo.config options which may be registered + at runtime by the library. + + Each element of the list is a tuple. The first element is the name of the + group under which the list of elements in the second element will be + registered. A group name of None corresponds to the [DEFAULT] group in + config files. + + The purpose of this is to allow tools like the Oslo sample config file + generator to discover the options exposed to users by this library. + + :returns: a list of (group_name, opts) tuples + """ + # This is the default group name, but that can be overridden by the caller + group = cfg.OptGroup('privsep', + title='oslo.privsep options', + help='Configuration options for the oslo.privsep ' + 'daemon. Note that this group name can be ' + 'changed by the consuming service. Check the ' + 'service\'s docs to see if this is the case.' + ) + return [(group, copy.deepcopy(OPTS))] + + @enum.unique class Method(enum.Enum): FORK = 1 diff --git a/setup.cfg b/setup.cfg index 71c727a..3d8372a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,6 +39,9 @@ warning-is-error = 1 console_scripts = privsep-helper = oslo_privsep.daemon:helper_main +oslo.config.opts = + oslo.privsep = oslo_privsep.priv_context:_list_opts + [upload_sphinx] upload-dir = doc/build/html