From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web09.38678.1655776013143853080 for ; Mon, 20 Jun 2022 18:46:53 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=Zxg5R5Q+; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=01711e5ef9=nickle.wang@hpe.com) Received: from pps.filterd (m0150242.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25KMWvxL023442; Tue, 21 Jun 2022 01:46:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pps0720; bh=9P66Pmna04sL3RY5HKKwqxDZBhw0wMB2gOJhHuiqqTs=; b=Zxg5R5Q+IbRlIha/UBCQEqBqKq/BfbzAMPcRt+Bpb7etbzKq7QrlSqdlm45nmoeXLPYd QCemTxf9tRm3INz9uFHaq2AVPHmRed8R7e5OVWYvqy+G6CedbQs2wAH+9aUOo+oMbC9w iN+AnEtdUExRGSR+MzUDY1+PkS1ab1k78KNnLW4fVcSSgBMgfhdON6nnt9slRWETIQ19 mkLWp9YSKYhwuaGJ0hfbCM12/H69hjZxyFKRJk1OQJExqx5WjlkFB9jQin9j8Ci/oqcc hSNUTVqgdXKCD9nOs1bHY89I7gAaS7jXqk3TbACJvTyS+tE4Ff2YLFJP/bzNVW7f9k7T GA== Received: from p1lg14880.it.hpe.com (p1lg14880.it.hpe.com [16.230.97.201]) by mx0a-002e3701.pphosted.com (PPS) with ESMTPS id 3gtjvms2x2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jun 2022 01:46:51 +0000 Received: from p1lg14886.dc01.its.hpecorp.net (unknown [10.119.18.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by p1lg14880.it.hpe.com (Postfix) with ESMTPS id 005AD800264; Tue, 21 Jun 2022 01:46:50 +0000 (UTC) Received: from WAFM3XJD5N.asiapacific.hpqcorp.net (unknown [16.231.227.36]) by p1lg14886.dc01.its.hpecorp.net (Postfix) with ESMTP id 6FE3F802CC0; Tue, 21 Jun 2022 01:46:49 +0000 (UTC) From: "Nickle Wang" To: devel@edk2.groups.io Cc: Nickle Wang , Abner Chang , Yang Atom , Nick Ramirez Subject: [edk2-staging][PATCH v2 4/5] edk2-staging/RedfishClientPkg: Add ETag support Date: Tue, 21 Jun 2022 09:46:44 +0800 Message-Id: <20220621014645.1388-1-nickle.wang@hpe.com> X-Mailer: git-send-email 2.32.0.windows.2 MIME-Version: 1.0 X-Proofpoint-GUID: sDLQ2BSdYB8WAgdiu5YMk9ybcMPUSbhK X-Proofpoint-ORIG-GUID: sDLQ2BSdYB8WAgdiu5YMk9ybcMPUSbhK X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-20_06,2022-06-17_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 spamscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=432 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206210005 Content-Transfer-Encoding: quoted-printable Implement ETag support in HTTP header Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Yang Atom Cc: Nick Ramirez --- .../v1sim/resource.py | 10 +++++-- .../v1sim/systems.py | 28 +++++++++++-------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/resourc= e.py b/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/resource.py index e722d16a0b..0c7a838281 100644 --- a/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/resource.py +++ b/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/resource.py @@ -36,6 +36,12 @@ class RfResource: self.final_init_processing(base_path, rel_path)=0D else:=0D self.res_data =3D {}=0D + self.generate_etag(json.dumps(self.res_data))=0D +=0D + def generate_etag(self, context):=0D + md5 =3D hashlib.md5()=0D + md5.update(context.encode('utf-8'))=0D + self.etag =3D 'W/"' + md5.hexdigest() + '"'=0D =0D def create_sub_objects(self, base_path, rel_path):=0D pass=0D @@ -49,8 +55,8 @@ class RfResource: # SHA1 should generate well-behaved etags=0D response =3D flask.make_response(self.response)=0D response.mimetype =3D 'application/json'=0D - etag =3D hashlib.sha1(self.response.encode('utf-8')).hexdigest= ()=0D - response.set_etag(etag)=0D + response.headers["ETag"] =3D self.etag=0D +=0D return response=0D except KeyError:=0D flask.abort(404)=0D diff --git a/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/systems= .py b/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/systems.py index 6305a51efb..5adf81be5b 100644 --- a/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/systems.py +++ b/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/systems.py @@ -92,7 +92,11 @@ class RfSystemObj(RfResource): if "BootOrder" in boot_data:=0D self.res_data['Boot']['BootOrder'] =3D boot_data['BootOrde= r']=0D =0D - resp =3D flask.Response(json.dumps(self.res_data,indent=3D4), mime= type=3D"application/json")=0D + context =3D json.dumps(self.res_data,indent=3D4)=0D + self.generate_etag(context)=0D + resp =3D flask.Response(context, mimetype=3D"application/json")=0D + resp.headers["ETag"] =3D self.etag=0D +=0D return 0, 200, None, resp=0D =0D def reset_resource(self, reset_data):=0D @@ -136,26 +140,28 @@ class RfMemoryCollection(RfCollection): =0D post_data["@odata.id"] =3D newMemoryUrl=0D =0D - md5 =3D hashlib.md5()=0D - md5.update(json.dumps(post_data).encode("utf-8"))=0D - etag_str =3D 'W/"' + md5.hexdigest() + '"'=0D - post_data["@odata.etag"] =3D etag_str=0D + self.generate_etag(json.dumps(post_data,indent=3D4))=0D +=0D + post_data["@odata.etag"] =3D self.etag=0D self.elements[str(newMemoryIdx)] =3D post_data=0D =0D resp =3D flask.Response(json.dumps(post_data,indent=3D4), mimetype= =3D"application/json")=0D resp.headers["Location"] =3D newMemoryUrl=0D - resp.headers["ETag"] =3D etag_str=0D -=0D + resp.headers["ETag"] =3D self.etag=0D return 0, 200, None, resp=0D =0D def patch_memory(self, Idx, patch_data):=0D - md5 =3D hashlib.md5()=0D - md5.update(json.dumps(patch_data).encode("utf-8"))=0D - etag_str =3D 'W/"' + md5.hexdigest() + '"'=0D - patch_data["@odata.etag"] =3D etag_str=0D =0D +=0D + self.elements[str(Idx)] =3D {**self.elements[str(Idx)], **patch_da= ta}=0D +=0D + context =3D json.dumps(self.elements[str(Idx)],indent=3D4)=0D + self.generate_etag(context)=0D + patch_data["@odata.etag"] =3D self.etag=0D self.elements[str(Idx)] =3D {**self.elements[str(Idx)], **patch_da= ta}=0D +=0D resp =3D flask.Response(json.dumps(self.elements[str(Idx)],indent= =3D4), mimetype=3D"application/json")=0D + resp.headers["ETag"] =3D self.etag=0D return 0, 200, None, resp=0D =0D def get_memory(self, Idx):=0D --=20 2.32.0.windows.2