Categorygithub.com/juju/utils/v4
modulepackage
4.0.2
Repository: https://github.com/juju/utils.git
Documentation: pkg.go.dev

# README

juju/utils

This package provides general utility packages and functions.

# Packages

No description provided by the author
Package bzr offers an interface to manage branches of the Bazaar VCS.
Package cache provides a simple caching mechanism that limits the age of cache entries and tries to avoid large repopulation events by staggering refresh times.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
utils/filestorage provides types for abstracting and implementing a system that stores files, including their metadata.
No description provided by the author
The hash package provides utilities that support use of the stdlib hash.Hash.
Copyright 2015 Canonical Ltd.
The keyvalues package implements a set of functions for parsing key=value data, usually passed in as command-line parameters to juju subcommands, e.g.
The parallel package provides utilities for running tasks concurrently.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package ssh contains utilities for dealing with SSH connections, key management, and so on.
No description provided by the author
No description provided by the author
This package provides convenience helpers on top of archive/tar to be able to tar/untar files with a functionality closer to gnu tar command.
No description provided by the author
Package voyeur implements a concurrency-safe value that can be watched for changes.
No description provided by the author
No description provided by the author

# Functions

AgentPasswordHash returns base64-encoded one-way hash of password.
AtomicWriteFile atomically writes the filename with the given contents and permissions, replacing any existing file at the same path.
AtomicWriteFileAndChange atomically writes the filename with the given contents and calls the given function after the contents were written, but before the file is renamed.
ChownPath sets the uid and gid of path to match that of the user specified.
CommandString flattens a sequence of command arguments into a string suitable for executing in a shell, escaping slashes, variables and quotes as necessary; each argument is double-quoted if and only if necessary.
ConformYAML ensures all keys of any nested maps are strings.
ContextWithDeadline is like context.WithDeadline except that it works with a clock.Clock rather than wall-clock time.
ContextWithTimeout is like context.WithTimeout except that it works with a clock.Clock rather than wall-clock time.
CopyFile writes the contents of the given source file to dest.
EnsureBaseDir ensures that path is always prefixed by baseDir, allowing for the fact that path might have a Window drive letter in it.
EnvUsername returns the username from the OS environment.
ExpandPath normalises (via Normalize) a path returning an absolute path.
GetAddressForInterface looks for the network interface and returns the IPv4 address from the possible addresses.
GetIPv4Address iterates through the addresses expecting the format from func (ifi *net.Interface) Addrs() ([]net.Addr, error).
GetIPv6Address iterates through the addresses expecting the format from func (ifi *net.Interface) Addrs() ([]net.Addr, error) and returns the first non-link local address.
GetV4OrV6AddressForInterface looks for the network interface and returns preferably the IPv4 address, and if it doesn't exists then IPv6 address.
Gunzip uncompresses the given data.
Gzip compresses the given data.
Home returns the os-specific home path.
IsFileOwner checks to see if the ownership of the file corresponds to the same username.
IsRcPassthroughError returns whether the error is an RcPassthroughError.
IsUbuntu executes lxb_release to see if the host OS is Ubuntu.
IsValidUUIDString returns true, if the given string matches a valid UUID (version 4, variant 2).
JoinServerPath joins any number of path elements into a single path, adding a path separator (based on the current juju server OS) if necessary.
LocalUsername determines the current username on the local host.
MakeFileURL returns a file URL if a directory is passed in else it does nothing.
MoveFile atomically moves the source file to the destination, returning whether the file was moved successfully.
MustNewUUID returns a new uuid, if an error occurs it panics.
NewBackoffTimer creates and initializes a new BackoffTimer A backoff timer starts at min and gets multiplied by factor until it reaches max.
NewLimiter creates a limiter.
NewLimiterWithPause creates a limiter.
NewMultiReaderAt is like io.MultiReader but produces a ReaderAt (and Size), instead of just a reader.
NewMultiReaderSeeker returns an io.ReadSeeker that combines all the given readers into a single one.
NewRcPassthroughError creates an error that will have the code used at the return code from the cmd.Main function rather than the default of 1 if there is an error.
NewUUID generates a new version 4 UUID relying only on random numbers.
NormalizePath expands a path containing ~ to its absolute form, and removes any .
OSIsUnix determines whether or not the given OS name is one of the unix-like operating systems recognized by Go.
OSUsername returns the username of the current OS user (based on UID).
ParseSize parses the string as a size, in mebibytes.
RandomBytes returns n random bytes.
RandomPassword generates a random base64-encoded password.
RandomSalt generates a random base64 data suitable for using as a password salt The pbkdf2 guideline is to use 8 bytes of salt, so we do 12 raw bytes into 16 base64 bytes.
RandomString will return a string of length n that will only contain runes inside validRunes.
ReadFileSHA256 is like ReadSHA256 but reads the contents of the given file.
ReadSHA256 returns the SHA256 hash of the contents read from source (hex encoded) and the size of the source in bytes.
ReadYaml unmarshals the yaml contained in the file at path into obj.
RelativeURLPath returns a relative URL path that is lexically equivalent to targpath when interpreted by url.URL.ResolveReference.
ReplaceFile atomically replaces the destination file or directory with the source.
ResolveSudo returns the original username if sudo was used.
ResolveUsername returns the username determined by the provided functions.
RunCommand executes the command and return the combined output.
Setenv sets an environment variable entry in the given env slice (as returned by os.Environ or passed in exec.Cmd.Environ) to the given value.
SetHome sets the os-specific home path in the environment.
ShQuote quotes s so that when read by bash, no metacharacters within s will be interpreted as such.
SortStringsNaturally sorts strings according to their natural sort order.
Start a timer, used for tracking time spent.
UniqueDirectory returns "path/name" if that directory doesn't exist.
UseMultipleCPUs sets GOMAXPROCS to the number of CPU cores unless it has already been overridden by the GOMAXPROCS environment variable.
UserHomeDir returns the home directory for the specified user, or the home directory for the current user if the specified user is empty.
UserPasswordHash returns base64-encoded one-way hash password that is computationally hard to crack by iterating through possible passwords.
No description provided by the author
WinCmdQuote quotes s so that when read by cmd.exe, no metacharacters within s will be interpreted as such.
WinPSQuote quotes s so that when read by powershell, no metacharacters within s will be interpreted as such.
WriteYaml marshals obj as yaml to a temporary file in the same directory as path, than atomically replaces path with the temporary file.

# Constants

The following are strings/regex-es which match common Unix error messages that may be returned in case of failed calls to the system.
The following are strings/regex-es which match common Unix error messages that may be returned in case of failed calls to the system.
The following are strings/regex-es which match common Unix error messages that may be returned in case of failed calls to the system.
These are the names of the operating systems recognized by Go.
These are the names of the operating systems recognized by Go.
These are the names of the operating systems recognized by Go.
These are the names of the operating systems recognized by Go.
These are the names of the operating systems recognized by Go.
These are the names of the operating systems recognized by Go.
These are the names of the operating systems recognized by Go.
These are the names of the operating systems recognized by Go.
These are the names of the operating systems recognized by Go.

# Variables

CompatSalt is because Juju 1.16 and older used a hard-coded salt to compute the password hash for all users and agents.
Can be used as a sane default argument for RandomString.
FastInsecureHash specifies whether a fast, insecure version of the hash algorithm will be used.
Can be used as a sane default argument for RandomString.
MinAgentPasswordLength describes how long agent passwords should be.
OSUnix is the list of unix-like operating systems recognized by Go.
Can be used as a sane default argument for RandomString.
regex for validating that the UUID matches RFC 4122.

# Structs

No description provided by the author
AttemptStrategy represents a strategy for waiting for an action to complete successfully.
BackoffTimer implements Countdown.
BackoffTimerConfig is a helper struct for backoff timer that encapsulates config information.
RcPassthroughError indicates that a Juju plugin command exited with a non-zero exit code.
SizeTracker tracks the number of bytes passing through its Write method (which is otherwise a no-op).

# Interfaces

Countdown implements a timer that will call a provided function.
Limiter represents a limited resource (eg a semaphore).
SizeReaderAt combines io.ReaderAt with a Size method.

# Type aliases

UUID represent a universal identifier with 16 octets.