utils

package
v0.0.0-...-ec844c3 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HSTSSetting = "max-age=31536000; includeSubDomains; preload"

	// Header Templates
	ContentDispositionAttachmentTemplate = "attachment; filename=\"%s\""

	HeaderValueWait = "wait"

	ErrorInvalidSkip  string = "invalid skip: %v"
	ErrorInvalidLimit string = "invalid limit: %v"
)

Variables

View Source
var (
	ErrInvalidSharpHoundVersion   = errors.New("invalid sharphound version string")
	ErrInvalidAzureHoundVersion   = errors.New("invalid azurehound version string")
	ErrRecommendSharphoundVersion = errors.New("please upgrade to sharphound v2.0.3 or above")
	ErrInvalidClientType          = errors.New("invalid client type")
)
View Source
var MapErrorsToStrings func(collection []error, iteratee func(value error) string) []string
View Source
var NilErrorValue = reflect.Zero(reflect.TypeOf((*error)(nil)).Elem())

NilErrorValue is the reflected zero value of errors.Error

Functions

func Bind

func Bind(functionPtr any, function func([]reflect.Value) []reflect.Value)

Bind sets a typed function pointer to a generic implementation of a function based on reflect.Value.

Caveat Emptor: These functions do not benefit from compiler type-checking and can panic during runtime in the same way dynamically typed languages behave. Albeit small, there is a performance impact when creating functions with Bind. This is due to the additional steps it takes to determine the type of an interface.

func GenericAssign

func GenericAssign(args []reflect.Value) []reflect.Value

GenericAssign is the implementation of a variadic assign function for dynamic types. The function assigns the enumerable properties of each source object from left to right to the returned object. Subsequent source objects overwrite the property assignments of previous source object.

var assignMap func(...map[string]interface{}) map[string]interface{}
func init() {
	Bind(&assignMap, GenericAssign)
}

func main() {
	m1 := map[string]interface{} {
		"foo": "bar",
	}
	m2 := map[string]interface{} {
		"foo": "baz",
	}
	m3 := map[string]interface{} {
		"bar": "buzz",
	}
	if m4, err := assignMap(m1, m2, m3); err == nil {
		fmt.Println(m4)
		// Output: map[bar:buzz foo:baz]
	}
}

func GenericClone

func GenericClone(args []reflect.Value) []reflect.Value

GenericClone is the implementation of a shallow clone function for dynamic types.

var cloneMap func(map[string]interface{}) map[string]interface{}
func init() {
	Bind(&cloneMap, GenericClone)
}

func main() {
	m1 := map[string]interface{} {
		"foo": "bar",
	}
	m2 := cloneMap(m1)
	fmt.Println(m2)
	// Output: map[foo:bar]
}

func GenericMap

func GenericMap(args []reflect.Value) []reflect.Value

GenericMap is the implementation of a map function for dynamic types.

func GetLimitParamForGraphQuery

func GetLimitParamForGraphQuery(params url.Values) (int, error)

func GetOrderForNeo4jQuery

func GetOrderForNeo4jQuery(params url.Values) string

func GetPageParamsForGraphQuery

func GetPageParamsForGraphQuery(_ context.Context, params url.Values) (int, int, string, error)

func GetSkipParamForGraphQuery

func GetSkipParamForGraphQuery(params url.Values) (int, error)

func HeaderMatches

func HeaderMatches(headers http.Header, key string, target ...string) bool

func IsValidClientVersion

func IsValidClientVersion(userAgent string) error

IsValidClientVersion checks the version from a user agent to ensure it's a valid UserAgent and that the version of the client is not EOL (currently SHS v1.x and SHS < v2.0.3). Returns an error if invalid and nil if valid

func IsValidEmail

func IsValidEmail(maybeEmail string) bool

func MarshalToMap

func MarshalToMap(marshalable any) (map[string]any, error)

func ReadRFC3339

func ReadRFC3339(valueStr string, defaultValue time.Time) (time.Time, error)

ReadRFC3339 attempts to parse a RFC3339 string into a time.Time struct.

If the RFC3339 string is empty this function returns the given default value. If the string is not formatted as a valid RFC3339 datetime then this function will return the resulting error.

func ReplaceFieldValueInJsonString

func ReplaceFieldValueInJsonString(jsonString string, field string, value any) (string, error)

ReplaceFieldValueInJsonString replaces a field value at the root of a JSON object If the field does not exist in jsonString, it will effectively do nothing

func SwitchCase

func SwitchCase(input string, format string) (string, error)

SwitchCase is a helper function to change string case. This was originally charted out to be used for formatting error responses

func WriteResultJson

func WriteResultJson(w http.ResponseWriter, r any)

func WriteResultRawJson

func WriteResultRawJson(w http.ResponseWriter, r []byte)

Types

type ClientType

type ClientType int
const (
	ClientTypeSharpHound ClientType = 0
	ClientTypeAzureHound ClientType = 1
)

type ClientVersion

type ClientVersion struct {
	ClientType ClientType
	Major      int
	Minor      int
	Patch      int
	Extra      int
}

func ParseAzurehoundVersion

func ParseAzurehoundVersion(userAgent string) (ClientVersion, error)

func ParseClientVersion

func ParseClientVersion(userAgent string) (ClientVersion, error)

func ParseSharpHoundVersion

func ParseSharpHoundVersion(userAgent string) (ClientVersion, error)

type Errors

type Errors []error

func (Errors) AsStringSlice

func (s Errors) AsStringSlice() []string

func (Errors) Error

func (s Errors) Error() string

type JsonResult

type JsonResult struct {
	Detail string `json:"detail,omitempty"`
	Msg    string `json:"msg,omitempty"`
}

Directories

Path Synopsis
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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