Files
dokku/plugins/apps/apps.go
Jose Diaz-Gonzalez 1a052969dc feat: app filtering to commands listing or iterating over apps
This increases the time to list apps from .05s to .2s~.3s on the simplest check, but the increased time is worth it for actually verifyng access to an app (should that need arise).

We'll also want to add the same to app existence checks.
2022-02-26 00:37:54 -05:00

51 lines
1.1 KiB
Go

package apps
import (
"fmt"
"io/ioutil"
"strings"
"github.com/dokku/dokku/plugins/common"
)
var (
// DefaultProperties is a map of all valid network properties with corresponding default property values
DefaultProperties = map[string]string{
"deploy-source": "",
"deploy-source-metadata": "",
}
// GlobalProperties is a map of all valid global network properties
GlobalProperties = map[string]bool{
"deploy-source": true,
"deploy-source-metadata": true,
}
)
// DokkuApps returns a list of all local apps
func DokkuApps() ([]string, error) {
apps := []string{}
dokkuRoot := common.MustGetEnv("DOKKU_ROOT")
files, err := ioutil.ReadDir(dokkuRoot)
if err != nil {
return apps, fmt.Errorf("You haven't deployed any applications yet")
}
for _, f := range files {
appRoot := common.AppRoot(f.Name())
if !common.DirectoryExists(appRoot) {
continue
}
if strings.HasPrefix(f.Name(), ".") {
continue
}
apps = append(apps, f.Name())
}
if len(apps) == 0 {
return apps, fmt.Errorf("You haven't deployed any applications yet")
}
return filterApps(apps)
}