...

Package util

Overview ▾

Index ▾

Constants
func AddOdoDirectory(gitIgnoreFile string) error
func CalculateFileDataKeyFromPath(absolutePath string, rootDirectory string) (string, error)
func CaseInsensitive(parameter string) func(word string) bool
func CheckPathExists(fsys filesystem.Filesystem, path string) bool
func CleanDefaultHTTPCacheDir() error
func ConvertLabelsToSelector(labels map[string]string) string
func CopyDirWithFS(src string, dst string, fs filesystem.Filesystem) error
func CreateIfNotExists(configFile string) error
func DeleteConfiguration(info interface{}, parameter string) error
func DeleteIndexFile(directory string) error
func DisplayLog(followLog bool, rd io.ReadCloser, writer io.Writer, compName string, numberOfLastLines int) (err error)
func DownloadFileInMemory(params dfutil.HTTPRequestParams) ([]byte, error)
func DownloadFileInMemoryWithCache(params dfutil.HTTPRequestParams, cacheFor int) ([]byte, error)
func GetAndExtractZip(zipURL string, destination string, pathToUnzip string, starterToken string, fsys filesystem.Filesystem) error
func GetBool(b bool) *bool
func GetCommandStringFromEnvs(envVars []v1alpha2.EnvVar) string
func GetDNS1123Name(str string) string
func GetDataFromURI(uri, componentContext string, fs devfilefs.Filesystem) (string, error)
func GetFromFile(c interface{}, filename string) error
func GetGitOriginPath(path string) string
func GetIndexFileRelativeToContext() string
func GetLowerCaseParameters(parameters []string) map[string]bool
func GitSubDir(srcPath, destinationPath, subDir string) error
func IsPortFree(port int, localAddress string) bool
func IsSet(info interface{}, parameter string) bool
func IsValidProjectDir(path string, devfilePath string, fs filesystem.Filesystem) error
func NamespaceKubernetesObject(componentName string, applicationName string) (string, error)
func NamespaceKubernetesObjectWithTrim(componentName, applicationName string, maxLen int) (string, error)
func NextFreePort(start, end int, usedPorts []int, address string) (int, error)
func ResolveIndexFilePath(directory string) (string, error)
func SafeGetBool(b *bool) bool
func StartSignalWatcher(watchSignals []os.Signal, handle func(receivedSignal os.Signal))
func TouchGitIgnoreFile(directory string) (gitIgnoreFile string, isNewFile bool, err error)
func TruncateString(str string, maxLen int, appendIfTrunicated ...string) string
func Unzip(src, dest, pathToUnzip string, fsys filesystem.Filesystem) ([]string, error)
func ValidateURL(sourceURL string) error
func WriteFile(newFileMap map[string]FileData, resolvedPath string) error
func WriteToJSONFile(c interface{}, filename string) error
func WriteToYAMLFile(c interface{}, filename string) error
type ConcurrentTask
type ConcurrentTasks
    func NewConcurrentTasks(taskNumber int) *ConcurrentTasks
    func (ct *ConcurrentTasks) Add(task ConcurrentTask)
    func (ct *ConcurrentTasks) Run() error
type FileData
    func GenerateNewFileDataEntry(absolutePath string, rootDirectory string) (string, *FileData, error)
type FileIndex
    func NewFileIndex() *FileIndex
    func ReadFileIndex(filePath string) (*FileIndex, error)
type IndexerRet
    func RunIndexerWithRemote(directory string, originalIgnoreRules []string, remoteDirectories map[string]string) (ret IndexerRet, err error)

Package files

concurrent.go config_util.go file_indexer.go httpcache.go util.go

Constants

const DotGitIgnoreFile = ".gitignore"
const DotOdoDirectory = ".odo"

func AddOdoDirectory

func AddOdoDirectory(gitIgnoreFile string) error

AddOdoFileIndex adds odo-file-index.json to .gitignore

func CalculateFileDataKeyFromPath

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

func CaseInsensitive(parameter string) func(word string) bool

CaseInsensitive returns a function which compares two words caseinsensitively

func CheckPathExists

func CheckPathExists(fsys filesystem.Filesystem, path string) bool

CheckPathExists checks if a path exists or not TODO(feloy) use from devfile library?

func CleanDefaultHTTPCacheDir

func CleanDefaultHTTPCacheDir() error

CleanDefaultHTTPCacheDir cleans the default directory used for HTTP caching

func ConvertLabelsToSelector

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

func CopyDirWithFS(src string, dst string, fs filesystem.Filesystem) error

CopyDirWithFS copies a whole directory recursively

func CreateIfNotExists

func CreateIfNotExists(configFile string) error

CreateIfNotExists creates the directory and the file if it doesn't exist

func DeleteConfiguration

func DeleteConfiguration(info interface{}, parameter string) error

DeleteConfiguration sets a parameter to null in a struct using reflection

func DeleteIndexFile

func DeleteIndexFile(directory string) error

DeleteIndexFile deletes the index file. It doesn't throw error if it doesn't exist

func DisplayLog

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

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

func DownloadFileInMemoryWithCache(params dfutil.HTTPRequestParams, cacheFor int) ([]byte, error)

DownloadFileInMemoryWithCache uses the url to download the file and return bytes

func GetAndExtractZip

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

func GetBool(b bool) *bool

Bool returns pointer to passed boolean

func GetCommandStringFromEnvs

func GetCommandStringFromEnvs(envVars []v1alpha2.EnvVar) string

GetCommandStringFromEnvs creates a string from the given environment variables

func GetDNS1123Name

func GetDNS1123Name(str string) string

GetDNS1123Name Converts passed string into DNS-1123 string TODO(feloy) sync with devfile library?

func GetDataFromURI

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

func GetFromFile(c interface{}, filename string) error

GetFromFile unmarshals a struct from a odo config file

func GetGitOriginPath

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

func GetIndexFileRelativeToContext() string

GetIndexFileRelativeToContext returns the index file relative to context i.e.; .odo/odo-file-index.json

func GetLowerCaseParameters

func GetLowerCaseParameters(parameters []string) map[string]bool

GetLowerCaseParameters creates a set-like map of supported parameters from the supported parameter names

func GitSubDir

func GitSubDir(srcPath, destinationPath, subDir string) error

GitSubDir handles subDir for git components using the default filesystem

func IsPortFree

func IsPortFree(port int, localAddress string) bool

IsPortFree checks if the port on a given address is free to use

func IsSet

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

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

func NamespaceKubernetesObject(componentName string, applicationName string) (string, error)

NamespaceKubernetesObject hyphenates applicationName and componentName

func NamespaceKubernetesObjectWithTrim

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

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

func ResolveIndexFilePath(directory string) (string, error)

ResolveIndexFilePath resolves the filepath of the odo index file in the .odo folder

func SafeGetBool

func SafeGetBool(b *bool) bool

SafeGetBool returns the value of the bool pointer, or false if the pointer is nil

func StartSignalWatcher

func StartSignalWatcher(watchSignals []os.Signal, handle func(receivedSignal os.Signal))

StartSignalWatcher watches for signals and handles the situation before exiting the program

func TouchGitIgnoreFile

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

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

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

func ValidateURL(sourceURL string) error

ValidateURL validates the URL TODO(feloy) sync with devfile library?

func WriteFile

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

func WriteToJSONFile(c interface{}, filename string) error

WriteToJSONFile writes a struct to json file

func WriteToYAMLFile

func WriteToYAMLFile(c interface{}, filename string) error

WriteToYAMLFile marshals a struct to a file

type ConcurrentTask

ConcurrentTask is a task to execute in a go-routine

type ConcurrentTask struct {
    ToRun func(errChannel chan error)
}

type ConcurrentTasks

ConcurrentTasks records tasks to be run concurrently with go-routines

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

func NewConcurrentTasks

func NewConcurrentTasks(taskNumber int) *ConcurrentTasks

NewConcurrentTasks creates a new ConcurrentTasks instance, dimensioned to accept at least the specified number of tasks

func (*ConcurrentTasks) Add

func (ct *ConcurrentTasks) Add(task ConcurrentTask)

Add adds the specified ConcurrentTask to the list of tasks to be run concurrently

func (*ConcurrentTasks) Run

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

type FileData struct {
    Size             int64
    LastModifiedDate time.Time
    RemoteAttribute  string `json:"RemoteAttribute,omitempty"`
}

func GenerateNewFileDataEntry

func GenerateNewFileDataEntry(absolutePath string, rootDirectory string) (string, *FileData, error)

GenerateNewFileDataEntry creates a new FileData entry for use by IndexerRet and/or FileIndex

type FileIndex

FileIndex holds the file index used for storing local file state change

type FileIndex struct {
    metav1.TypeMeta
    Files map[string]FileData
}

func NewFileIndex

func NewFileIndex() *FileIndex

NewFileIndex returns a fileIndex

func ReadFileIndex

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

type IndexerRet

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

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