From: "Chang, Abner" <abner.chang@amd.com>
To: Nickle Wang <nicklew@nvidia.com>,
"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Igor Kulchytskyy <igork@ami.com>
Subject: Re: [edk2-redfish-client][PATCH 4/6] Tool/Redfish-Profile-Simulator: Add ETag support
Date: Tue, 9 May 2023 06:06:42 +0000 [thread overview]
Message-ID: <MN2PR12MB3966A8ABDF3DDA23427C2025EA769@MN2PR12MB3966.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20230508145155.16858-1-nicklew@nvidia.com>
[AMD Official Use Only - General]
Reviewed-by: Abner Chang <abner.chang@amd.com>
> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Monday, May 8, 2023 10:52 PM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>
> Subject: [edk2-redfish-client][PATCH 4/6] Tool/Redfish-Profile-Simulator:
> Add ETag support
>
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
>
>
> Implement ETag support in HTTP header
>
> Signed-off-by: Nickle Wang <nicklew@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
> .../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/Redfish-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 = {}
> + self.generate_etag(json.dumps(self.res_data))
> +
> + def generate_etag(self, context):
> + md5 = hashlib.md5()
> + md5.update(context.encode('utf-8'))
> + self.etag = 'W/"' + md5.hexdigest() + '"'
>
> def create_sub_objects(self, base_path, rel_path):
> pass
> @@ -49,8 +55,8 @@ class RfResource:
> # SHA1 should generate well-behaved etags
> response = flask.make_response(self.response)
> response.mimetype = 'application/json'
> - etag = hashlib.sha1(self.response.encode('utf-8')).hexdigest()
> - response.set_etag(etag)
> + response.headers["ETag"] = self.etag
> +
> return response
> except KeyError:
> flask.abort(404)
> diff --git a/Tools/Redfish-Profile-Simulator/v1sim/systems.py
> b/Tools/Redfish-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'] = boot_data['BootOrder']
>
> - resp = flask.Response(json.dumps(self.res_data,indent=4),
> mimetype="application/json")
> + context = json.dumps(self.res_data,indent=4)
> + self.generate_etag(context)
> + resp = flask.Response(context, mimetype="application/json")
> + resp.headers["ETag"] = self.etag
> +
> return 0, 200, None, resp
>
> def reset_resource(self, reset_data):
> @@ -136,26 +140,28 @@ class RfMemoryCollection(RfCollection):
>
> post_data["@odata.id"] = newMemoryUrl
>
> - md5 = hashlib.md5()
> - md5.update(json.dumps(post_data).encode("utf-8"))
> - etag_str = 'W/"' + md5.hexdigest() + '"'
> - post_data["@odata.etag"] = etag_str
> + self.generate_etag(json.dumps(post_data,indent=4))
> +
> + post_data["@odata.etag"] = self.etag
> self.elements[str(newMemoryIdx)] = post_data
>
> resp = flask.Response(json.dumps(post_data,indent=4),
> mimetype="application/json")
> resp.headers["Location"] = newMemoryUrl
> - resp.headers["ETag"] = etag_str
> -
> + resp.headers["ETag"] = self.etag
> return 0, 200, None, resp
>
> def patch_memory(self, Idx, patch_data):
> - md5 = hashlib.md5()
> - md5.update(json.dumps(patch_data).encode("utf-8"))
> - etag_str = 'W/"' + md5.hexdigest() + '"'
> - patch_data["@odata.etag"] = etag_str
>
> +
> + self.elements[str(Idx)] = {**self.elements[str(Idx)], **patch_data}
> +
> + context = json.dumps(self.elements[str(Idx)],indent=4)
> + self.generate_etag(context)
> + patch_data["@odata.etag"] = self.etag
> self.elements[str(Idx)] = {**self.elements[str(Idx)], **patch_data}
> +
> resp = flask.Response(json.dumps(self.elements[str(Idx)],indent=4),
> mimetype="application/json")
> + resp.headers["ETag"] = self.etag
> return 0, 200, None, resp
>
> def get_memory(self, Idx):
> --
> 2.17.1
prev parent reply other threads:[~2023-05-09 6:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-08 14:51 [edk2-redfish-client][PATCH 4/6] Tool/Redfish-Profile-Simulator: Add ETag support Nickle Wang
2023-05-09 6:06 ` Chang, Abner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=MN2PR12MB3966A8ABDF3DDA23427C2025EA769@MN2PR12MB3966.namprd12.prod.outlook.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox