This commit addresses the OWASP security audit by enforcing strict host key verification and resolves persistent CI issues. Security Changes: - Replaced StrictHostKeyChecking=accept-new with yes in pkg/container and devops. - Removed insecure host key verification from pkg/ansible. - Implemented synchronous host key discovery using ssh-keyscan during VM boot. - Updated Boot lifecycle to wait for host key verification. - Handled missing known_hosts file in pkg/ansible. - Refactored hardcoded SSH port to DefaultSSHPort constant. CI and Maintenance: - Fixed auto-merge.yml by inlining the script and adding repository context to 'gh' command, resolving the "not a git repository" error in CI. - Resolved merge conflicts in .github/workflows/auto-merge.yml with dev branch. - Added pkg/ansible/ssh_test.go for SSH client verification. - Fixed formatting in pkg/io/local/client.go to pass QA checks.
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package unifi
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/host-uk/core/pkg/cli"
|
|
"github.com/host-uk/core/pkg/log"
|
|
uf "github.com/host-uk/core/pkg/unifi"
|
|
)
|
|
|
|
// Devices command flags.
|
|
var (
|
|
devicesSite string
|
|
devicesType string
|
|
)
|
|
|
|
// addDevicesCommand adds the 'devices' subcommand for listing infrastructure devices.
|
|
func addDevicesCommand(parent *cli.Command) {
|
|
cmd := &cli.Command{
|
|
Use: "devices",
|
|
Short: "List infrastructure devices",
|
|
Long: "List all infrastructure devices (APs, switches, gateways) on the UniFi network.",
|
|
RunE: func(cmd *cli.Command, args []string) error {
|
|
return runDevices()
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVar(&devicesSite, "site", "", "Filter by site name")
|
|
cmd.Flags().StringVar(&devicesType, "type", "", "Filter by device type (uap, usw, usg, udm, uxg)")
|
|
|
|
parent.AddCommand(cmd)
|
|
}
|
|
|
|
func runDevices() error {
|
|
client, err := uf.NewFromConfig("", "", "", "")
|
|
if err != nil {
|
|
return log.E("unifi.devices", "failed to initialise client", err)
|
|
}
|
|
|
|
devices, err := client.GetDeviceList(devicesSite, strings.ToLower(devicesType))
|
|
if err != nil {
|
|
return log.E("unifi.devices", "failed to fetch devices", err)
|
|
}
|
|
|
|
if len(devices) == 0 {
|
|
cli.Text("No devices found.")
|
|
return nil
|
|
}
|
|
|
|
table := cli.NewTable("Name", "IP", "MAC", "Model", "Type", "Version", "Status")
|
|
|
|
for _, d := range devices {
|
|
status := successStyle.Render("online")
|
|
if d.Status != 1 {
|
|
status = errorStyle.Render("offline")
|
|
}
|
|
|
|
table.AddRow(
|
|
valueStyle.Render(d.Name),
|
|
d.IP,
|
|
dimStyle.Render(d.Mac),
|
|
d.Model,
|
|
dimStyle.Render(d.Type),
|
|
dimStyle.Render(d.Version),
|
|
status,
|
|
)
|
|
}
|
|
|
|
cli.Blank()
|
|
cli.Print(" %d devices\n\n", len(devices))
|
|
table.Render()
|
|
|
|
return nil
|
|
}
|