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