util

package
v0.23.0-alpha4-docker-... Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: BSD-3-Clause Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RegisterMethodAuthKey = "authkey"
	RegisterMethodOIDC    = "oidc"
	RegisterMethodCLI     = "cli"
)
View Source
const (
	ByteSize = 8

	// value related to RFC 1123 and 952.
	LabelHostnameLength = 63
)
View Source
const (
	Base8              = 8
	Base10             = 10
	BitSize16          = 16
	BitSize32          = 32
	BitSize64          = 64
	PermissionFallback = 0o700
)

Variables

View Source
var (
	NodePublicKeyRegex       = regexp.MustCompile("nodekey:[a-fA-F0-9]+")
	ErrCannotDecryptResponse = errors.New("cannot decrypt response")
	ZstdCompression          = "zstd"
)
View Source
var DkeyComparer = cmp.Comparer(func(x, y key.DiscoPublic) bool {
	return x.String() == y.String()
})
View Source
var ErrInvalidUserName = errors.New("invalid user name")
View Source
var IPComparer = cmp.Comparer(func(x, y netip.Addr) bool {
	return x.Compare(y) == 0
})
View Source
var MkeyComparer = cmp.Comparer(func(x, y key.MachinePublic) bool {
	return x.String() == y.String()
})
View Source
var NkeyComparer = cmp.Comparer(func(x, y key.NodePublic) bool {
	return x.String() == y.String()
})
View Source
var PrefixComparer = cmp.Comparer(func(x, y netip.Prefix) bool {
	return x == y
})

Functions

func AbsolutePathFromConfigPath

func AbsolutePathFromConfigPath(path string) string

func CheckForFQDNRules

func CheckForFQDNRules(name string) error

func DecodeAndUnmarshalNaCl

func DecodeAndUnmarshalNaCl(
	msg []byte,
	output interface{},
	pubKey *key.MachinePublic,
	privKey *key.MachinePrivate,
) error

func GenerateMagicDNSRootDomains

func GenerateMagicDNSRootDomains(ipPrefixes []netip.Prefix) []dnsname.FQDN

From the netmask we can find out the wildcard bits (the bits that are not set in the netmask). This allows us to then calculate the subnets included in the subsequent class block and generate the entries.

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomStringDNSSafe

func GenerateRandomStringDNSSafe(size int) (string, error)

GenerateRandomStringDNSSafe returns a DNS-safe securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomStringURLSafe

func GenerateRandomStringURLSafe(n int) (string, error)

GenerateRandomStringURLSafe returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GetFileMode

func GetFileMode(key string) fs.FileMode

func GetIPPrefixEndpoints

func GetIPPrefixEndpoints(na netip.Prefix) (netip.Addr, netip.Addr)

func GrpcSocketDialer

func GrpcSocketDialer(ctx context.Context, addr string) (net.Conn, error)

func IsStringInSlice

func IsStringInSlice(slice []string, str string) bool

func LogErr

func LogErr(err error, msg string)

func NormalizeToFQDNRules

func NormalizeToFQDNRules(name string, stripEmailDomain bool) (string, error)

NormalizeToFQDNRules will replace forbidden chars in user it can also return an error if the user doesn't respect RFC 952 and 1123.

func NormalizeToFQDNRulesConfigFromViper

func NormalizeToFQDNRulesConfigFromViper(name string) (string, error)

func ParseIPSet

func ParseIPSet(arg string, bits *int) (*netipx.IPSet, error)

parseIPSet parses arg as one:

  • an IP address (IPv4 or IPv6)
  • the string "*" to match everything (both IPv4 & IPv6)
  • a CIDR (e.g. "192.168.0.0/16")
  • a range of two IPs, inclusive, separated by hyphen ("2eff::1-2eff::0800")

bits, if non-nil, is the legacy SrcBits CIDR length to make a IP address (without a slash) treated as a CIDR of *bits length. nolint

func StringOrPrefixListContains

func StringOrPrefixListContains[T string | netip.Prefix](ts []T, t T) bool

func StringToIPPrefix

func StringToIPPrefix(prefixes []string) ([]netip.Prefix, error)

func TSLogfWrapper

func TSLogfWrapper() logger.Logf

func TailMapResponseToString

func TailMapResponseToString(resp tailcfg.MapResponse) string

func TailNodesToString

func TailNodesToString(nodes []*tailcfg.Node) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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