github.com/go-chef/chef@v0.30.1/cookbook_artifacts_download.go (about) 1 package chef 2 3 import ( 4 "fmt" 5 "path" 6 ) 7 8 // DownloadTo downloads a cookbook artifact to the specified local directory on disk 9 func (c *CBAService) DownloadTo(name, id, localDir string) error { 10 11 cba, err := c.GetVersion(name, id) 12 if err != nil { 13 return err 14 } 15 16 debug("Downloading %s cookbook artifact with id %s\n", cba.Name, cba.Identifier) 17 18 cookbookService := CookbookService{client: c.client} 19 cookbookLongName := fmt.Sprintf("%v-%v", name, cba.Identifier[0:20]) 20 cookbookPath := path.Join(localDir, cookbookLongName) 21 22 downloadErrs := []error{ 23 cookbookService.downloadCookbookItems(cba.RootFiles, "root_files", cookbookPath), 24 cookbookService.downloadCookbookItems(cba.Files, "files", path.Join(cookbookPath, "files")), 25 cookbookService.downloadCookbookItems(cba.Templates, "templates", path.Join(cookbookPath, "templates")), 26 cookbookService.downloadCookbookItems(cba.Attributes, "attributes", path.Join(cookbookPath, "attributes")), 27 cookbookService.downloadCookbookItems(cba.Recipes, "recipes", path.Join(cookbookPath, "recipes")), 28 cookbookService.downloadCookbookItems(cba.Definitions, "definitions", path.Join(cookbookPath, "definitions")), 29 cookbookService.downloadCookbookItems(cba.Libraries, "libraries", path.Join(cookbookPath, "libraries")), 30 cookbookService.downloadCookbookItems(cba.Providers, "providers", path.Join(cookbookPath, "providers")), 31 cookbookService.downloadCookbookItems(cba.Resources, "resources", path.Join(cookbookPath, "resources")), 32 } 33 34 for _, err := range downloadErrs { 35 if err != nil { 36 return err 37 } 38 } 39 40 debug("Cookbook artifact downloaded to %s\n", cookbookPath) 41 return nil 42 }