Commit 957dfbb0 authored by Eric's avatar Eric Committed by Eric_Lee

[update]更新asset的API数据获取

parent 4b65f008
...@@ -76,21 +76,21 @@ func assetSortByHostName(asset1, asset2 *Asset) bool { ...@@ -76,21 +76,21 @@ func assetSortByHostName(asset1, asset2 *Asset) bool {
type NodeList []Node type NodeList []Node
type Asset struct { type Asset struct {
ID string `json:"id"` ID string `json:"id"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
IP string `json:"ip"` IP string `json:"ip"`
Port int `json:"port"` Port int `json:"port"`
SystemUsers []SystemUser `json:"system_users_granted"` SystemUsers []SystemUser `json:"system_users_granted"`
IsActive bool `json:"is_active"` IsActive bool `json:"is_active"`
SystemUsersJoin string `json:"system_users_join"` SystemUsersJoin string `json:"system_users_join"`
Os string `json:"os"` Os string `json:"os"`
Domain string `json:"domain"` Domain string `json:"domain"`
Platform string `json:"platform"` Platform string `json:"platform"`
Comment string `json:"comment"` Comment string `json:"comment"`
Protocol string `json:"protocol"` Protocol string `json:"protocol"`
Protocols []protocolItem `json:"protocols,omitempty"` Protocols []string `json:"protocols,omitempty"`
OrgID string `json:"org_id"` OrgID string `json:"org_id"`
OrgName string `json:"org_name"` OrgName string `json:"org_name"`
} }
func (a *Asset) ProtocolPort(protocol string) int { func (a *Asset) ProtocolPort(protocol string) int {
...@@ -99,8 +99,13 @@ func (a *Asset) ProtocolPort(protocol string) int { ...@@ -99,8 +99,13 @@ func (a *Asset) ProtocolPort(protocol string) int {
return a.Port return a.Port
} }
for _, item := range a.Protocols { for _, item := range a.Protocols {
if strings.ToLower(item.Name) == strings.ToLower(protocol) { if strings.Contains(strings.ToLower(item), strings.ToLower(protocol)) {
return item.Port proAndPort := strings.Split(item, "/")
if len(proAndPort) == 2 {
if port, err := strconv.Atoi(proAndPort[1]); err == nil {
return port
}
}
} }
} }
switch strings.ToLower(protocol) { switch strings.ToLower(protocol) {
...@@ -120,18 +125,13 @@ func (a *Asset) IsSupportProtocol(protocol string) bool { ...@@ -120,18 +125,13 @@ func (a *Asset) IsSupportProtocol(protocol string) bool {
return a.Protocol == protocol return a.Protocol == protocol
} }
for _, item := range a.Protocols { for _, item := range a.Protocols {
if strings.ToLower(item.Name) == strings.ToLower(protocol) { if strings.Contains(strings.ToLower(item), strings.ToLower(protocol)) {
return true return true
} }
} }
return false return false
} }
type protocolItem struct {
Name string `json:"name"`
Port int `json:"port"`
}
type Gateway struct { type Gateway struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"Name"` Name string `json:"Name"`
...@@ -333,7 +333,7 @@ func (sf *SystemUserFilterRule) Pattern() *regexp.Regexp { ...@@ -333,7 +333,7 @@ func (sf *SystemUserFilterRule) Pattern() *regexp.Regexp {
func (sf *SystemUserFilterRule) Match(cmd string) (RuleAction, string) { func (sf *SystemUserFilterRule) Match(cmd string) (RuleAction, string) {
pattern := sf.Pattern() pattern := sf.Pattern()
if pattern == nil{ if pattern == nil {
return ActionUnknown, "" return ActionUnknown, ""
} }
found := pattern.FindString(cmd) found := pattern.FindString(cmd)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment