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 — kale/action-datastore ( 9f47ff...fd1ef0 )
by
unknown
12:31 queued 06:24
created

st2client.Client.__init__()   F

Complexity

Conditions 9

Size

Total Lines 79

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 79
rs 3.8175
cc 9

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
import os
17
import logging
18
19
import six
20
21
from st2client import models
22
from st2client.models.core import ResourceManager
23
from st2client.models.core import ActionAliasResourceManager
24
from st2client.models.core import LiveActionResourceManager
25
from st2client.models.core import TriggerInstanceResourceManager
26
27
28
LOG = logging.getLogger(__name__)
29
30
# Default values for the options not explicitly specified by the user
31
DEFAULT_API_PORT = 9101
32
DEFAULT_AUTH_PORT = 9100
33
34
DEFAULT_BASE_URL = 'http://127.0.0.1'
35
DEFAULT_API_VERSION = 'v1'
36
37
38
class Client(object):
39
    def __init__(self, base_url=None, auth_url=None, api_url=None, api_version=None, cacert=None,
40
                 debug=False, token=None):
41
        # Get CLI options. If not given, then try to get it from the environment.
42
        self.endpoints = dict()
43
44
        # Populate the endpoints
45
        if base_url:
46
            self.endpoints['base'] = base_url
47
        else:
48
            self.endpoints['base'] = os.environ.get('ST2_BASE_URL', DEFAULT_BASE_URL)
49
50
        api_version = api_version or os.environ.get('ST2_API_VERSION', DEFAULT_API_VERSION)
51
52
        if api_url:
53
            self.endpoints['api'] = api_url
54
        else:
55
            self.endpoints['api'] = os.environ.get(
56
                'ST2_API_URL', '%s:%s/%s' % (self.endpoints['base'], DEFAULT_API_PORT, api_version))
57
58
        if auth_url:
59
            self.endpoints['auth'] = auth_url
60
        else:
61
            self.endpoints['auth'] = os.environ.get(
62
                'ST2_AUTH_URL', '%s:%s' % (self.endpoints['base'], DEFAULT_AUTH_PORT))
63
64
        if cacert is not None:
65
            self.cacert = cacert
66
        else:
67
            self.cacert = os.environ.get('ST2_CACERT', None)
68
69
        # Note: boolean is also a valid value for "cacert"
70
        is_cacert_string = isinstance(self.cacert, six.string_types)
71
        if (self.cacert and is_cacert_string and not os.path.isfile(self.cacert)):
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after if.
Loading history...
72
            raise ValueError('CA cert file "%s" does not exist.' % (self.cacert))
73
74
        self.debug = debug
75
76
        # Note: This is a nasty hack for now, but we need to get rid of the decrator abuse
77
        if token:
78
            os.environ['ST2_AUTH_TOKEN'] = token
79
80
        self.token = token
81
82
        # Instantiate resource managers and assign appropriate API endpoint.
83
        self.managers = dict()
84
        self.managers['Token'] = ResourceManager(
85
            models.Token, self.endpoints['auth'], cacert=self.cacert, debug=self.debug)
86
        self.managers['RunnerType'] = ResourceManager(
87
            models.RunnerType, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
88
        self.managers['Action'] = ResourceManager(
89
            models.Action, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
90
        self.managers['ActionAlias'] = ActionAliasResourceManager(
91
            models.ActionAlias, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
92
        self.managers['ApiKey'] = ResourceManager(
93
            models.ApiKey, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
94
        self.managers['LiveAction'] = LiveActionResourceManager(
95
            models.LiveAction, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
96
        self.managers['Policy'] = ResourceManager(
97
            models.Policy, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
98
        self.managers['PolicyType'] = ResourceManager(
99
            models.PolicyType, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
100
        self.managers['Rule'] = ResourceManager(
101
            models.Rule, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
102
        self.managers['Sensor'] = ResourceManager(
103
            models.Sensor, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
104
        self.managers['TriggerType'] = ResourceManager(
105
            models.TriggerType, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
106
        self.managers['Trigger'] = ResourceManager(
107
            models.Trigger, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
108
        self.managers['TriggerInstance'] = TriggerInstanceResourceManager(
109
            models.TriggerInstance, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
110
        self.managers['KeyValuePair'] = ResourceManager(
111
            models.KeyValuePair, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
112
        self.managers['Webhook'] = ResourceManager(
113
            models.Webhook, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
114
        self.managers['Trace'] = ResourceManager(
115
            models.Trace, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
116
        self.managers['RuleEnforcement'] = ResourceManager(
117
            models.RuleEnforcement, self.endpoints['api'], cacert=self.cacert, debug=self.debug)
118
119
    @property
120
    def actions(self):
121
        return self.managers['Action']
122
123
    @property
124
    def apikeys(self):
125
        return self.managers['ApiKey']
126
127
    @property
128
    def keys(self):
129
        return self.managers['KeyValuePair']
130
131
    @property
132
    def liveactions(self):
133
        return self.managers['LiveAction']
134
135
    @property
136
    def policies(self):
137
        return self.managers['Policy']
138
139
    @property
140
    def policytypes(self):
141
        return self.managers['PolicyType']
142
143
    @property
144
    def rules(self):
145
        return self.managers['Rule']
146
147
    @property
148
    def runners(self):
149
        return self.managers['RunnerType']
150
151
    @property
152
    def sensors(self):
153
        return self.managers['Sensor']
154
155
    @property
156
    def tokens(self):
157
        return self.managers['Token']
158
159
    @property
160
    def triggertypes(self):
161
        return self.managers['TriggerType']
162
163
    @property
164
    def triggerinstances(self):
165
        return self.managers['TriggerInstance']
166
167
    @property
168
    def trace(self):
169
        return self.managers['Trace']
170
171
    @property
172
    def ruleenforcements(self):
173
        return self.managers['RuleEnforcement']
174