-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildpack-management.go
89 lines (78 loc) · 2.33 KB
/
buildpack-management.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
"github.com/cloudfoundry/cli/plugin"
"github.com/davidehringer/cf-buildpack-management-plugin/buildpacks"
"os"
"strings"
)
type BuildpackManager struct{}
func (c *BuildpackManager) GetMetadata() plugin.PluginMetadata {
primaryUsage := "cf configure-buildpacks PATH_TO_YAML_CONFIG_FILE [-dryRun]"
secondaryUsage := ` The provided path for the configuration file can be an absolute or relative path to
a file. The file should have a map named "buildpacks" containing an array of buildpacks. The "filename"
values for each buildpack can be an absolute or relative path to a file.
Valid YAML file example:
---
buildpacks:
- name: java
position: 1
enabled: true
locked: false
filename: java-buildpack-offline-v3.0.zip
- name: ruby_buildpack
position: 2
enabled: true
locked: false
filename: ruby_buildpack-cached-v1.3.0.zip
`
flags := make(map[string]string)
flags["dryRun"] = "stop before making any changes"
return plugin.PluginMetadata{
Name: "buildpack-management",
Version: plugin.VersionType{
Major: 1,
Minor: 0,
Build: 0,
},
Commands: []plugin.Command{
{
Name: "configure-buildpacks",
HelpText: "Configures system buildpacks using a declarative configuration file.",
UsageDetails: plugin.Usage{
Usage: strings.Join([]string{primaryUsage, secondaryUsage}, "\n\n"),
Options: flags,
},
},
},
}
}
func main() {
plugin.Start(new(BuildpackManager))
}
func (c *BuildpackManager) Run(cliConnection plugin.CliConnection, args []string) {
if args[0] == "configure-buildpacks" {
if len(args) < 2 {
// TODO this is not so great validation. Make useful
fmt.Println("Incorrect Usage. \n\nPATH_TO_YAML_CONFIG_FILE is a required argument")
os.Exit(1)
}
manifestRepo := buildpacks.NewFilesystemBuildpackManifestRepo()
buildpackRepo := buildpacks.NewCliBuildpackRepository(cliConnection)
config, err := manifestRepo.ReadManifest(args[1])
if err != nil {
fmt.Printf("Invalid manifest file '%v': %v", args[1], err)
os.Exit(1)
}
service := buildpacks.NewCliBuildpackService(cliConnection, buildpackRepo)
service.ConfigureBuildpacks(config, dryRun(args))
}
}
func dryRun(args []string) (dryRun bool) {
for _, arg := range args {
if arg == "--dryRun" {
dryRun = true
}
}
return
}