mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
openswitch.py: Fix the OpenSwitch REST authentication
It's a cookie based authentication, that we get it through /login endpoint, called by connect() method and save the cookie for the rest of the call.
This commit is contained in:
parent
42f6114b61
commit
2043c32551
1 changed files with 15 additions and 2 deletions
|
@ -114,7 +114,20 @@ class Rest(object):
|
||||||
if not port:
|
if not port:
|
||||||
port = 80
|
port = 80
|
||||||
|
|
||||||
self.baseurl = '%s://%s:%s/rest/v1' % (proto, host, port)
|
baseurl = '%s://%s:%s' % (proto, host, port)
|
||||||
|
headers = dict({'Content-Type': 'application/x-www-form-urlencoded'})
|
||||||
|
# Get a cookie and save it the rest of the operations.
|
||||||
|
url = '%s/%s' % (baseurl, 'login')
|
||||||
|
data = 'username=%s&password=%s' % (self.module.params['username'],
|
||||||
|
self.module.params['password'])
|
||||||
|
resp, hdrs = fetch_url(self.module, url, data=data,
|
||||||
|
headers=headers, method='POST')
|
||||||
|
|
||||||
|
# Update the base url for the rest of the operations.
|
||||||
|
self.baseurl = '%s/rest/v1' % (baseurl)
|
||||||
|
self.headers = dict({'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Cookie': resp.headers.get('Set-Cookie')})
|
||||||
|
|
||||||
def _url_builder(self, path):
|
def _url_builder(self, path):
|
||||||
if path[0] == '/':
|
if path[0] == '/':
|
||||||
|
@ -127,7 +140,7 @@ class Rest(object):
|
||||||
|
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = dict()
|
headers = dict()
|
||||||
headers.update({'Content-Type': 'application/json'})
|
headers.update(self.headers)
|
||||||
|
|
||||||
resp, hdrs = fetch_url(self.module, url, data=data, headers=headers,
|
resp, hdrs = fetch_url(self.module, url, data=data, headers=headers,
|
||||||
method=method)
|
method=method)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue