GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — develop ( ee2b60...7df2da )
by Plexxi
11:50 queued 05:56
created

main()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 8
rs 9.4285
1
#!/usr/bin/env python
2
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
3
# contributor license agreements.  See the NOTICE file distributed with
4
# this work for additional information regarding copyright ownership.
5
# The ASF licenses this file to You under the Apache License, Version 2.0
6
# (the "License"); you may not use this file except in compliance with
7
# the License.  You may obtain a copy of the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16
17
import collections
18
import importlib
19
import six
20
import sys
21
import traceback
22
23
from oslo_config import cfg
24
25
26
CONFIGS = ['st2actions.config',
27
           'st2actions.notifier.config',
28
           'st2actions.resultstracker.config',
29
           'st2api.config',
30
           'st2stream.config',
31
           'st2auth.config',
32
           'st2common.config',
33
           'st2exporter.config',
34
           'st2reactor.rules.config',
35
           'st2reactor.sensor.config',
36
           'st2reactor.garbage_collector.config']
37
38
SKIP_GROUPS = ['api_pecan', 'rbac']
39
40
# We group auth options together to nake it a bit more clear what applies where
41
AUTH_OPTIONS = {
42
    'common': [
43
        'enable',
44
        'mode',
45
        'logging',
46
        'api_url',
47
        'token_ttl',
48
        'debug'
49
    ],
50
    'standalone': [
51
        'host',
52
        'port',
53
        'use_ssl',
54
        'cert',
55
        'key',
56
        'backend',
57
        'backend_kwargs'
58
    ]
59
}
60
61
COMMON_AUTH_OPTIONS_COMMENT = """
62
# Common option - options below apply in both scenarios - when auth service is running as a WSGI
63
# service (e.g. under Apache or Nginx) and when it's running in the standalone mode.
64
""".strip()
65
66
STANDALONE_AUTH_OPTIONS_COMMENT = """
67
# Standalone mode options - options below only apply when auth service is running in the standalone
68
# mode.
69
""".strip()
70
71
72
def _import_config(config):
73
    try:
74
        return importlib.import_module(config)
75
    except:
76
        traceback.print_exc()
77
    return None
78
79
80
def _read_current_config(opt_groups):
81
    for k, v in six.iteritems(cfg.CONF._groups):
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _groups was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
82
        if k in SKIP_GROUPS:
83
            continue
84
        if k not in opt_groups:
85
            opt_groups[k] = v
86
    return opt_groups
87
88
89
def _clear_config():
90
    cfg.CONF.reset()
91
92
93
def _read_group(opt_group):
94
    all_options = opt_group._opts.values()
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _opts was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
95
96
    if opt_group.name == 'auth':
97
        print(COMMON_AUTH_OPTIONS_COMMENT)
98
        print('')
99
        common_options = [option for option in all_options if option['opt'].name in
100
                          AUTH_OPTIONS['common']]
101
        _print_options(options=common_options)
102
103
        print('')
104
        print(STANDALONE_AUTH_OPTIONS_COMMENT)
105
        print('')
106
        standalone_options = [option for option in all_options if option['opt'].name in
107
                              AUTH_OPTIONS['standalone']]
108
        _print_options(options=standalone_options)
109
110
        if len(common_options) + len(standalone_options) != len(all_options):
111
            msg = ('Not all options are declared in AUTH_OPTIONS dict, please update it')
112
            raise Exception(msg)
113
    else:
114
        options = all_options
115
        _print_options(options=options)
116
117
118
def _read_groups(opt_groups):
119
    opt_groups = collections.OrderedDict(sorted(opt_groups.items()))
120
    for name, opt_group in six.iteritems(opt_groups):
121
        print('[%s]' % name)
122
        _read_group(opt_group)
123
        print('')
124
125
126
def _print_options(options):
127
    for opt in options:
128
        opt = opt['opt']
129
130
        # Special handling for list options
131
        if isinstance(opt, cfg.ListOpt):
132
            if opt.default:
133
                value = ','.join(opt.default)
134
            else:
135
                value = ''
136
137
            value += ' # comma separated list allowed here.'
138
        else:
139
            value = opt.default
140
141
        print('# %s' % opt.help)
142
        print('%s = %s' % (opt.name, value))
143
144
145
def main(args):
146
    opt_groups = {}
147
    for config in CONFIGS:
148
        mod = _import_config(config)
149
        mod.register_opts()
150
        _read_current_config(opt_groups)
151
        _clear_config()
152
    _read_groups(opt_groups)
153
154
155
if __name__ == '__main__':
156
    main(sys.argv)
157