Documentation
¶
Overview ¶
Package util provides utility functions for the library.
Index ¶
- Constants
- Variables
- func ErrorIs(err error, errs ...error) bool
- func FormatError(err error) error
- func GetExecutablePath() string
- func GetFromKeyring(key string) (string, error)
- func Handle(err error) error
- func Hexify(s string) string
- func LookupAddress(address string) string
- func NewGUID() string
- func RebuildStringSliceFlag(flags []string, delimiter rune) ([]string, error)
- func RemoveFromKeyRing(key string) error
- func SetToKeyring(key, value string) error
- func SkipOAT(t testing.TB)
- func Time1601() time.Time
- func TimeAfter1601(offset int64) time.Time
- func TimeSince1601() time.Duration
- func ToTitleNoLower(in string) string
- func Unhexify(s string) string
- func Validate() *validator.Validate
- type ValidatorInterface
Constants ¶
const ( KEYCTL_PERM_VIEW = uint32(1 << iota) KEYCTL_PERM_READ KEYCTL_PERM_WRITE KEYCTL_PERM_SEARCH KEYCTL_PERM_LINK KEYCTL_PERM_SETATTR KEYCTL_PERM_ALL = uint32((1 << iota) - 1) )
forked KEYCTL_PERM modes from github.com/99designs/keyring to make the config platform independent e.g. (KEYCTL_PERM_ALL << KEYCTL_PERM_USER) | (KEYCTL_PERM_ALL << KEYCTL_PERM_PROCESS)
const ( KEYCTL_PERM_OTHERS uint32 = iota * 8 KEYCTL_PERM_GROUP KEYCTL_PERM_USER KEYCTL_PERM_PROCESS )
Variables ¶
var Config = func() keyring.Config { cfg := &keyring.Config{ AllowedBackends: nil, FileDir: "~/.config/ldap-cli", FilePasswordFunc: passwordFunc, KeyCtlScope: "user", KeyCtlPerm: (KEYCTL_PERM_ALL << KEYCTL_PERM_USER) | (KEYCTL_PERM_ALL << KEYCTL_PERM_PROCESS), KeychainAccessibleWhenUnlocked: true, KeychainName: "ldap-cli", KeychainPasswordFunc: nil, KeychainSynchronizable: false, KeychainTrustApplication: true, KWalletAppID: "ldap-cli", KWalletFolder: "ldap-cli", LibSecretCollectionName: "ldap-cli", PassCmd: "pass", PassDir: "~/.password-store", PassPrefix: "ldap-cli.", ServiceName: "ldap-cli", WinCredPrefix: "ldap-cli.", } cfg.KeychainPasswordFunc = keyring.FixedStringPrompt("test") // evaluate available backends var backends []keyring.BackendType for _, backend := range backendOrder { if !func() bool { for _, available := range availableBackends { if backend == available { return true } } return false }() || backend == keyring.FileBackend { continue } cfg.AllowedBackends = []keyring.BackendType{backend} ring, err := keyring.Open(*cfg) if err != nil { continue } if err := ring.Set(keyring.Item{Key: "test", Data: []byte("test")}); err != nil { continue } _ = ring.Remove("test") backends = append(backends, backend) } backends = append(backends, keyring.FileBackend) cfg.AllowedBackends = backends cfg.KeychainPasswordFunc = passwordFunc return *cfg }()
Config is the configuration for the keyring
var ErrAuthenticationFailed = errors.New("authentication failed")
var ErrInvalidFilter = errors.New("invalid filter syntax")
var ErrNetworkFailure = errors.New("network error")
var ErrNothingReturned = errors.New("nothing returned")
var ErrOperationFailed = errors.New("query failed")
var ErrQuotaExceeded = errors.New("quota limit exceed")
var ErrUbiquitousResults = errors.New("ubiquitous response")
var Exit = os.Exit
Exit is reference to os.Exit (can be mocked)
var Now = time.Now
Now is reference to time.Now (can be mocked)
var OpenKeyring = keyring.Open
OpenKeyring is a reference to keyring.Open (can be overwritten for testing)
Functions ¶
func GetExecutablePath ¶
func GetExecutablePath() string
GetExecutablePath returns the path to the current executable
func GetFromKeyring ¶
GetFromKeyring retrieves a value from the keyring
func LookupAddress ¶
LookupAddress returns the hostname for the given address
func RebuildStringSliceFlag ¶
RebuildStringSliceFlag rebuilds a string slice flag from a string by using custom CSV reader
func RemoveFromKeyRing ¶
RemoveFromKeyRing removes a value from the keyring
func SetToKeyring ¶
SetToKeyring sets a value to the keyring
func TimeAfter1601 ¶
TimeAfter1601 returns time after 1601-01-01 00:00:00 UTC. Offset should be in 0.1 µs
func TimeSince1601 ¶
TimeSince1601 returns time since 1601-01-01 00:00:00 UTC
func ToTitleNoLower ¶
ToTitleNoLower converts a string to title case without lowercasing
Types ¶
type ValidatorInterface ¶
type ValidatorInterface interface {
IsValid() bool
}
ValidatorInterface is an interface for validating structs