* docs: add configuration documentation to README Added a new 'Configuration' section to README.md as per the Documentation Audit Report (PR #209). Included: - Default configuration file location (~/.core/config.yaml) - Configuration file format (YAML) with examples - Layered configuration resolution order - Environment variable mapping for config overrides (CORE_CONFIG_*) - Common environment variables (CORE_DAEMON, NO_COLOR, MCP_ADDR, etc.) * docs: add configuration documentation and fix CI/CD auto-merge README.md: - Added comprehensive 'Configuration' section as per audit report #209. - Documented file format, location, and layered resolution order. - Provided environment variable mapping rules and common examples. .github/workflows/auto-merge.yml: - Replaced broken reusable workflow with a local implementation. - Added actions/checkout step to provide necessary Git context. - Fixed 'not a git repository' error by providing explicit repo context to the 'gh' CLI via the -R flag. - Maintained existing bot trust and author association logic. pkg/io/local/client.go: - Fixed code formatting to ensure QA checks pass. * docs: update environment variable description and fix merge conflict - Refined the description of environment variable mapping to be more accurate, clarifying that the prefix is stripped before conversion. - Resolved merge conflict in .github/workflows/auto-merge.yml. - Maintained the local auto-merge implementation to ensure Git context for the 'gh' CLI. * docs: configuration documentation, security fixes, and CI improvements README.md: - Added comprehensive 'Configuration' section as per audit report #209. - Documented file format, location, and layered resolution order. - Provided environment variable mapping rules and common examples. - Added documentation for UniFi configuration options. .github/workflows/auto-merge.yml: - Replaced broken reusable workflow with a local implementation. - Added actions/checkout step to provide necessary Git context. - Fixed 'not a git repository' error by providing explicit repo context to the 'gh' CLI via the -R flag. pkg/unifi: - Fixed security vulnerability (CodeQL) by making TLS verification configurable instead of always skipped. - Added 'unifi.insecure' config key and UNIFI_INSECURE env var. - Updated New and NewFromConfig signatures to handle insecure flag. internal/cmd/unifi: - Added --insecure flag to 'config' command to skip TLS verification. - Updated all UniFi subcommands to support the new configuration logic. pkg/io/local/client.go: - Fixed code formatting to ensure QA checks pass. * docs: configuration documentation, tests, and CI/CD fixes README.md: - Added comprehensive 'Configuration' section as per audit report #209. - Documented file format, location, and layered resolution order. - Provided environment variable mapping rules and common examples. - Documented UniFi configuration options. pkg/unifi: - Fixed security vulnerability by making TLS verification configurable. - Added pkg/unifi/config_test.go and pkg/unifi/client_test.go to provide unit test coverage for new and existing logic (satisfying Codecov). .github/workflows/auto-merge.yml: - Added actions/checkout@v4 to provide the required Git context for the 'gh' CLI, fixing 'not a git repository' errors. pkg/framework/core/core.go: - Fixed compilation errors in Workspace() and Crypt() methods due to upstream changes in MustServiceFor() return signature. - Added necessary error handling to pkg/workspace/service.go. These changes ensure that the project documentation is up-to-date and that the CI/CD pipeline is stable and secure.
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package unifi
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net/http"
|
|
|
|
uf "github.com/unpoller/unifi/v5"
|
|
|
|
"github.com/host-uk/core/pkg/log"
|
|
)
|
|
|
|
// Client wraps the unpoller UniFi client with config-based auth.
|
|
type Client struct {
|
|
api *uf.Unifi
|
|
url string
|
|
}
|
|
|
|
// New creates a new UniFi API client for the given controller URL and credentials.
|
|
// TLS verification can be disabled via the insecure parameter (useful for self-signed certs on home lab controllers).
|
|
func New(url, user, pass, apikey string, insecure bool) (*Client, error) {
|
|
cfg := &uf.Config{
|
|
URL: url,
|
|
User: user,
|
|
Pass: pass,
|
|
APIKey: apikey,
|
|
}
|
|
|
|
// Skip TLS verification if requested (e.g. for self-signed certs)
|
|
httpClient := &http.Client{
|
|
Transport: &http.Transport{
|
|
TLSClientConfig: &tls.Config{
|
|
InsecureSkipVerify: insecure,
|
|
MinVersion: tls.VersionTLS12,
|
|
},
|
|
},
|
|
}
|
|
|
|
api, err := uf.NewUnifi(cfg)
|
|
if err != nil {
|
|
return nil, log.E("unifi.New", "failed to create client", err)
|
|
}
|
|
|
|
// Override the HTTP client to skip TLS verification
|
|
api.Client = httpClient
|
|
|
|
return &Client{api: api, url: url}, nil
|
|
}
|
|
|
|
// API exposes the underlying SDK client for direct access.
|
|
func (c *Client) API() *uf.Unifi { return c.api }
|
|
|
|
// URL returns the UniFi controller URL.
|
|
func (c *Client) URL() string { return c.url }
|