Skip to content

Commit

Permalink
Update config files, improve WS login
Browse files Browse the repository at this point in the history
Ref #279
  • Loading branch information
algorys committed Apr 11, 2018
1 parent f58db0c commit d2b44a8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions alignak_app/backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ def login(self, username=None, password=None, proxies=None, check=False):
'Check [Alignak] section in configuration file or use login window of application.'
)

if self.connected and check:
if self.connected and not check:
self.ws_client.login(self.user['token'])

return self.connected

def get(self, endpoint, params=None, projection=None, all_items=False):
"""
GET on alignak Backend REST API.
GET on alignak Backend REST API
:param endpoint: endpoint (API URL)
:type endpoint: str
Expand All @@ -145,7 +145,7 @@ def get(self, endpoint, params=None, projection=None, all_items=False):
:type projection: list|None
:param all_items: make GET on all items
:type all_items: bool
:return: desired request of app_backend
:return: request response
:rtype: dict
"""

Expand Down
6 changes: 5 additions & 1 deletion alignak_app/backend/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ def login(self, token):
response = requests.post(
'/'.join([self.ws_backend, 'login']), json=params, headers=headers
)

resp = response.json()

if '_result' in resp:
assert token == resp['_result'][0]
self.token = token
self.auth = requests.auth.HTTPBasicAuth(self.token, '')
except (RequestsConnectionError, AssertionError) as exp:
logger.error(exp)
msg = 'Connection to Web Service on [%s] has failed' % \
'/'.join([self.ws_backend, 'login'])
logger.warning(msg)
logger.debug(exp)

def get(self, endpoint, params):
"""
Expand Down
10 changes: 8 additions & 2 deletions etc/settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ url = http://127.0.0.1

; Backend url
; ------------------------------------------------------------------------------------------
; The url of your Backend.
; The url of alignak Backend.
; Default is %(url)s:5000
backend = %(url)s:5000

; Webui url
; ------------------------------------------------------------------------------------------
; The url of your Webui
; The url of alignak WebUI
; Default is %(url)s:80
webui = %(url)s:80

; Web service
; ------------------------------------------------------------------------------------------
; The url of web service
; Default is %(url)s:8888
webservice = %(url)s:8888

; Backend processes
; ------------------------------------------------------------------------------------------
; The number of processes for connection to backend
Expand Down
10 changes: 8 additions & 2 deletions test/etc/settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ url = http://demo.alignak.net

; Backend url
; ------------------------------------------------------------------------------------------
; The url of your Backend.
; The url of alignak Backend.
; Default is %(url)s:5000
backend = %(url)s:6000

; Webui url
; ------------------------------------------------------------------------------------------
; The url of your Webui
; The url of alignak WebUI
; Default is %(url)s:80
webui = %(url)s:80

; Web service
; ------------------------------------------------------------------------------------------
; The url of web service
; Default is %(url)s:8888
webservice = %(url)s:8888

; Backend processes
; ------------------------------------------------------------------------------------------
; The number of processes for connection to backend
Expand Down

0 comments on commit d2b44a8

Please sign in to comment.