Skip to content

Commit

Permalink
server: api: rest: Add firewall rules to refined infra data
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed Nov 21, 2024
1 parent b3385a9 commit b033a3a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
21 changes: 18 additions & 3 deletions server/pkg/api/rest/controller/getRefined.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ func doGetRefinedInfraInfo(connID string) (*inframodel.ServerProperty, error) {
})
}

var firewallRules []inframodel.FirewallRuleProperty

for _, firewall := range infraInfo.Network.Host.FirewallRule {
firewallRules = append(firewallRules, inframodel.FirewallRuleProperty{
SrcCIDR: firewall.Src,
DstCIDR: firewall.Dst,
SrcPorts: firewall.SrcPorts,
DstPorts: firewall.DstPorts,
Protocol: firewall.Protocol,
Direction: firewall.Direction,
Action: firewall.Action,
})
}

refinedInfraInfo := inframodel.ServerProperty{
Hostname: infraInfo.Compute.OS.Node.Hostname,
CPU: inframodel.CpuProperty{
Expand All @@ -114,9 +128,10 @@ func doGetRefinedInfraInfo(connID string) (*inframodel.ServerProperty, error) {
Available: uint64(infraInfo.Compute.ComputeResource.RootDisk.Available), // GiB
Used: uint64(infraInfo.Compute.ComputeResource.RootDisk.Used), // GiB
},
DataDisks: dataDisks,
Interfaces: interfaces,
RoutingTable: routingTable,
DataDisks: dataDisks,
Interfaces: interfaces,
RoutingTable: routingTable,
FirewallRules: firewallRules,
OS: inframodel.OsProperty{
PrettyName: infraInfo.Compute.OS.OS.PrettyName,
Version: infraInfo.Compute.OS.OS.Version,
Expand Down
35 changes: 35 additions & 0 deletions server/pkg/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2814,6 +2814,35 @@ const docTemplate = `{
}
}
},
"inframodel.FirewallRuleProperty": {
"type": "object",
"properties": {
"action": {
"description": "allow, deny",
"type": "string"
},
"direction": {
"description": "inbound, outbound",
"type": "string"
},
"dstCIDR": {
"type": "string"
},
"dstPorts": {
"type": "string"
},
"protocol": {
"description": "TCP, UDP, ICMP",
"type": "string"
},
"srcCIDR": {
"type": "string"
},
"srcPorts": {
"type": "string"
}
}
},
"inframodel.MemoryProperty": {
"type": "object",
"required": [
Expand Down Expand Up @@ -3014,6 +3043,12 @@ const docTemplate = `{
"$ref": "#/definitions/inframodel.DiskProperty"
}
},
"firewallRules": {
"type": "array",
"items": {
"$ref": "#/definitions/inframodel.FirewallRuleProperty"
}
},
"hostname": {
"type": "string"
},
Expand Down
35 changes: 35 additions & 0 deletions server/pkg/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2807,6 +2807,35 @@
}
}
},
"inframodel.FirewallRuleProperty": {
"type": "object",
"properties": {
"action": {
"description": "allow, deny",
"type": "string"
},
"direction": {
"description": "inbound, outbound",
"type": "string"
},
"dstCIDR": {
"type": "string"
},
"dstPorts": {
"type": "string"
},
"protocol": {
"description": "TCP, UDP, ICMP",
"type": "string"
},
"srcCIDR": {
"type": "string"
},
"srcPorts": {
"type": "string"
}
}
},
"inframodel.MemoryProperty": {
"type": "object",
"required": [
Expand Down Expand Up @@ -3007,6 +3036,12 @@
"$ref": "#/definitions/inframodel.DiskProperty"
}
},
"firewallRules": {
"type": "array",
"items": {
"$ref": "#/definitions/inframodel.FirewallRuleProperty"
}
},
"hostname": {
"type": "string"
},
Expand Down
24 changes: 24 additions & 0 deletions server/pkg/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,26 @@ definitions:
- totalSize
- type
type: object
inframodel.FirewallRuleProperty:
properties:
action:
description: allow, deny
type: string
direction:
description: inbound, outbound
type: string
dstCIDR:
type: string
dstPorts:
type: string
protocol:
description: TCP, UDP, ICMP
type: string
srcCIDR:
type: string
srcPorts:
type: string
type: object
inframodel.MemoryProperty:
properties:
available:
Expand Down Expand Up @@ -772,6 +792,10 @@ definitions:
items:
$ref: '#/definitions/inframodel.DiskProperty'
type: array
firewallRules:
items:
$ref: '#/definitions/inframodel.FirewallRuleProperty'
type: array
hostname:
type: string
interfaces:
Expand Down

0 comments on commit b033a3a

Please sign in to comment.