go/pkg/unifi/clients.go
Snider 4ef698cbe3 Secure SSH, fix CI auto-merge, and resolve merge conflicts
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.
2026-02-05 03:40:28 +00:00

64 lines
1.5 KiB
Go

package unifi
import (
uf "github.com/unpoller/unifi/v5"
"github.com/host-uk/core/pkg/log"
)
// ClientFilter controls which clients are returned.
type ClientFilter struct {
Site string // Filter by site name (empty = all sites)
Wired bool // Show only wired clients
Wireless bool // Show only wireless clients
}
// GetClients returns connected clients from the UniFi controller,
// optionally filtered by site and connection type.
func (c *Client) GetClients(filter ClientFilter) ([]*uf.Client, error) {
sites, err := c.getSitesForFilter(filter.Site)
if err != nil {
return nil, err
}
clients, err := c.api.GetClients(sites)
if err != nil {
return nil, log.E("unifi.GetClients", "failed to fetch clients", err)
}
// Apply wired/wireless filter
if filter.Wired || filter.Wireless {
var filtered []*uf.Client
for _, cl := range clients {
if filter.Wired && cl.IsWired.Val {
filtered = append(filtered, cl)
} else if filter.Wireless && !cl.IsWired.Val {
filtered = append(filtered, cl)
}
}
return filtered, nil
}
return clients, nil
}
// getSitesForFilter resolves sites by name or returns all sites.
func (c *Client) getSitesForFilter(siteName string) ([]*uf.Site, error) {
sites, err := c.GetSites()
if err != nil {
return nil, err
}
if siteName == "" {
return sites, nil
}
// Filter to matching site
for _, s := range sites {
if s.Name == siteName {
return []*uf.Site{s}, nil
}
}
return nil, log.E("unifi.getSitesForFilter", "site not found: "+siteName, nil)
}