util

package
v0.0.0-...-664ceaa Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendToken

func AppendToken(token string, tokensFile string, chownGroup string) error

AppendToken appends a token to a file. Token files contain a single token in each line.

func FileExists

func FileExists(path string) bool

FileExists returns true if the specified path exists.

func GenerateCSRConf

func GenerateCSRConf(extraSANs []string) ([]byte, error)

GenerateCSRConf generates a csr.conf.template file for the MicroK8s node. extraSANs are a list of extra Subject Alternate Names to be added to the certificates.

func GetRemoteHost

func GetRemoteHost(lookupIP func(string) ([]net.IP, error), hostname string, remoteAddress string) string

GetRemoteHost returns the hostname that should be used for communicating with the joining node. The endpoint is either the hostname (if it can be resolved), or the remote IP address, as read from the HTTP request. lookupIP is net.LookupIP. If the hostname resolves to a different IP than remoteAddress, then the IP from remoteAddress is returned.

func IsValidToken

func IsValidToken(token string, tokensFile string) (isValidToken, hasTTL bool)

IsValidToken checks tokensFile to see if token is valid. A token is valid when it appears in the tokensFile. A token may optionally have a TTL, which is appended at the end of the token. For example, the tokens file may look like this:

token1
token2|35616531876

In the file above, token1 is a valid token. token2 is valid until the unix timestamp 35616531876.

func NewRandomString

func NewRandomString(letters RandomCharacters, length int) string

NewRandomString creates a new cryptographically safe random string from a source of characters.

func ParseArgumentLine

func ParseArgumentLine(line string) (key string, value string)

ParseArgumentLine parses a command-line argument from a single line. The returned key includes any dash prefixes.

func ReadFile

func ReadFile(path string) (string, error)

ReadFile returns the file contents as a string.

func RemoveToken

func RemoveToken(token string, tokensFile string, chownGroup string) error

RemoveToken removes a token from a tokens file, if it exists. RemoveToken will not return an error if the token does not exist. RemoveToken will only the first occurence of the token, if it exists multiple times in the tokens file. RemoveToken will return an error if it fails to read or write the tokens file.

func RunCommand

func RunCommand(ctx context.Context, command ...string) error

RunCommand executes a command with a given context. RunCommand returns nil if the command completes successfully and the exit code is 0.

func SetupPermissions

func SetupPermissions(path string, chownGroup string)

SetupPermissions attempts to set file permissions to 0660 and group to `microk8s` for a given file. SetupPermissions will knowingly ignore any errors, as failing to update permissions will only occur in extraordinary situations, and will never break the MicroK8s cluster.

Types

type RandomCharacters

type RandomCharacters string

RandomCharacters is used as a source for NewRandomString.

const (
	// Alpha is lower-case and upper-case ASCII characters, as well as digits 0-9.
	Alpha RandomCharacters = "abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMONPQRSTUVWXYZ1234567890"
	// Digits is digits 0-9.
	Digits RandomCharacters = "0123456789"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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