// 此模板仅供参考,如果不适用可以修改
问题描述
希望使用该url,req body为{},下载文件到postman 客户端,目前在映射器中没看到相关的案例
https://bmc_ip/redfish/v1/Managers/{ManagerId}/LogServices/Actions/Oem/Chinatelecom/DownloadAllLog
期望结果
希望使用该url,req body为{},下载文件到postman 客户端
// 此模板仅供参考,如果不适用可以修改
希望使用该url,req body为{},下载文件到postman 客户端,目前在映射器中没看到相关的案例
希望使用该url,req body为{},下载文件到postman 客户端
当前暂不支持直接配置
目前暂不支持直接配置后通过postman客户端下载文件。但是可以配置接口读取文件内容后,将文件内容返回。这样子postman接收到的响应体是返回的内容;如果想要获取到文件的话,可以通过curl命令调用redfish接口,加上-o 参数指定保存文件即可。
感谢,请问文件内容以二进制方式读取后可以写到response里吗
可以借助定制仓处理redfish接口响应的功能来实现
在定制仓的interface_config/redifsh下配置Actions类型的redfish接口,接口类型是POST。
比如配置RspBody的返回值为
{
“xxx”: true,
“data”: data
}
其中xxx是一个具备特色的名称, 用于确认这个属性为true时,接口返回data对应的数据,需要保证这个名称无歧义。
data就是读取到的文件内容。
然后在定制仓新增src/plugins/redfish/custom_request_response.lua文件,文件内容如下
local cjson = require ‘cjson’
local http = require ‘http’
local log = require ‘mc.logging’
– [[
@param code 响应码
@param body 响应体
@param header 响应头
@param manufacture 产商名称
]]
local function rsp_postprocess(code, body, header, manufacture)
local ok, rsp_ret, rsp_header = pcall(function ()
– 去除actions类型接口的error-code格式
if code == http.HTTP_OK then
local rsp_body
– 注意做好防护
if body and body ~= ‘’ and body ~= cjson.null then
rsp_body = cjson.json_object_ordered_decode(body)
else
rsp_body = cjson.json_object_new_object()
end
– 这里的xxx对应RspBody的返回值
if rsp_body[‘error’] and rsp_body[‘error’][‘@Message.ExtendedInfo’] and rsp_body[‘error’][‘@Message.ExtendedInfo’][1] and
rsp_body[‘error’][‘@Message.ExtendedInfo’][1][‘xxx’] == true then
return rsp_body['error']['@Message.ExtendedInfo'][1]['data'], header
end
end
-- 没有做额外处理,返回原始内容
return body, header
end)
if not ok then
log:info('rsp_postprocess failed, ret = %s', rsp_ret)
-- 异常时返回未修改的响应内容
return body, header
end
return rsp_ret, rsp_header
end
return {
[‘rsp_postprocess’] = rsp_postprocess
}
使用ngnix反向代理的方式在定制化组件中可以实现相同的效果