forked from paketo-buildpacks/packit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildpack.go
68 lines (53 loc) · 1.82 KB
/
buildpack.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
package postal
import (
"fmt"
"os"
"time"
"github.com/BurntSushi/toml"
)
// Dependency is a representation of a buildpack dependency.
type Dependency struct {
// DeprecationDate is the data upon which this dependency is considered deprecated.
DeprecationDate time.Time `toml:"deprecation_date"`
// ID is the identifier used to specify the dependency.
ID string `toml:"id"`
// Name is the human-readable name of the dependency.
Name string `toml:"name"`
// SHA256 is the hex-encoded SHA256 checksum of the built dependency.
SHA256 string `toml:"sha256"`
// Source is the uri location of the source-code representation of the dependency.
Source string `toml:"source"`
// SourceSHA256 is the hex-encoded SHA256 checksum of the source-code representation of the dependency.
SourceSHA256 string `toml:"source_sha256"`
// Stacks is a list of stacks for which the dependency is built.
Stacks []string `toml:"stacks"`
// URI is the uri location of the built dependency.
URI string `toml:"uri"`
// Version is the specific version of the dependency.
Version string `toml:"version"`
}
func parseBuildpack(path, name string) ([]Dependency, string, error) {
file, err := os.Open(path)
if err != nil {
return nil, "", fmt.Errorf("failed to parse buildpack.toml: %w", err)
}
var buildpack struct {
Metadata struct {
DefaultVersions map[string]string `toml:"default-versions"`
Dependencies []Dependency `toml:"dependencies"`
} `toml:"metadata"`
}
_, err = toml.DecodeReader(file, &buildpack)
if err != nil {
return nil, "", fmt.Errorf("failed to parse buildpack.toml: %w", err)
}
return buildpack.Metadata.Dependencies, buildpack.Metadata.DefaultVersions[name], nil
}
func stacksInclude(stacks []string, stack string) bool {
for _, s := range stacks {
if s == stack {
return true
}
}
return false
}