@ -20,8 +20,10 @@ var APPS_JSON = path.Join(ABRA_DIR, "apps.json")
|
||||
var APPS_DIR = path.Join(ABRA_DIR, "apps")
|
||||
var REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud"
|
||||
|
||||
// GetServers retrieves all servers.
|
||||
func (a AppFiles) GetServers() []string {
|
||||
var unique []string
|
||||
|
||||
servers := make(map[string]struct{})
|
||||
for _, appFile := range a {
|
||||
if _, ok := servers[appFile.Server]; !ok {
|
||||
@ -29,33 +31,48 @@ func (a AppFiles) GetServers() []string {
|
||||
unique = append(unique, appFile.Server)
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved servers: '%s'", unique)
|
||||
|
||||
return unique
|
||||
}
|
||||
|
||||
// ReadEnv loads an app envivornment into a map.
|
||||
func ReadEnv(filePath string) (AppEnv, error) {
|
||||
var envFile AppEnv
|
||||
|
||||
envFile, err := godotenv.Read(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logrus.Debugf("read '%s' from '%s'", envFile, filePath)
|
||||
|
||||
return envFile, nil
|
||||
}
|
||||
|
||||
// ReadServerNames retrieves all server names.
|
||||
func ReadServerNames() ([]string, error) {
|
||||
serverNames, err := getAllFoldersInDirectory(ABRA_SERVER_FOLDER)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logrus.Debugf("read '%s' from '%s'", strings.Join(serverNames, ","), ABRA_SERVER_FOLDER)
|
||||
|
||||
return serverNames, nil
|
||||
}
|
||||
|
||||
// getAllFilesInDirectory returns filenames of all files in directory
|
||||
func getAllFilesInDirectory(directory string) ([]fs.FileInfo, error) {
|
||||
var realFiles []fs.FileInfo
|
||||
|
||||
files, err := ioutil.ReadDir(directory)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
// Follow any symlinks
|
||||
filePath := path.Join(directory, file.Name())
|
||||
@ -71,14 +88,15 @@ func getAllFilesInDirectory(directory string) ([]fs.FileInfo, error) {
|
||||
realFiles = append(realFiles, file)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return realFiles, nil
|
||||
}
|
||||
|
||||
// getAllFoldersInDirectory returns both folder and symlink paths
|
||||
func getAllFoldersInDirectory(directory string) ([]string, error) {
|
||||
var folders []string
|
||||
|
||||
files, err := ioutil.ReadDir(directory)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -86,6 +104,7 @@ func getAllFoldersInDirectory(directory string) ([]string, error) {
|
||||
if len(files) == 0 {
|
||||
return nil, fmt.Errorf("directory is empty: '%s'", directory)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
// Check if file is directory or symlink
|
||||
if file.IsDir() || file.Mode()&fs.ModeSymlink != 0 {
|
||||
@ -99,12 +118,14 @@ func getAllFoldersInDirectory(directory string) ([]string, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return folders, nil
|
||||
}
|
||||
|
||||
// EnsureAbraDirExists checks for the abra config folder and throws error if not
|
||||
func EnsureAbraDirExists() error {
|
||||
if _, err := os.Stat(ABRA_DIR); os.IsNotExist(err) {
|
||||
logrus.Debugf("'%s' does not exist, creating it", ABRA_DIR)
|
||||
if err := os.Mkdir(ABRA_DIR, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -112,6 +133,7 @@ func EnsureAbraDirExists() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReadAbraShEnvVars reads env vars from an abra.sh recipe file.
|
||||
func ReadAbraShEnvVars(abraSh string) (map[string]string, error) {
|
||||
envVars := make(map[string]string)
|
||||
|
||||
@ -137,5 +159,7 @@ func ReadAbraShEnvVars(abraSh string) (map[string]string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("read '%s' from '%s'", envVars, abraSh)
|
||||
|
||||
return envVars, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user