util

package
v2.6.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package util provides utility functions for the library.

Index

Constants

View Source
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)

View Source
const (
	KEYCTL_PERM_OTHERS uint32 = iota * 8
	KEYCTL_PERM_GROUP
	KEYCTL_PERM_USER
	KEYCTL_PERM_PROCESS
)

Variables

View Source
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 keyring.AvailableBackends() {

		if 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

View Source
var ErrAuthenticationFailed = errors.New("authentication failed")
View Source
var ErrInvalidFilter = errors.New("invalid filter syntax")
View Source
var ErrNetworkFailure = errors.New("network error")
View Source
var ErrNothingReturned = errors.New("nothing returned")
View Source
var ErrOperationFailed = errors.New("query failed")
View Source
var ErrQuotaExceeded = errors.New("quota limit exceed")
View Source
var ErrUbiquitousResults = errors.New("ubiquitous response")
View Source
var Time1601 = time.Date(1601, time.January, 1, 0, 0, 0, 0, time.UTC)

Time1601 is the epoch start date: 1601-01-01 00:00:00 UTC

Functions

func FormatError

func FormatError(err error) error

FormatError formats a validation error

func GetExecutablePath

func GetExecutablePath() string

GetExecutablePath returns the path to the current executable

func GetFromKeyring

func GetFromKeyring(key string) (string, error)

GetFromKeyring retrieves a value from the keyring

func Handle

func Handle(err error) error

Handle maps LDAP errors to more specific errors

func Hexify

func Hexify(s string) string

Hexify converts a string to a hex representation

func LookupAddress

func LookupAddress(address string) string

LookupAddress returns the hostname for the given address

func NewGUID

func NewGUID() string

NewGUID generates a new GUID

func RebuildStringSliceFlag

func RebuildStringSliceFlag(flags []string, delimiter rune) ([]string, error)

RebuildStringSliceFlag rebuilds a string slice flag from a string by using custom CSV reader

func RemoveFromKeyRing

func RemoveFromKeyRing(key string) error

RemoveFromKeyRing removes a value from the keyring

func SetToKeyring

func SetToKeyring(key, value string) error

SetToKeyring sets a value to the keyring

func SkipOAT

func SkipOAT(t testing.TB)

SkipOAT skips the test if TEST_OAT is not set to true

func TimeAfter1601

func TimeAfter1601(offset int64) time.Time

TimeAfter1601 returns time after 1601-01-01 00:00:00 UTC. Offset should be in 0.1 µs

func TimeSince1601

func TimeSince1601() time.Duration

TimeSince1601 returns time since 1601-01-01 00:00:00 UTC

func ToTitleNoLower

func ToTitleNoLower(in string) string

ToTitleNoLower converts a string to title case without lowercasing

func Unhexify

func Unhexify(s string) string

Unhexify converts a hex representation to a string

func Validate

func Validate() *validator.Validate

Validate returns a validator instance

Types

type ValidatorInterface

type ValidatorInterface interface {
	IsValid() bool
}

ValidatorInterface is an interface for validating structs

Jump to

Keyboard shortcuts

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