netenv

package
v0.41.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package netenv provides network environment detection and NodeContext resolution.

Package netenv detects the network environment (home LAN vs VPS vs cloud).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLocalDomain

func DefaultLocalDomain() string

DefaultLocalDomain returns the local-only domain suffix used when no explicit domain was provided. STACKKIT_LOCAL_DOMAIN remains a compatibility override; the shipped default is the device-enrolled, resolver-backed home zone.

func FormatEnvironment

func FormatEnvironment(env models.NetworkEnvironment) string

FormatEnvironment returns a human-readable description of the network environment.

func FormatNodeContext

func FormatNodeContext(ctx models.NodeContext) string

FormatNodeContext returns a human-readable description of a NodeContext.

func GetCloudUserEmail

func GetCloudUserEmail() string

GetCloudUserEmail returns the authenticated user's email when running in kombify Cloud context. The email is injected by the Cloud platform via the STACKKIT_USER_EMAIL environment variable or the local user-email file.

Returns an empty string when:

  • Not running in kombify Cloud context
  • Neither STACKKIT_USER_EMAIL nor the local user-email file is set

func IsPublicServer

func IsPublicServer(env models.NetworkEnvironment) bool

IsPublicServer reports whether the detected environment is a VPS or managed cloud host with a public interface. Home/NAT and unknown are not.

func NodeContextIsCloud

func NodeContextIsCloud(ctx models.NodeContext) bool

NodeContextIsCloud returns true if the context represents a public-facing server.

func PrivateIP

func PrivateIP() string

PrivateIP returns the first non-loopback RFC1918 address on the host. It is intentionally network-local only and does not call external services.

func ResolveFromResult

func ResolveFromResult(result *Result, cpuCores int, memoryGB float64) models.NodeContext

ResolveFromResult builds a ContextInput from a netenv.Result and optional hardware info, then resolves the NodeContext.

func ResolveNodeContext

func ResolveNodeContext(input ContextInput) models.NodeContext

ResolveNodeContext determines the NodeContext from network environment and hardware.

Mapping:

  • NetEnvCloud or NetEnvVPS on x86_64 → "cloud"
  • NetEnvHome on x86_64 → "local"
  • ARM64 + low resources (< 4 cores or < 4 GB) → "pi"
  • ARM64 + adequate resources → uses network env (local or cloud)
  • Unknown → "local" (safe default)

func SelectPublicCloudDomain

func SelectPublicCloudDomain(requested string) (domain string, usedFallback bool)

SelectPublicCloudDomain picks the Cloud Kit public domain. An empty or local value becomes kombify.me. A custom domain is kept only when DNS already points at this host; otherwise kombify.me is the fallback.

func SuggestDomain

func SuggestDomain(env models.NetworkEnvironment, currentDomain string) (domain string, reason string)

SuggestDomain returns the recommended domain strategy for the detected environment.

func SuggestDomainForContext

func SuggestDomainForContext(ctx models.NodeContext, currentDomain string) (domain string, reason string)

SuggestDomainForContext returns the recommended domain for a NodeContext. This replaces the NetworkEnvironment-based SuggestDomain for external callers.

Types

type ContextInput

type ContextInput struct {
	// NetworkEnv is the detected network environment (home/vps/cloud).
	NetworkEnv models.NetworkEnvironment
	// Arch is the CPU architecture (from runtime.GOARCH or detected on target).
	Arch string
	// CPUCores is the number of CPU cores (0 if unknown).
	CPUCores int
	// MemoryGB is the total system memory in GB (0 if unknown).
	MemoryGB float64
}

ContextInput holds the inputs used for NodeContext resolution.

type Result

type Result struct {
	Environment        models.NetworkEnvironment
	PublicIP           string
	PrivateIP          string
	IsNAT              bool
	HasPublicInterface bool
}

Result holds the outcome of network environment detection.

func Detect

func Detect(ctx context.Context) *Result

Detect determines the network environment by checking network interfaces and comparing the local IP to the external IP.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL