Skip to content

Commit

Permalink
RedfishClientPkg/RedfishVersionLib: use HTTP cache lib
Browse files Browse the repository at this point in the history
Use Redfish Http cache library to query Redfish service.

Signed-off-by: Nickle Wang <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
Cc: Nick Ramirez <[email protected]>
Reviewed-by: Abner Chang <[email protected]>
  • Loading branch information
nicklela committed Jan 4, 2024
1 parent dde8765 commit 841cad3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
5 changes: 3 additions & 2 deletions RedfishClientPkg/Include/Library/RedfishVersionLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file defines the Redfish version Library interface.
(C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand All @@ -11,8 +12,8 @@
#define REDFISH_VERSION_LIB_H_

/**
Query HTTP request to BMC with given redfish service and return redfish
version information. If there is troulbe to get Redfish version on BMC,
Query HTTP request to redfish service and return redfish
version information. If there is trouble to get Redfish version on service,
The value of PcdDefaultRedfishVersion is returned.
It's call responsibility to release returned buffer.
Expand Down
32 changes: 23 additions & 9 deletions RedfishClientPkg/Library/RedfishVersionLib/RedfishVersionLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Redfish version library implementation
(C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand All @@ -10,23 +11,25 @@
#include <Uefi.h>
#include <RedfishBase.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <Library/RedfishLib.h>
#include <Library/JsonLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/RedfishVersionLib.h>
#include <Library/RedfishHttpCacheLib.h>

#define REDFISH_VERSION_DEFAULT_STRING L"v1"
#define REDFISH_ROOT_URI "/redfish"
#define REDFISH_ROOT_URI L"/redfish"

REDFISH_SERVICE *mCacheService;
EFI_STRING mVersionCache;
UINTN mVersionStringSize;

/**
Cache the redfish service version for later use so we don't have to query
HTTP request everytime.
HTTP request every time.
@param[in] Service Redfish service instance
@param[in] Version Version string to cache
Expand Down Expand Up @@ -65,8 +68,8 @@ CacheVersion (
}

/**
Query HTTP request to BMC with given redfish service and return redfish
version information. If there is troulbe to get Redfish version on BMC,
Query HTTP request to redfish service and return redfish
version information. If there is trouble to get Redfish version on service,
The value of PcdDefaultRedfishVersion is returned.
It's call responsibility to release returned buffer.
Expand All @@ -90,6 +93,7 @@ RedfishGetVersion (
EDKII_JSON_VALUE Value;

VersionString = NULL;
ZeroMem (&Response, sizeof (REDFISH_RESPONSE));

if (Service == NULL) {
goto ON_ERROR;
Expand All @@ -105,13 +109,14 @@ RedfishGetVersion (
//
// Get resource from redfish service.
//
Status = RedfishGetByUri (
Status = RedfishHttpGetResource (
Service,
REDFISH_ROOT_URI,
&Response
&Response,
TRUE
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, RedfishGetByService to %a failed: %r\n", __func__, REDFISH_ROOT_URI, Status));
DEBUG ((DEBUG_ERROR, "%a, RedfishGetByService to %s failed: %r\n", __func__, REDFISH_ROOT_URI, Status));
if (Response.Payload != NULL) {
RedfishDumpPayload (Response.Payload);
RedfishFreeResponse (
Expand Down Expand Up @@ -151,18 +156,27 @@ RedfishGetVersion (
VersionString = REDFISH_VERSION_DEFAULT_STRING;
}

if (Response.Payload != NULL) {
RedfishFreeResponse (
Response.StatusCode,
Response.HeaderCount,
Response.Headers,
Response.Payload
);
}

DEBUG ((DEBUG_MANAGEABILITY, "%a: Redfish version - %s\n", __func__, VersionString));
return AllocateCopyPool (StrSize (VersionString), VersionString);
}

/**
Initial redfish version library instace.
Initial redfish version library instate.
@param[in] ImageHandle The image handle.
@param[in] SystemTable The system table.
@retval EFI_SUCEESS Install Boot manager menu success.
@retval EFI_SUCCESS Install Boot manager menu success.
@retval Other Return error status.
**/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## @file
#
# (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand Down Expand Up @@ -31,11 +32,13 @@

[LibraryClasses]
BaseLib
BaseMemoryLib
DebugLib
MemoryAllocationLib
PcdLib
RedfishLib
JsonLib
RedfishHttpCacheLib

[Protocols]

Expand Down

0 comments on commit 841cad3

Please sign in to comment.