utils

package
v0.18.0-dev.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: AGPL-3.0 Imports: 40 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Timing []timeLog

Functions

func BuildRequestPayload

func BuildRequestPayload(signature string, payload map[string]interface{}) *bytes.Buffer

BuildRequestPayload merges the provided payload with the standard payload that needs to be sent

func CtyToGo

func CtyToGo(v cty.Value) (val interface{}, err error)

func CtyToJSON

func CtyToJSON(val cty.Value) (string, error)

CtyToJSON converts a cty value to it;s JSON representation

func CtyToPostgresString

func CtyToPostgresString(v cty.Value) (valStr string, err error)

CtyToPostgresString convert a cty value into a postgres representation of the value

func CtyToString

func CtyToString(v cty.Value) (valStr string, err error)

CtyToString convert a cty value into a string representation of the value

func CtyTypeToHclType

func CtyTypeToHclType(types ...cty.Type) string

CtyTypeToHclType converts a cty type to a hcl type accept multiple types and use the first non null and non dynamic one

func DisplayProfileData

func DisplayProfileData()

func EnsureDirectoryPermission

func EnsureDirectoryPermission(directoryPath string) error

func FileHash

func FileHash(filePath string) (string, error)

func FileMD5Hash added in v0.17.0

func FileMD5Hash(filePath string) ([]byte, error)

func FileModTime

func FileModTime(filePath string) (time.Time, error)

func FilenameNoExtension added in v0.17.0

func FilenameNoExtension(fileName string) string

func Filter

func Filter[V any](elements []V, predicate func(V) bool) []V

Filter returns a new slice only containing the elements for which invoking the predicate returned true

The predicate is invoked with each element

func FindProcess

func FindProcess(targetPid int) (*psutils.Process, error)

FindProcess tries to find the process with the given pid returns nil if the process could not be found

func GetMD5Hash

func GetMD5Hash(text string) string

func GetPluginName added in v0.17.0

func GetPluginName(plugin string) string

GetPluginName function is used to get the plugin name required while installing/updating/removing a plugin. External plugins require the repo names to be prefixed(eg: francois2metz/scalingo). Sample input 1: hub.steampipe.io/plugins/francois2metz/scalingo@latest Sample output 1: francois2metz/scalingo Sample input 2: hub.steampipe.io/plugins/turbot/aws@latest Sample output 2: aws

func IsContextCancelled

func IsContextCancelled(ctx context.Context) bool

func IsMacM1

func IsMacM1() (bool, error)

IsMacM1 returns whether the system is a Mac M1 machine

func IsPortBindable

func IsPortBindable(port int) error

func IsWSL

func IsWSL() bool

IsWSL detects whether app is running in WSL environment refer to: https://github.com/Microsoft/WSL/issues/423#issuecomment-679190758

func LocalAddresses

func LocalAddresses() ([]string, error)

func LogTime

func LogTime(operation string)

func Map

func Map[V any, M any](elements []V, mapper func(V) M) []M

Map returns a new slice where every value is mapped to a new value through the mapper

The mapper is invoked with each element

func MergeMaps added in v0.17.0

func MergeMaps[M ~map[K]V, K comparable, V any](old, new M) M

MergeMaps merges 'new' onto 'old'. Values existing in old already have precedence Any value existing in new but not old is added to old

func MoveFile

func MoveFile(source string, destination string) error

MoveFile moves a file from source to destiantion.

It first attempts the movement using OS primitives (os.Rename)
If os.Rename fails, it copies the file byte-by-byte to the destination and then removes the source

func PadRight added in v0.16.2

func PadRight(str string, length int, pad byte) string

PadRight returns a new string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character.

func ParseCertificateInLocation added in v0.17.0

func ParseCertificateInLocation(location string) (*x509.Certificate, error)

func Partition

func Partition[V any](elements []V, predicate func(V) bool) ([]V, []V)

Partition splits the array of elements into two groups: the left partition contains elements that the predicate returns `true` for. the right partition contains elements that the predicate returns `false` for.

The predicate is invoked with each element

func PidExists

func PidExists(targetPid int) (bool, error)

PidExists scans through the list of PIDs in the system and checks for the `targetPID`.

PidExists uses iteration, instead of signalling, since we have observed that signalling does not always work reliably when the destination of the signal is a child of the source of the signal - which may be the case then starting implicit services

func Pluralize

func Pluralize(base string, count int) string

Pluralize :: pluralizes a word (if applicable) based on provided count

func PrettifyJsonFromReader added in v0.17.0

func PrettifyJsonFromReader(dataToExport io.Reader) (io.Reader, error)

func RemoveDirectoryContents

func RemoveDirectoryContents(removePath string) error

func Resize added in v0.16.2

func Resize(s string, length uint) string

Resize resizes the string with the given length. It ellipses with '…' when the string's length exceeds the desired length or pads spaces to the right of the string when length is smaller than desired

func SafeIntEqual

func SafeIntEqual(i1, i2 *int) bool

func SafeStringsEqual

func SafeStringsEqual(s1, s2 interface{}) bool

func SendRequest

func SendRequest(signature string, method string, sendRequestTo url.URL, payload *bytes.Buffer, timeout time.Duration) (*http.Response, error)

SendRequest makes a http call to the given URL

func SortedMapKeys added in v0.17.0

func SortedMapKeys[V any](m map[string]V) []string

func SplitByRune

func SplitByRune(str string, r rune) []string

SplitByRune uses the CSV decoder to parse out the tokens - even if they are quoted and/or escaped

func SplitByWhitespace

func SplitByWhitespace(str string) []string

SplitByWhitespace splits by the ' ' rune

func StringHash

func StringHash(s string) uint32

func ToIntegerPointer

func ToIntegerPointer(i int) *int

ToIntegerPointer converts an integer into its pointer

func ToStringPointer

func ToStringPointer(s string) *string

ToStringPointer converts a string into its pointer

func UnderlyingArch

func UnderlyingArch() (string, error)

UnderlyingArch detects the underlying architecture(amd64/arm64) of the system we need this to detect the underlying architecture to install the correct FDW package

func UnquoteStringArray added in v0.17.0

func UnquoteStringArray(stringArray []string) []string

UnquoteStringArray removes quote marks from elements of string array

func WriteCertificate added in v0.17.0

func WriteCertificate(path string, certificate []byte) error

func WritePrivateKey added in v0.17.0

func WritePrivateKey(path string, key *rsa.PrivateKey) error

Types

type ExitCode

type ExitCode int

ExitCode :: alias for exitcode

type InteractiveExitStatus

type InteractiveExitStatus struct {
	// TODO remove altogether
	ExitCode int
}

InteractiveExitStatus :: exist status from the interative prompt

We exit go-prompt after every query (in order to manage the prompt history to only include complete queries) We therefore need to distinguish between:

a user requested exit (ctrl+D or .exit) - indicated by a non-nil exit code and restart=false and a value , go-prompt being terminated after a query completion and requiring restarting - indicated by restart=true

type Semaphore added in v0.17.0

type Semaphore struct {
	// contains filtered or unexported fields
}

Semaphore is a struct wrapping a sema`phore thast makes it easier to debug deadlocvks and failures to release

func NewSemaphore added in v0.17.0

func NewSemaphore(count int64) *Semaphore

func (Semaphore) Acquire added in v0.17.0

func (l Semaphore) Acquire(ctx context.Context, count int64, owner string) error

func (Semaphore) Release added in v0.17.0

func (l Semaphore) Release(i int64, owner string)

func (Semaphore) String added in v0.17.0

func (l Semaphore) String() any

Jump to

Keyboard shortcuts

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