utils

package
v1.4.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const FRAMEWORK_WEIGHT = 10
View Source
const FROM_PORT = 0
View Source
const TOOL_WEIGHT = 5
View Source
const TO_PORT = 65535

Variables

This section is empty.

Functions

func AddToArrayIfValueExist

func AddToArrayIfValueExist(arr *[]string, val string)

func CloseFile added in v1.3.1

func CloseFile(file *os.File)

func CloseHttpResponseBody added in v1.3.1

func CloseHttpResponseBody(resp *http.Response)

func Contains

func Contains(s []string, str string) bool

func ConvertPropertiesFileAsPathToMap

func ConvertPropertiesFileAsPathToMap(path string) (map[string]string, error)

ConvertPropertiesFileAsPathToMap fetches a file from a given path and transforms it into a map

func ConvertPropertiesFileToMap

func ConvertPropertiesFileToMap(fileInBytes []byte) (map[string]string, error)

ConvertPropertiesFileAsPathToMap transforms a slice of bytes it into a map

func FindAllPortsSubmatch

func FindAllPortsSubmatch(re *regexp.Regexp, text string, group int) []int

FindAllPortsSubmatch returns a slice of port int values, matching a regex inside a given text

func FindPortSubmatch

func FindPortSubmatch(re *regexp.Regexp, text string, group int) int

FindPortSubMatch returns a port number in case it finds one for a given regex group

func FindPotentialPortGroup

func FindPotentialPortGroup(re *regexp.Regexp, text string, group int) string

FindPotentialPortGroup returns a placeholder for port if is found

func GenLogger

func GenLogger(logLevel string) error

GenLogger: Generates the logger with the given zapcore.Level

func GenerateApplicationFileFromFilters added in v1.2.0

func GenerateApplicationFileFromFilters(files []string, path string, suffix string, ctx *context.Context) []model.ApplicationFileInfo

GenerateApplicationFileFromFilters generates a slice of model.ApplicationFileInfo from a given list of files and the root path of a component. If suffix exists it generates items only for files ending with this suffix.

func GetAnyApplicationFilePath

func GetAnyApplicationFilePath(root string, propsFiles []model.ApplicationFileInfo, ctx *context.Context) string

GetAnyApplicationFilePath returns the location of a file if it exists in the directory and the given file name is a substring.

func GetAnyApplicationFilePathExactMatch

func GetAnyApplicationFilePathExactMatch(root string, propsFiles []model.ApplicationFileInfo) string

GetAnyApplicationFilePathExactMatch returns the location of a file if it exists in the directory and matches the given file name.

func GetApplicationFileBytes added in v1.2.0

func GetApplicationFileBytes(propsFile model.ApplicationFileInfo) ([]byte, error)

GetApplicationFileBytes returns a slice of bytes of a file if it exists in the directory and the given file name is a substring.

func GetApplicationFileContents added in v1.2.0

func GetApplicationFileContents(appFileInfos []model.ApplicationFileInfo) ([]string, error)

GetApplicationFileContents returns a slice of strings for all file contents found for a given slice of ApplicationFileInfo.

func GetApplicationFileInfo added in v1.2.0

func GetApplicationFileInfo(propsFiles []model.ApplicationFileInfo, filename string) (model.ApplicationFileInfo, error)

GetApplicationFileInfo returns an item from a slice of applicationFileInfos if it matches the given filename

func GetCachedFilePathsFromRoot

func GetCachedFilePathsFromRoot(root string, ctx *context.Context) ([]string, error)

func GetComposerJsonSchemaFromFile

func GetComposerJsonSchemaFromFile(path string) (schema.ComposerJson, error)

GetComposerJsonSchemaFromFile returns the composer.json found in the path.

func GetEnvVarPortValueFromDockerfile added in v1.1.5

func GetEnvVarPortValueFromDockerfile(path string, portPlaceholders []string) ([]int, error)

GetEnvVarPortValueFromDockerfile gets port value defined as env vars.

func GetEnvVarsFromDockerFile added in v1.1.5

func GetEnvVarsFromDockerFile(root string) ([]model.EnvVar, error)

GetEnvVarsFromDockerFile returns a slice of env vars from Dockerfiles in the given directory.

func GetFile

func GetFile(filePaths *[]string, wantedFile string) string

GetFile returns the first match where the wantedFile is in a filePaths path.

func GetFilePathsFromRoot

func GetFilePathsFromRoot(root string) ([]string, error)

GetFilePathsFromRoot walks the file tree starting from root and returns a slice of all file paths found. Ignores files from .gitignore if it exists.

func GetFilePathsInRoot

func GetFilePathsInRoot(root string) ([]string, error)

GetFilePathsInRoot returns a slice of all files in the root.

func GetFilesByRegex

func GetFilesByRegex(filePaths *[]string, regexFile string) []string

GetFilesByRegex returns a slice of file paths from filePaths if the file name matches the regex.

func GetLocations added in v1.1.5

func GetLocations(root string) []string

GetLocations returns a list of file paths representing common locations where Dockerfiles might be found within the specified 'root' directory and one level down.

It starts with a predefined list of common file names for a Dockerfile ('Dockerfile', 'Containerfile', 'dockerfile', 'containerfile'), and appends such file names to the 'root' subdirectories.

Note that hidden files and directories (starting with a dot, e.g., '.git') are ignored while traversing the 'root' directory.

func GetOrCreateLogger

func GetOrCreateLogger() logr.Logger

GetOrCreateLogger: Checks if the CliLogger is already created, otherwise it creates it with errorLevel

func GetPackageJsonSchemaFromFile

func GetPackageJsonSchemaFromFile(path string) (schema.PackageJson, error)

GetPackageJsonSchemaFromFile returns the package.json found in the path.

func GetPomFileContent

func GetPomFileContent(pomFilePath string) (schema.Pom, error)

GetPomFileContent returns the pom found in the path.

func GetPortValueFromEnvFile

func GetPortValueFromEnvFile(root string, regex string) int

GetPortValueFromEnvFile returns the first port value of a slice of port values declared from env var files.

func GetPortValuesFromEnvFile

func GetPortValuesFromEnvFile(root string, regexes []string) []int

GetPortValuesFromEnvFile returns all port values found inside an env var file

func GetStringValueFromEnvFile

func GetStringValueFromEnvFile(root string, regex string) string

GetStringValueFromEnvFile returns port values as string from env file

func GetValidPort

func GetValidPort(port string) (int, error)

GetValidPort checks if a string is a valid port and returns the port. Returns -1 if not a valid port.

func GetValidPorts

func GetValidPorts(ports []string) []int

GetValidPorts returns a slice of valid ports.

func GetValidPortsFromEnvDockerfile added in v1.1.5

func GetValidPortsFromEnvDockerfile(envs []string, envVars []model.EnvVar) []int

GetValidPortsFromEnvs returns a slice of valid ports from a dockerfile.

func GetValidPortsFromEnvs

func GetValidPortsFromEnvs(envs []string) []int

GetValidPortsFromEnvs returns a slice of valid ports.

func IsPathOfWantedFile

func IsPathOfWantedFile(path string, wantedFile string) bool

IsPathOfWantedFile checks if the file is in the path.

func IsTagInComposerJsonFile

func IsTagInComposerJsonFile(file string, tag string) bool

IsTagInComposerJsonFile checks if the file is a composer.json and contains the tag.

func IsTagInFile

func IsTagInFile(file string, tag string) (bool, error)

IsTagInFile checks if the file contains the tag.

func IsTagInPackageJsonFile

func IsTagInPackageJsonFile(file string, tag string) bool

IsTagInPackageJsonFile checks if the file is a package.json and contains the tag.

func IsTagInPomXMLFile

func IsTagInPomXMLFile(pomFilePath string, tag string) (bool, error)

IsTagInPomXMLFile checks if a pom file contains the tag.

func IsTagInPomXMLFileArtifactId

func IsTagInPomXMLFileArtifactId(pomFilePath, groupId, artifactId string) (bool, error)

IsTagInPomXMLFileArtifactId checks if a pom file contains the artifactId.

func IsValidPort

func IsValidPort(port int) bool

IsValidPort checks if an integer is a valid port.

func NormalizeSplit

func NormalizeSplit(file string) (string, string)

NormalizeSplit splits a filepath into dir and filename

func PrintNoArgsWarningMessage

func PrintNoArgsWarningMessage(command string)

func PrintPrettifyOutput

func PrintPrettifyOutput(value interface{}, err error)

func PrintWrongLoggingLevelMessage

func PrintWrongLoggingLevelMessage(command string)

func ReadAnyApplicationFileExactMatch

func ReadAnyApplicationFileExactMatch(root string, propsFiles []model.ApplicationFileInfo) ([]byte, error)

ReadAnyApplicationFileExactMatch returns a byte slice if the exact given file exists in the directory.

func ReadPortsFromDockerfile added in v1.1.5

func ReadPortsFromDockerfile(file io.Reader) []int

ReadPortsFromDockerfile returns a slice of port numbers.

func RedirectErrorStringToStdErrAndExit

func RedirectErrorStringToStdErrAndExit(err string)

func RedirectErrorToStdErrAndExit

func RedirectErrorToStdErrAndExit(err error)

Types

type CLILogger

type CLILogger struct {
	Logger    logr.Logger
	Activated bool
}
var CliLogger CLILogger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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