utils

package
v0.0.0-...-05f333e Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckExpired

func CheckExpired(expireOn string) (bool, error)

CheckExpired takes a time string and determines if it represents a time in the past.

func CheckExpiredKey

func CheckExpiredKey(key string) error

CheckExpiredKey validates whether a key has expired. Keys with invalid expiration formats will result in an error.

func CopyFile

func CopyFile(src, dst string, perm fs.FileMode) error

CopyFile copies content from src to dst and sets permissions.

func GetUserKey

func GetUserKey(rawKey string) (string, string, error)

GetUserKey returns a user and a SSH key if a rawKey has a correct format, nil otherwise. It doesn't validate entries.

func MakeRandRSAPubKey

func MakeRandRSAPubKey(t *testing.T) string

MakeRandRSAPubKey generates base64 encoded 256 bit RSA public key for use in tests.

func RegexGroupsMap

func RegexGroupsMap(regex *regexp.Regexp, data string) map[string]string

RegexGroupsMap takes a compiled Regexp and a string data and return a map of groups:data pairs. The compiled regex must contain grouping.

func SaferWriteFile

func SaferWriteFile(content []byte, outputFile string, perm fs.FileMode) error

SaferWriteFile writes to a temporary file and then replaces the expected output file. This prevents other processes from reading partial content while the writer is still writing.

func ValidateUser

func ValidateUser(user string) error

ValidateUser checks for the presence of a characters which should not be allowed in a username string, returns an error if any such characters are detected, nil otherwise. Currently, the only banned characters are whitespace characters.

func ValidateUserKey

func ValidateUserKey(user, key string) error

ValidateUserKey takes an user and a key received from GetUserKey() and validate the user for special characters and the key for expiration

func WriteFile

func WriteFile(content []byte, outputFile string, perm fs.FileMode) error

WriteFile creates parent directories if required and writes content to the output file.

Types

type SerialPort

type SerialPort struct {
	Port string
}

SerialPort is a type for writing to a named serial port.

func (*SerialPort) Write

func (s *SerialPort) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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