From 97dc9cf1b1d1dd67fee28e9321dd5a11e947a05b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 15 Nov 2021 16:04:04 -0500 Subject: [PATCH] Fix nonce login Redfish needed changes from ipmi side, also need to tolerate a gzipped reply. Change-Id: Ib9ffd4be9e4616d5a0b0a5d8ee35b140dd563ace --- pyghmi/ipmi/oem/lenovo/imm.py | 12 ++++-------- pyghmi/redfish/oem/lenovo/xcc.py | 5 +++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index fa730eb0..4dd15b4b 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -1035,18 +1035,14 @@ class XCCClient(IMMClient): adata = json.dumps({'username': self.username, 'password': self.password }) - nonce = None - wc.request('POST', '/api/providers/get_nonce', '{}') - rsp = wc.getresponse() - tokbody = rsp.read() - if rsp.status == 200: - rsp = json.loads(tokbody) - nonce = rsp.get('nonce', None) headers = {'Connection': 'keep-alive', 'Referer': 'https://xcc/', 'Host': 'xcc', 'Content-Type': 'application/json'} - if nonce: + rsp, status = wc.grab_json_response_with_status( + '/api/providers/get_nonce', {}) + if status == 200: + nonce = rsp.get('nonce', None) headers['Content-Security-Policy'] = 'nonce={0}'.format(nonce) wc.request('POST', '/api/login', adata, headers) rsp = wc.getresponse() diff --git a/pyghmi/redfish/oem/lenovo/xcc.py b/pyghmi/redfish/oem/lenovo/xcc.py index 54871962..8c6e9c10 100644 --- a/pyghmi/redfish/oem/lenovo/xcc.py +++ b/pyghmi/redfish/oem/lenovo/xcc.py @@ -628,6 +628,11 @@ class OEMHandler(generic.OEMHandler): 'Referer': referer, 'Host': 'xcc', 'Content-Type': 'application/json'} + rsp, status = wc.grab_json_response_with_status( + '/api/providers/get_nonce', {}) + if status == 200: + nonce = rsp.get('nonce', None) + headers['Content-Security-Policy'] = 'nonce={0}'.format(nonce) wc.request('POST', '/api/login', adata, headers) rsp = wc.getresponse() if rsp.status == 200: