piperutils

package
v1.414.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 23 Imported by: 52

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsStringPart added in v1.38.0

func ContainsStringPart(s []string, part string) bool

ContainsStringPart checks whether the element is contained as part of one of the elements of the slice

func Copy added in v1.3.0

func Copy(src, dst string) (int64, error)

Copy ...

func CopyAtoB added in v1.204.0

func CopyAtoB(a, b interface{})

CopyAtoB copies the contents of a into slice b given that they are of equal size and compatible type

func CopyData added in v1.149.0

func CopyData(dst io.Writer, src io.Reader) (int64, error)

CopyData transfers the bytes from src to dst without doing close handling implicitly.

func EncodeString added in v1.153.0

func EncodeString(token string) string

func EncodeUsernamePassword added in v1.153.0

func EncodeUsernamePassword(username, password string) string

func ExcludeFiles added in v1.111.0

func ExcludeFiles(files, excludes []string) ([]string, error)

ExcludeFiles returns a slice of files, which contains only the sub-set of files that matched none of the glob patterns in the provided excludes list.

func ExecuteTemplate added in v1.38.0

func ExecuteTemplate(txtTemplate string, context interface{}) (string, error)

ExecuteTemplate parses the provided template, substitutes values and returns the output

func ExecuteTemplateFunctions added in v1.38.0

func ExecuteTemplateFunctions(txtTemplate string, functionMap template.FuncMap, context interface{}) (string, error)

ExecuteTemplateFunctions parses the provided template, applies the transformation functions, substitutes values and returns the output

func FileExists

func FileExists(filename string) (bool, error)

FileExists returns true if the file system entry for the given path exists and is not a directory.

func GetPurl added in v1.403.0

func GetPurl(bomFilePath string) string

func Keys added in v1.238.0

func Keys[M ~map[K]V, K comparable, V any](m M) []K
func PersistReportsAndLinks(stepName, workspace string, files fileWriter, reports, links []Path) error

PersistReportsAndLinks stores the report paths and links in JSON format in the workspace for processing outside

func Prefix added in v1.19.0

func Prefix(in []string, prefix string) []string

Prefix adds a prefix to each element of the slice

func PrefixIfNeeded added in v1.22.0

func PrefixIfNeeded(in []string, prefix string) []string

PrefixIfNeeded adds a prefix to each element of the slice if not already prefixed

func RemoveAll added in v1.87.0

func RemoveAll(arr []string, item string) ([]string, bool)

RemoveAll removes all instances of element from the slice and returns a truncated slice as well as a boolean to indicate whether at least one element was found and removed.

func SafeDereference added in v1.311.0

func SafeDereference[T any](p *T) T

func SplitAndTrim added in v1.25.0

func SplitAndTrim(in []string, separator string) (out []string)

SplitAndTrim iterates over the strings in the given slice and splits each on the provided separator. Each resulting sub-string is then a separate entry in the returned array.

func Title added in v1.222.0

func Title(in string) string

func Trim added in v1.19.0

func Trim(in []string) (out []string)

Trim removes dangling whitespaces from each element of the slice, empty elements are dropped

func UniqueStrings added in v1.123.0

func UniqueStrings(values []string) []string

UniqueStrings removes duplicates from values

func Untar added in v1.172.0

func Untar(src string, dest string, stripComponentLevel int) error

Untar will decompress a gzipped archive and then untar it, moving all files and folders within the tgz file (parameter 1) to an output directory (parameter 2). some tar like the one created from npm have an addtional package folder which need to be removed during untar stripComponent level acts the same like in the tar cli with level 1 corresponding to elimination of parent folder stripComponentLevel = 1 -> parentFolder/someFile.Txt -> someFile.Txt stripComponentLevel = 2 -> parentFolder/childFolder/someFile.Txt -> someFile.Txt when stripCompenent in 0 the untar will retain the original tar folder structure when stripCompmenet is greater than 0 the expectation is all files must be under that level folder and if not there is a hard check and failure condition

func Unzip added in v1.19.0

func Unzip(src, dest string) ([]string, error)

Unzip will decompress a zip archive, moving all files and folders within the zip file (parameter 1) to an output directory (parameter 2). from https://golangcode.com/unzip-files-in-go/ with the following license: MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

func Values added in v1.238.0

func Values[M ~map[K]V, K comparable, V any](m M) []V

Values returns the slice of values of the map provided

Types

type Bom added in v1.387.0

type Bom struct {
	Metadata Metadata `xml:"metadata"`
}

To serialize the cyclonedx BOM file

func GetBom added in v1.387.0

func GetBom(absoluteBomPath string) (Bom, error)

type BomComponent added in v1.387.0

type BomComponent struct {
	Purl string `xml:"purl"`
}

type BomProperty added in v1.387.0

type BomProperty struct {
	Name  string `xml:"name,attr"`
	Value string `xml:"value,attr"`
}

type FileUtils added in v1.15.0

type FileUtils interface {
	Abs(path string) (string, error)
	DirExists(path string) (bool, error)
	FileExists(filename string) (bool, error)
	Copy(src, dest string) (int64, error)
	Move(src, dest string) error
	FileRead(path string) ([]byte, error)
	ReadFile(path string) ([]byte, error)
	FileWrite(path string, content []byte, perm os.FileMode) error
	WriteFile(path string, content []byte, perm os.FileMode) error
	FileRemove(path string) error
	MkdirAll(path string, perm os.FileMode) error
	Chmod(path string, mode os.FileMode) error
	Chown(path string, uid, gid int) error
	Glob(pattern string) (matches []string, err error)
	Chdir(path string) error
	TempDir(string, string) (string, error)
	RemoveAll(string) error
	FileRename(string, string) error
	Getwd() (string, error)
	Symlink(oldname string, newname string) error
	SHA256(path string) (string, error)
	CurrentTime(format string) string
	Open(name string) (io.ReadWriteCloser, error)
	Create(name string) (io.ReadWriteCloser, error)
	Readlink(name string) (string, error)
	Stat(path string) (os.FileInfo, error)
	Lstat(path string) (os.FileInfo, error)
}

FileUtils ...

type Files added in v1.15.0

type Files struct{}

Files ...

func (Files) Abs added in v1.62.0

func (f Files) Abs(path string) (string, error)

Abs is a wrapper for filepath.Abs()

func (Files) Chdir added in v1.43.0

func (f Files) Chdir(path string) error

Chdir is a wrapper for os.Chdir().

func (Files) Chmod added in v1.57.0

func (f Files) Chmod(path string, mode os.FileMode) error

Chmod is a wrapper for os.Chmod().

func (Files) Chown added in v1.318.0

func (f Files) Chown(path string, uid, gid int) error

Chown is a recursive wrapper for os.Chown().

func (Files) Copy added in v1.15.0

func (f Files) Copy(src, dst string) (int64, error)

Copy ...

func (Files) Create added in v1.207.0

func (f Files) Create(name string) (io.ReadWriteCloser, error)

Create is a wrapper for os.Create

func (Files) CurrentTime added in v1.204.0

func (f Files) CurrentTime(format string) string

CurrentTime returns the current time in the specified format

func (Files) DirExists added in v1.43.0

func (f Files) DirExists(path string) (bool, error)

DirExists returns true if the file system entry for the given path exists and is a directory.

func (Files) FileExists added in v1.15.0

func (f Files) FileExists(filename string) (bool, error)

FileExists returns true if the file system entry for the given path exists and is not a directory.

func (*Files) FileOpen added in v1.85.0

func (f *Files) FileOpen(name string, flag int, perm os.FileMode) (*os.File, error)

FileOpen is a wrapper for os.OpenFile().

func (Files) FileRead added in v1.15.0

func (f Files) FileRead(path string) ([]byte, error)

FileRead is a wrapper for os.ReadFile().

func (Files) FileRemove added in v1.43.0

func (f Files) FileRemove(path string) error

FileRemove is a wrapper for os.Remove().

func (Files) FileRename added in v1.85.0

func (f Files) FileRename(oldPath, newPath string) error

FileRename is a wrapper for os.Rename().

func (Files) FileWrite added in v1.15.0

func (f Files) FileWrite(path string, content []byte, perm os.FileMode) error

FileWrite is a wrapper for os.WriteFile().

func (Files) Getwd added in v1.43.0

func (f Files) Getwd() (string, error)

Getwd is a wrapper for os.Getwd().

func (Files) Glob added in v1.43.0

func (f Files) Glob(pattern string) (matches []string, err error)

Glob is a wrapper for doublestar.Glob().

func (Files) Lstat added in v1.381.0

func (f Files) Lstat(path string) (os.FileInfo, error)

Readlink wraps os.Readlink

func (Files) MkdirAll added in v1.15.0

func (f Files) MkdirAll(path string, perm os.FileMode) error

MkdirAll is a wrapper for os.MkdirAll().

func (Files) Move added in v1.200.0

func (f Files) Move(src, dst string) error

Move will move files from src to dst

func (Files) Open added in v1.207.0

func (f Files) Open(name string) (io.ReadWriteCloser, error)

Open is a wrapper for os.Open

func (Files) ReadFile added in v1.238.0

func (f Files) ReadFile(path string) ([]byte, error)

ReadFile is a wrapper for os.ReadFile() using the same name and syntax.

func (f Files) Readlink(name string) (string, error)

Readlink wraps os.Readlink

func (Files) RemoveAll added in v1.85.0

func (f Files) RemoveAll(path string) error

RemoveAll is a wrapper for os.RemoveAll().

func (Files) SHA256 added in v1.191.0

func (f Files) SHA256(path string) (string, error)

SHA256 computes a SHA256 for a given file

func (Files) Stat added in v1.57.0

func (f Files) Stat(path string) (os.FileInfo, error)

Stat is a wrapper for os.Stat()

func (f Files) Symlink(oldname, newname string) error

Symlink is a wrapper for os.Symlink

func (Files) TempDir added in v1.95.0

func (f Files) TempDir(dir, pattern string) (name string, err error)

TempDir creates a temporary directory

func (Files) WriteFile added in v1.238.0

func (f Files) WriteFile(path string, content []byte, perm os.FileMode) error

WriteFile is a wrapper for os.ReadFile() using the same name and syntax.

type Metadata added in v1.387.0

type Metadata struct {
	Component  BomComponent  `xml:"component"`
	Properties []BomProperty `xml:"properties>property"`
}

type Path added in v1.11.0

type Path struct {
	Name      string `json:"name"`
	Target    string `json:"target"`
	Mandatory bool   `json:"mandatory"`
	Scope     string `json:"scope"`
}

Path - struct to serialize paths and some metadata back to the invoker

type ProjectStructure added in v1.14.0

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

ProjectStructure describes a directory containing source code

func (*ProjectStructure) UsesMaven added in v1.14.0

func (projectStructure *ProjectStructure) UsesMaven() bool

UsesMaven returns `true` if the project structure directory contains a pom.xml file, false otherwise

func (*ProjectStructure) UsesMta added in v1.14.0

func (projectStructure *ProjectStructure) UsesMta() bool

UsesMta returns `true` if the project structure directory contains typical files for mta projects (mta.yaml, mta.yml), `false` otherwise

func (*ProjectStructure) UsesNpm added in v1.14.0

func (projectStructure *ProjectStructure) UsesNpm() bool

UsesNpm returns `true` if the project structure directory contains a package.json file, false otherwise

Jump to

Keyboard shortcuts

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