github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/ddevapp/providers.go (about) 1 package ddevapp 2 3 import ( 4 "github.com/ddev/ddev/pkg/fileutil" 5 "github.com/ddev/ddev/pkg/nodeps" 6 "os" 7 "strings" 8 ) 9 10 // IsValidProvider is a helper function to determine if a provider value is valid, returning 11 // true if the supplied provider is valid and false otherwise. 12 func (app *DdevApp) IsValidProvider(provider string) (bool, error) { 13 pList, err := app.GetValidProviders() 14 if err != nil { 15 return false, err 16 } 17 return nodeps.ArrayContainsString(pList, provider), nil 18 } 19 20 // GetValidProviders is a helper function that returns a list of valid providers. 21 func (app *DdevApp) GetValidProviders() ([]string, error) { 22 pPath := app.GetConfigPath("providers") 23 providers := []string{} 24 if !fileutil.IsDirectory(pPath) { 25 return providers, nil 26 } 27 28 dirEntrySlice, err := os.ReadDir(pPath) 29 if err != nil { 30 return providers, err 31 } 32 for _, de := range dirEntrySlice { 33 if strings.HasSuffix(de.Name(), ".yaml") { 34 providers = append(providers, strings.TrimSuffix(de.Name(), ".yaml")) 35 } 36 } 37 return providers, nil 38 }