github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/service/client_config.go (about) 1 package service 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strings" 8 9 "github.com/evergreen-ci/evergreen" 10 "github.com/mongodb/grip" 11 "github.com/pkg/errors" 12 ) 13 14 // getClientConfig should be called once at startup and looks at the 15 // current environment and loads all currently available client 16 // binaries for use by the API server in presenting the settings page. 17 // 18 // If there are no built clients, this returns an empty config 19 // version, but does *not* error. 20 func getClientConfig(settings *evergreen.Settings) (*evergreen.ClientConfig, error) { 21 c := &evergreen.ClientConfig{} 22 c.LatestRevision = evergreen.ClientVersion 23 24 root := filepath.Join(evergreen.FindEvergreenHome(), evergreen.ClientDirectory) 25 26 if _, err := os.Stat(root); os.IsNotExist(err) { 27 grip.Warningf("client directory '%s' does not exist, creating empty "+ 28 "directory and continuing with caution", root) 29 grip.Error(os.MkdirAll(root, 0755)) 30 } 31 32 err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { 33 if err != nil { 34 return err 35 } 36 37 if info.IsDir() { 38 return nil 39 } 40 41 parts := strings.Split(path, string(filepath.Separator)) 42 buildInfo := strings.Split(parts[len(parts)-2], "_") 43 44 c.ClientBinaries = append(c.ClientBinaries, evergreen.ClientBinary{ 45 URL: fmt.Sprintf("%s/%s/%s", settings.Ui.Url, evergreen.ClientDirectory, 46 strings.Join(parts[len(parts)-2:], "/")), 47 OS: buildInfo[0], 48 Arch: buildInfo[1], 49 }) 50 51 return nil 52 }) 53 if err != nil { 54 return nil, errors.Wrap(err, "problem finding client binaries") 55 } 56 57 return c, nil 58 }