- 增加资产附加属性功能
This commit is contained in:
@ -106,6 +106,31 @@ func AssetUpdateEndpoint(c echo.Context) error {
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
func AssetGetAttributeEndpoint(c echo.Context) error {
|
||||
|
||||
assetId := c.Param("id")
|
||||
attributeMap, err := model.FindAssetAttrMapByAssetId(assetId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, attributeMap)
|
||||
}
|
||||
|
||||
func AssetUpdateAttributeEndpoint(c echo.Context) error {
|
||||
m := echo.Map{}
|
||||
if err := c.Bind(&m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
assetId := c.Param("id")
|
||||
protocol := c.QueryParam("protocol")
|
||||
err := model.UpdateAssetAttributes(assetId, protocol, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, "")
|
||||
}
|
||||
|
||||
func AssetDeleteEndpoint(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
split := strings.Split(id, ",")
|
||||
|
@ -74,6 +74,8 @@ func SetupRoutes() *echo.Echo {
|
||||
assets.GET("/paging", AssetPagingEndpoint)
|
||||
assets.POST("/:id/tcping", AssetTcpingEndpoint)
|
||||
assets.PUT("/:id", AssetUpdateEndpoint)
|
||||
assets.GET("/:id/attributes", AssetGetAttributeEndpoint)
|
||||
assets.PUT("/:id/attributes", AssetUpdateAttributeEndpoint)
|
||||
assets.DELETE("/:id", AssetDeleteEndpoint)
|
||||
assets.GET("/:id", AssetGetEndpoint)
|
||||
assets.POST("/:id/change-owner", Admin(AssetChangeOwnerEndpoint))
|
||||
|
@ -124,6 +124,15 @@ func TunEndpoint(c echo.Context) error {
|
||||
|
||||
configuration.SetParameter("hostname", session.IP)
|
||||
configuration.SetParameter("port", strconv.Itoa(session.Port))
|
||||
|
||||
// 加载资产配置的属性,优先级比全局配置的高,因此最后加载,覆盖掉全局配置
|
||||
attributes, _ := model.FindAssetAttributeByAssetId(session.AssetId)
|
||||
if len(attributes) > 0 {
|
||||
for i := range attributes {
|
||||
attribute := attributes[i]
|
||||
configuration.SetParameter(attribute.Name, attribute.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
for name := range configuration.Parameters {
|
||||
// 替换数据库空格字符串占位符为真正的空格
|
||||
|
Reference in New Issue
Block a user