@@ -110,29 +110,31 @@ def bail(self, msg):
110
110
111
111
def get_api_settings (self ):
112
112
'''
113
- Return a hash of API settings derived first from ENV['sensu_api_url ']
113
+ Return a dict of API settings derived first from ENV['SENSU_API_URL ']
114
114
if set, then Sensu config `api` scope if configured, and finally
115
115
falling back to to ipv4 localhost address on default API port.
116
116
117
117
return dict
118
118
'''
119
119
120
- sensu_api_url = os .environ .get ('sensu_api_url ' )
120
+ sensu_api_url = os .environ .get ('SENSU_API_URL ' )
121
121
if sensu_api_url :
122
122
uri = urlparse (sensu_api_url )
123
- self . api_settings = {
123
+ api_settings = {
124
124
'host' : '{0}//{1}' .format (uri .scheme , uri .hostname ),
125
125
'port' : uri .port ,
126
126
'user' : uri .username ,
127
127
'password' : uri .password
128
128
}
129
129
else :
130
- self . api_settings = self .settings .get ('api' , {})
131
- self . api_settings ['host' ] = self . api_settings .get (
130
+ api_settings = self .settings .get ('api' , {})
131
+ api_settings ['host' ] = api_settings .get (
132
132
'host' , '127.0.0.1' )
133
- self . api_settings ['port' ] = self . api_settings .get (
133
+ api_settings ['port' ] = api_settings .get (
134
134
'port' , 4567 )
135
135
136
+ return api_settings
137
+
136
138
# API requests
137
139
def api_request (self , method , path ):
138
140
'''
@@ -148,7 +150,7 @@ def api_request(self, method, path):
148
150
149
151
domain = self .api_settings ['host' ]
150
152
uri = 'http://{}:{}{}' .format (domain , self .api_settings ['port' ], path )
151
- if self .api_settings [ 'user' ] and self .api_settings [ 'password' ] :
153
+ if self .api_settings . get ( 'user' ) and self .api_settings . get ( 'password' ) :
152
154
auth = (self .api_settings ['user' ], self .api_settings ['password' ])
153
155
else :
154
156
auth = ()
0 commit comments