Browse Source

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
Ben Nemec 3 months ago
parent
commit
c913b972b7
2 changed files with 31 additions and 1 deletions
  1. 28
    1
      oslo_privsep/priv_context.py
  2. 3
    0
      setup.cfg

+ 28
- 1
oslo_privsep/priv_context.py View File

@@ -12,7 +12,7 @@
12 12
 #    License for the specific language governing permissions and limitations
13 13
 #    under the License.
14 14
 
15
-
15
+import copy
16 16
 import enum
17 17
 import functools
18 18
 import logging
@@ -69,6 +69,33 @@ _ENTRYPOINT_ATTR = 'privsep_entrypoint'
69 69
 _HELPER_COMMAND_PREFIX = ['sudo']
70 70
 
71 71
 
72
+def _list_opts():
73
+    """Returns a list of oslo.config options available in the library.
74
+
75
+    The returned list includes all oslo.config options which may be registered
76
+    at runtime by the library.
77
+
78
+    Each element of the list is a tuple. The first element is the name of the
79
+    group under which the list of elements in the second element will be
80
+    registered. A group name of None corresponds to the [DEFAULT] group in
81
+    config files.
82
+
83
+    The purpose of this is to allow tools like the Oslo sample config file
84
+    generator to discover the options exposed to users by this library.
85
+
86
+    :returns: a list of (group_name, opts) tuples
87
+    """
88
+    # This is the default group name, but that can be overridden by the caller
89
+    group = cfg.OptGroup('privsep',
90
+                         title='oslo.privsep options',
91
+                         help='Configuration options for the oslo.privsep '
92
+                              'daemon. Note that this group name can be '
93
+                              'changed by the consuming service. Check the '
94
+                              'service\'s docs to see if this is the case.'
95
+                         )
96
+    return [(group, copy.deepcopy(OPTS))]
97
+
98
+
72 99
 @enum.unique
73 100
 class Method(enum.Enum):
74 101
     FORK = 1

+ 3
- 0
setup.cfg View File

@@ -39,6 +39,9 @@ warning-is-error = 1
39 39
 console_scripts =
40 40
     privsep-helper = oslo_privsep.daemon:helper_main
41 41
 
42
+oslo.config.opts =
43
+    oslo.privsep = oslo_privsep.priv_context:_list_opts
44
+
42 45
 [upload_sphinx]
43 46
 upload-dir = doc/build/html
44 47
 

Loading…
Cancel
Save