File: opts.py

package info (click to toggle)
python-oslo.limit 2.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 404 kB
  • sloc: python: 1,439; makefile: 25; sh: 2
file content (92 lines) | stat: -rw-r--r-- 2,799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#    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 copy
from typing import Any

from keystoneauth1 import loading
from oslo_config import cfg

from oslo_limit._i18n import _

__all__ = [
    'list_opts',
    'register_opts',
]

CONF = cfg.CONF

_options = [
    cfg.StrOpt(
        'endpoint_id',
        help=_("The service's endpoint id which is registered in Keystone."),
    ),
    cfg.StrOpt(
        'endpoint_service_name', help=_("Service name for endpoint discovery")
    ),
    cfg.StrOpt(
        'endpoint_service_type', help=_("Service type for endpoint discovery")
    ),
    cfg.StrOpt(
        'endpoint_region_name', help=_("Region to which the endpoint belongs")
    ),
    cfg.StrOpt(
        'endpoint_interface',
        default='public',
        choices=[
            'public',
            'publicURL',
            'internal',
            'internalURL',
            'admin',
            'adminURL',
        ],
        help=_("The interface for endpoint discovery"),
    ),
]

_option_group = 'oslo_limit'


def list_opts() -> list[tuple[str, list[cfg.Opt]]]:
    """Return a list of oslo.config options available in the library.

    :returns: a list of (group_name, opts) tuples
    """

    return [
        (
            _option_group,
            copy.deepcopy(_options)
            + loading.get_session_conf_options()
            + loading.get_auth_plugin_conf_options('password')
            + loading.get_auth_plugin_conf_options('v2password')
            + loading.get_auth_plugin_conf_options('v3password')
            + loading.get_adapter_conf_options(include_deprecated=False),
        )
    ]


def register_opts(conf: cfg.ConfigOpts) -> None:
    loading.register_session_conf_options(CONF, _option_group)
    loading.register_adapter_conf_options(
        CONF, _option_group, include_deprecated=False
    )

    loading.register_auth_conf_options(CONF, _option_group)
    plugin_name = CONF.oslo_limit.auth_type
    if plugin_name:
        plugin_loader: loading.BaseLoader[Any]
        plugin_loader = loading.get_plugin_loader(plugin_name)
        plugin_opts = loading.get_auth_plugin_conf_options(plugin_loader)
        CONF.register_opts(plugin_opts, group=_option_group)
    conf.register_opts(_options, group=_option_group)