From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.61]) by mx.groups.io with SMTP id smtpd.web10.109636.1683557530121395619 for ; Mon, 08 May 2023 07:52:10 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=OXKZA5sH; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.93.61, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LcdOrdltbDMl8FZYNRkjO+YjQ0y/tgG6tw0PM8OEZ41kszIhzL+rgo+x1DFsieCuO+cNFxvPSr7cO88jj1bWlGaD8Sx/jXwD5B6KxVcDDxn8P39mwcPMNaLKO4v0G8rMpAC7HwdiI6xPX1xWeBTz2cx24F7A9npA+RGo0eN56810k0DmcoehWAiZE6xuiATC3RS2s6TQI2Kkr3eB2gC9Ci7u5K2Zh1VagUAMelgV0a0T/70sRMOrpBXfo6OoWNbDhCRVwPuMEiDT3AqxUOLjqL9QuFcYj2IePy+GUFZb/t/8OdTcySa+xCgOHkor0HTXE1v//fUUSioiloMHWRZfMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=puaGXAtmFoj7y9JAkDIBxbo8zIC2W3SDC8IZBUc44UQ=; b=K8tWyVgHtdJc5WazNmaC4E+qPRZhuEVXqJDI9ONNjAnY7JItr74IaUCzptTvewCqb1+N96GIVK6V0LYWE6av/t9KvV4WVetenGVdaaWVG+JAv35De4YjyewK9HLj+/5Hr/HCZGEDQOZvG1C64J26ZXQe7uW+vmuIYvAoBDzXkfrYMd/RGOqQjwirLMISdWBArU6ApAAEbBDb0S1x8Qk+WjCijjfDetMDUSIHi85VmfWd/kWjopxIkTQ7yQQZKHgH7Ebh/yRowlTJnzg7ijkxkt7awwOqfg0pYbNDfkzKUGMKKbvc7swTgtZh3CPjeK6Yw73749Z2NlybWMVBTywpuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=puaGXAtmFoj7y9JAkDIBxbo8zIC2W3SDC8IZBUc44UQ=; b=OXKZA5sHISLjXeQ6AhY7141gCkPa87fuOFgoF/pAhViUSEJZYKC0VRqsu/PGghQGGFrSDhKI3ZxgxkDNs6wPzeL3GGVws7Bpl0i3HQ1mIznOSpp34xz0A4bsPpIaGs5x+IaNqo8ByMMiCKVq5pvGYWLzy/NZ9RxMkAKeqoZAvQ/nNGwgfskzCY1gheU5CxZNHq45ujECcGKU7w2YMqLG95dm68jD98eQrzj+w92zO5+hRWUNnQTpAr8z6Rvg92VdskItD+NjQDkj0tnCSfM7Jiq/PvqEUcl0+al+G1wvrepbrloH2dnms7YUspa4AnP8XSr6RBgjM+veGkn0YrB/Ow== Received: from BN9P221CA0019.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::34) by MW4PR12MB7334.namprd12.prod.outlook.com (2603:10b6:303:219::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Mon, 8 May 2023 14:52:07 +0000 Received: from BN8NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10a:cafe::91) by BN9P221CA0019.outlook.office365.com (2603:10b6:408:10a::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32 via Frontend Transport; Mon, 8 May 2023 14:52:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN8NAM11FT101.mail.protection.outlook.com (10.13.177.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32 via Frontend Transport; Mon, 8 May 2023 14:52:06 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Mon, 8 May 2023 07:51:56 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Mon, 8 May 2023 07:51:55 -0700 Received: from NV-CL38DL3.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 8 May 2023 07:51:55 -0700 From: "Nickle Wang" To: CC: Abner Chang , Igor Kulchytskyy Subject: [edk2-redfish-client][PATCH 4/6] Tool/Redfish-Profile-Simulator: Add ETag support Date: Mon, 8 May 2023 22:51:55 +0800 Message-ID: <20230508145155.16858-1-nicklew@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Return-Path: nicklew@nvidia.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT101:EE_|MW4PR12MB7334:EE_ X-MS-Office365-Filtering-Correlation-Id: 605efaa2-33e3-4846-3028-08db4fd3cb45 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0kaU+5eOBZmWhmAVDuixb+6Ti4JEzbDA0TAZnkuBS6yspH0yvnIf8tO0emLT6Q7bgdkxbP0X4qrpnmwAFQ8JtNz53gCmxSnmtJrUgKAJBr7typlfwBlUw+aXYacldXwiEt6FmIj/UKnPKA2zt/AiJ9NdgXjaIz3Ca0EWLoeVegePAmMQoZu5m/xmO44cKcDOQehrmRXaAMN0Ldf5VlzVMKXdIY43aeKjr3bnIVjL6qf85bZJ4e1GbhpWbUULIHqxMBvg2vWVPKiymN0KqARk0FXrwPz/TY+Mp4SoyhMgQ6rBxce4cf5jnU8tXDHgYkIB7g9oZlzlSqZyOZ43L8Kp58fjSdcBiGimvAOzBqfPeqCJA6GcBOANxrCyuXw7tEXy15+urfiBgciMJdTwIb5SYCZg7TBh4TIRanlpXjGOC0Hx7Z32i+w3Tf4qMJnfDbF6E4U2gWfOz0STxXD2hNouf/hl5LUkUeELjuYRQuU8zFzSSDPr43HiYteM5hSKpqWDVKoqmH31N1XQs7Cw3w/AEIILDJIUojEuoBQeCeiEK17Nh5Jrx/NIxKpZR9ZpIa7hdbTboFRwHy0vEq5sTPYrU1sF5z9ulA8kNBJDLYrsER2oR2jCWw93v7g/2A8zf3P19kChwx5mWAhKMk1WTBWjT4CqcCAARYPpniWilzSxAFw= X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(346002)(136003)(39860400002)(451199021)(36840700001)(46966006)(26005)(1076003)(83380400001)(336012)(40480700001)(426003)(36860700001)(36756003)(2616005)(7636003)(86362001)(82310400005)(82740400003)(356005)(186003)(7696005)(47076005)(19627235002)(54906003)(2906002)(8936002)(8676002)(316002)(41300700001)(478600001)(70586007)(6916009)(4326008)(70206006)(5660300002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2023 14:52:06.8185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 605efaa2-33e3-4846-3028-08db4fd3cb45 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7334 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Implement ETag support in HTTP header Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy --- .../v1sim/resource.py | 10 +++++-- .../v1sim/systems.py | 28 +++++++++++-------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Tools/Redfish-Profile-Simulator/v1sim/resource.py b/Tools/Redf= ish-Profile-Simulator/v1sim/resource.py index e722d16a..0c7a8382 100644 --- a/Tools/Redfish-Profile-Simulator/v1sim/resource.py +++ b/Tools/Redfish-Profile-Simulator/v1sim/resource.py @@ -36,6 +36,12 @@ class RfResource: self.final_init_processing(base_path, rel_path) else: self.res_data =3D {} + self.generate_etag(json.dumps(self.res_data)) + + def generate_etag(self, context): + md5 =3D hashlib.md5() + md5.update(context.encode('utf-8')) + self.etag =3D 'W/"' + md5.hexdigest() + '"' =20 def create_sub_objects(self, base_path, rel_path): pass @@ -49,8 +55,8 @@ class RfResource: # SHA1 should generate well-behaved etags response =3D flask.make_response(self.response) response.mimetype =3D 'application/json' - etag =3D hashlib.sha1(self.response.encode('utf-8')).hexdigest= () - response.set_etag(etag) + response.headers["ETag"] =3D self.etag + return response except KeyError: flask.abort(404) diff --git a/Tools/Redfish-Profile-Simulator/v1sim/systems.py b/Tools/Redfi= sh-Profile-Simulator/v1sim/systems.py index 6305a51e..5adf81be 100644 --- a/Tools/Redfish-Profile-Simulator/v1sim/systems.py +++ b/Tools/Redfish-Profile-Simulator/v1sim/systems.py @@ -92,7 +92,11 @@ class RfSystemObj(RfResource): if "BootOrder" in boot_data: self.res_data['Boot']['BootOrder'] =3D boot_data['BootOrde= r'] =20 - resp =3D flask.Response(json.dumps(self.res_data,indent=3D4), mime= type=3D"application/json") + context =3D json.dumps(self.res_data,indent=3D4) + self.generate_etag(context) + resp =3D flask.Response(context, mimetype=3D"application/json") + resp.headers["ETag"] =3D self.etag + return 0, 200, None, resp =20 def reset_resource(self, reset_data): @@ -136,26 +140,28 @@ class RfMemoryCollection(RfCollection): =20 post_data["@odata.id"] =3D newMemoryUrl =20 - md5 =3D hashlib.md5() - md5.update(json.dumps(post_data).encode("utf-8")) - etag_str =3D 'W/"' + md5.hexdigest() + '"' - post_data["@odata.etag"] =3D etag_str + self.generate_etag(json.dumps(post_data,indent=3D4)) + + post_data["@odata.etag"] =3D self.etag self.elements[str(newMemoryIdx)] =3D post_data =20 resp =3D flask.Response(json.dumps(post_data,indent=3D4), mimetype= =3D"application/json") resp.headers["Location"] =3D newMemoryUrl - resp.headers["ETag"] =3D etag_str - + resp.headers["ETag"] =3D self.etag return 0, 200, None, resp =20 def patch_memory(self, Idx, patch_data): - md5 =3D hashlib.md5() - md5.update(json.dumps(patch_data).encode("utf-8")) - etag_str =3D 'W/"' + md5.hexdigest() + '"' - patch_data["@odata.etag"] =3D etag_str =20 + + self.elements[str(Idx)] =3D {**self.elements[str(Idx)], **patch_da= ta} + + context =3D json.dumps(self.elements[str(Idx)],indent=3D4) + self.generate_etag(context) + patch_data["@odata.etag"] =3D self.etag self.elements[str(Idx)] =3D {**self.elements[str(Idx)], **patch_da= ta} + resp =3D flask.Response(json.dumps(self.elements[str(Idx)],indent= =3D4), mimetype=3D"application/json") + resp.headers["ETag"] =3D self.etag return 0, 200, None, resp =20 def get_memory(self, Idx): --=20 2.17.1