const DotGitIgnoreFile = ".gitignore"
const DotOdoDirectory = ".odo"
func AddOdoDirectory(gitIgnoreFile string) error
AddOdoFileIndex adds odo-file-index.json to .gitignore
func CalculateFileDataKeyFromPath(absolutePath string, rootDirectory string) (string, error)
CalculateFileDataKeyFromPath converts an absolute path to relative (and converts to OS-specific paths) for use as a map key in IndexerRet and FileIndex
func CaseInsensitive(parameter string) func(word string) bool
CaseInsensitive returns a function which compares two words caseinsensitively
func CheckPathExists(fsys filesystem.Filesystem, path string) bool
CheckPathExists checks if a path exists or not TODO(feloy) use from devfile library?
func CleanDefaultHTTPCacheDir() error
CleanDefaultHTTPCacheDir cleans the default directory used for HTTP caching
func ConvertLabelsToSelector(labels map[string]string) string
ConvertLabelsToSelector converts the given labels to selector To pass operands such as !=, append a ! prefix to the value. For E.g. map[string]string{"app.kubernetes.io/managed-by": "!odo"} Using != operators also means that resource will be filtered even if it doesn't have the key. So a resource not labelled with key "app.kubernetes.io/managed-by" will also be returned. TODO(feloy) sync with devfile library?
func CopyDirWithFS(src string, dst string, fs filesystem.Filesystem) error
CopyDirWithFS copies a whole directory recursively
func CreateIfNotExists(configFile string) error
CreateIfNotExists creates the directory and the file if it doesn't exist
func DeleteConfiguration(info interface{}, parameter string) error
DeleteConfiguration sets a parameter to null in a struct using reflection
func DeleteIndexFile(directory string) error
DeleteIndexFile deletes the index file. It doesn't throw error if it doesn't exist
func DisplayLog(followLog bool, rd io.ReadCloser, writer io.Writer, compName string, numberOfLastLines int) (err error)
DisplayLog displays logs to user stdout with some color formatting numberOfLastLines limits the number of lines from the output when we are not following it TODO(feloy) sync with devfile library?
func DownloadFileInMemory(params dfutil.HTTPRequestParams) ([]byte, error)
DownloadFileInMemory uses the url to download the file and return bytes TODO(feloy): sync with devfile library?
func DownloadFileInMemoryWithCache(params dfutil.HTTPRequestParams, cacheFor int) ([]byte, error)
DownloadFileInMemoryWithCache uses the url to download the file and return bytes
func GetAndExtractZip(zipURL string, destination string, pathToUnzip string, starterToken string, fsys filesystem.Filesystem) error
GetAndExtractZip downloads a zip file from a URL with a http prefix or takes an absolute path prefixed with file:// and extracts it to a destination. pathToUnzip specifies the path within the zip folder to extract TODO(feloy) sync with devfile library?
func GetBool(b bool) *bool
Bool returns pointer to passed boolean
func GetCommandStringFromEnvs(envVars []v1alpha2.EnvVar) string
GetCommandStringFromEnvs creates a string from the given environment variables
func GetDNS1123Name(str string) string
GetDNS1123Name Converts passed string into DNS-1123 string TODO(feloy) sync with devfile library?
func GetDataFromURI(uri, componentContext string, fs devfilefs.Filesystem) (string, error)
GetDataFromURI gets the data from the given URI if the uri is a local path, we use the componentContext to complete the local path
func GetFromFile(c interface{}, filename string) error
GetFromFile unmarshals a struct from a odo config file
func GetGitOriginPath(path string) string
GetGitOriginPath gets the remote fetch URL from the given git repo if the repo is not a git repo, the error is ignored
func GetIndexFileRelativeToContext() string
GetIndexFileRelativeToContext returns the index file relative to context i.e.; .odo/odo-file-index.json
func GetLowerCaseParameters(parameters []string) map[string]bool
GetLowerCaseParameters creates a set-like map of supported parameters from the supported parameter names
func GitSubDir(srcPath, destinationPath, subDir string) error
GitSubDir handles subDir for git components using the default filesystem
func IsPortFree(port int, localAddress string) bool
IsPortFree checks if the port on a given address is free to use
func IsSet(info interface{}, parameter string) bool
IsSet uses reflection to check if a parameter is set in a struct using the name in a case insensitive manner only supports flat structs TODO: support deeper struct using recursion
func IsValidProjectDir(path string, devfilePath string, fs filesystem.Filesystem) error
IsValidProjectDir checks that the folder to download the project from devfile is either empty or contains the devfile used. TODO(feloy) sync with devfile library?
func NamespaceKubernetesObject(componentName string, applicationName string) (string, error)
NamespaceKubernetesObject hyphenates applicationName and componentName
func NamespaceKubernetesObjectWithTrim(componentName, applicationName string, maxLen int) (string, error)
NamespaceKubernetesObjectWithTrim hyphenates applicationName and componentName if the resultant name is greater than 63 characters it trims app name then component name
func NextFreePort(start, end int, usedPorts []int, address string) (int, error)
NextFreePort returns the next free port on system, starting at start end finishing at end. If no port is found in the range [start, end], 0 is returned
func ResolveIndexFilePath(directory string) (string, error)
ResolveIndexFilePath resolves the filepath of the odo index file in the .odo folder
func SafeGetBool(b *bool) bool
SafeGetBool returns the value of the bool pointer, or false if the pointer is nil
func StartSignalWatcher(watchSignals []os.Signal, handle func(receivedSignal os.Signal))
StartSignalWatcher watches for signals and handles the situation before exiting the program
func TouchGitIgnoreFile(directory string) (gitIgnoreFile string, isNewFile bool, err error)
TouchGitIgnoreFile checks .gitignore file exists or not, if not then creates it. The first return value is the path to the .gitignore file, and the second return value indicates whether the file has been created (because it did not exist at the time this function was called).
func TruncateString(str string, maxLen int, appendIfTrunicated ...string) string
TruncateString truncates passed string to given length Note: if -1 is passed, the original string is returned if appendIfTrunicated is given, then it will be appended to trunicated string TODO(feloy) sync with devfile library?
func Unzip(src, dest, pathToUnzip string, fsys filesystem.Filesystem) ([]string, error)
Unzip will decompress a zip archive, moving specified files and folders within the zip file (parameter 1) to an output directory (parameter 2) Source: https://golangcode.com/unzip-files-in-go/ pathToUnzip (parameter 3) is the path within the zip folder to extract TODO(feloy) sync with devfile library?
func ValidateURL(sourceURL string) error
ValidateURL validates the URL TODO(feloy) sync with devfile library?
func WriteFile(newFileMap map[string]FileData, resolvedPath string) error
WriteFile writes a file map to a file, the file map is given by newFileMap param and the file location is resolvedPath param
func WriteToJSONFile(c interface{}, filename string) error
WriteToJSONFile writes a struct to json file
func WriteToYAMLFile(c interface{}, filename string) error
WriteToYAMLFile marshals a struct to a file
ConcurrentTask is a task to execute in a go-routine
type ConcurrentTask struct { ToRun func(errChannel chan error) }
ConcurrentTasks records tasks to be run concurrently with go-routines
type ConcurrentTasks struct {
// contains filtered or unexported fields
}
func NewConcurrentTasks(taskNumber int) *ConcurrentTasks
NewConcurrentTasks creates a new ConcurrentTasks instance, dimensioned to accept at least the specified number of tasks
func (ct *ConcurrentTasks) Add(task ConcurrentTask)
Add adds the specified ConcurrentTask to the list of tasks to be run concurrently
func (ct *ConcurrentTasks) Run() error
Run concurrently runs the added tasks failing on the first error Based on https://garrypolley.com/2016/02/10/golang-routines-errors/
type FileData struct { Size int64 LastModifiedDate time.Time RemoteAttribute string `json:"RemoteAttribute,omitempty"` }
func GenerateNewFileDataEntry(absolutePath string, rootDirectory string) (string, *FileData, error)
GenerateNewFileDataEntry creates a new FileData entry for use by IndexerRet and/or FileIndex
FileIndex holds the file index used for storing local file state change
type FileIndex struct { metav1.TypeMeta Files map[string]FileData }
func NewFileIndex() *FileIndex
NewFileIndex returns a fileIndex
func ReadFileIndex(filePath string) (*FileIndex, error)
ReadFileIndex tries to read the odo index file from the given location and returns the data from the file if no such file is present, it means the folder hasn't been walked and thus returns an empty list
IndexerRet is a struct that represent return value of RunIndexer function
type IndexerRet struct { FilesChanged []string FilesDeleted []string RemoteDeleted []string NewFileMap map[string]FileData ResolvedPath string }
func RunIndexerWithRemote(directory string, originalIgnoreRules []string, remoteDirectories map[string]string) (ret IndexerRet, err error)
RunIndexerWithRemote reads the existing index from the given directory and runs the indexer on it with the given ignore rules it also adds the file index to the .gitignore file and resolves the path