Web Rest接口映射配置指南
更新时间:2025/08/18
在Gitcode上查看源码openUBMC社区的Web Rest接口采用接口映射配置方案实现,需要将命令配置到json文件中。Web Rest接口的接口映射配置文件在rackmount代码仓的web_backend路径下。
接口URI
- URI格式
shell
/UI/Rest/<resource>
支持请求类型 GET POST PATCH DELETE
注意事项 对于大多数的Web Rest接口,URI都是固定的字符串,无须进行URI有效性校验。部分接口URI包含动态参数, 需要配置URI有效性校验。例如:在
/UI/Rest/AccessMgnt/Accounts/Account_ID/ImportSSHPublicKey
中, Account_ID就是动态的参数,在接收请求的时候才能获取到该参数,需要对参数进行校验。
配置示例
Web Rest接口数据映射器配置,请参考《接口映射配置》。
json
{
"Uri": "/UI/Rest/BMCSettings/Language/OpenLanuage",
"Interfaces": [
{
"Type": "POST",
"ReqBody": [
{
"Name": "LanguageSetStr",
"Type": "String"
}
],
"RspBody": {
"LanguageSet": "${Statements/LanguageSetRsp()}"
},
"Statements": {
"LanguageSet": {
"Input": "${ProcessingFlow[1]/Destination/LanguageSet}",
"Steps": [
{
"Type": "Script",
"Formula": "Input[#Input + 1] = 'add' .. ReqBody.LanguageSetStr return Input"
}
]
},
"LanguageSetRsp": {
"Input": "/bmc/kepler/Systems/1/Product",
"Steps": [
{
"Type": "Expand",
"Formula": 1
}
]
}
},
"ProcessingFlow": [
{
"Type": "Property",
"Path": "/bmc/kepler/Systems/1/Product",
"Interface": "bmc.kepler.Systems.Product",
"Destination": {
"LanguageSet": "LanguageSet"
}
},
{
"Type": "Property",
"Path": "/bmc/kepler/Systems/1/Product",
"Interface": "bmc.kepler.Systems.Product",
"Source": {
"LanguageSet": "${Statements/LanguageSet()}"
}
}
]
}
]
}
特有字段说明
二次鉴权
部分与用户,安全相关的接口,需要结果Web二次认证。需要二次认证的操作包括修改VNC密码、创建新用户、删除用户、 修改指定用户信息、SSH公钥带入、SSH公钥删除、修改自定义角色权限、修改指定域控制器、修改SNMPV3加密密码的信息、 新增/修改/删除LDAP和Kerberos用户组信息、导入LDAP证书或证书吊销列表、导入Kerberos密钥表、配置导入等。
- 请求消息体需要指定ReauthKey
json
{
"ReauthKey": value
}
- 映射器配置使用Reauth进行二次认证声明
json
{
"Resource": [
{
"Uri": "xxxx",
"Interfaces": [
{
"Type": "POST",
"ReqBody": [xxxx],
"Reauth": "${ReqBody/ReauthKey}",
"ProcessingFlow": [xxxx]
}
]
}
]
}
错误消息
当前统一使用Redfish标准对Web Rest接口的错误消息进行定义,Web Rest使用标准错误信息中的Code 和Message字段拼接完整错误信息,响应码码则使用HttpStatusCode字段。例如:
- 标准错误定义
json
"InsufficientPrivilege": {
"Description": "Indicates that the credentials associated with the established session do not have sufficient privileges for the requested operation",
"Message": "There are insufficient privileges for the account or credentials associated with the current session to perform the requested operation.",
"Severity": "Critical",
"NumberOfArgs": 0,
"Resolution": "Either abandon the operation or change the associated access rights and resubmit the request if the operation failed.",
"HttpStatusCode": 403,
"IpmiCompletionCode": "0xFF",
"SnmpStatusCode": 6,
"TraceDepth": 0
}
- 拼接后的Web Rest错误信息和响应码
json
{
"error": [
{
"code": "InsufficientPrivilege",
"message": "There are insufficient privileges for the account or credentials associated with the current session to perform the requested operation."
}
]
}