forked from paketo-buildpacks/packit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension_config.go
98 lines (84 loc) · 3.96 KB
/
extension_config.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
90
91
92
93
94
95
96
97
98
package cargo
import (
"encoding/json"
"io"
"github.com/BurntSushi/toml"
)
type ExtensionConfig struct {
API string `toml:"api" json:"api,omitempty"`
Extension ConfigExtension `toml:"extension" json:"extension,omitempty"`
Metadata ConfigExtensionMetadata `toml:"metadata" json:"metadata,omitempty"`
}
type ConfigExtensionMetadata struct {
IncludeFiles []string `toml:"include-files" json:"include-files,omitempty"`
PrePackage string `toml:"pre-package" json:"pre-package,omitempty"`
DefaultVersions map[string]string `toml:"default-versions" json:"default-versions,omitempty"`
Dependencies []ConfigExtensionMetadataDependency `toml:"dependencies" json:"dependencies,omitempty"`
Configurations []ConfigExtensionMetadataConfiguration `toml:"configurations" json:"configurations,omitempty"`
}
type ConfigExtensionMetadataDependency struct {
Checksum string `toml:"checksum" json:"checksum,omitempty"`
ID string `toml:"id" json:"id,omitempty"`
Licenses []interface{} `toml:"licenses" json:"licenses,omitempty"`
Name string `toml:"name" json:"name,omitempty"`
SHA256 string `toml:"sha256" json:"sha256,omitempty"`
Source string `toml:"source" json:"source,omitempty"`
SourceChecksum string `toml:"source-checksum" json:"source-checksum,omitempty"`
SourceSHA256 string `toml:"source_sha256" json:"source_sha256,omitempty"`
Stacks []string `toml:"stacks" json:"stacks,omitempty"`
URI string `toml:"uri" json:"uri,omitempty"`
Version string `toml:"version" json:"version,omitempty"`
}
type ConfigExtensionMetadataConfiguration struct {
Default string `toml:"default" json:"default,omitempty"`
Launch bool `toml:"launch" json:"launch,omitempty"`
Description string `toml:"description" json:"description,omitempty"`
Build bool `toml:"build" json:"build,omitempty"`
Name string `toml:"name" json:"name,omitempty"`
}
type ConfigExtension struct {
ID string `toml:"id" json:"id,omitempty"`
Name string `toml:"name" json:"name,omitempty"`
Version string `toml:"version" json:"version,omitempty"`
Homepage string `toml:"homepage,omitempty" json:"homepage,omitempty"`
Description string `toml:"description,omitempty" json:"description,omitempty"`
Keywords []string `toml:"keywords,omitempty" json:"keywords,omitempty"`
Licenses []ConfigExtensionLicense `toml:"licenses,omitempty" json:"licenses,omitempty"`
SBOMFormats []string `toml:"sbom-formats,omitempty" json:"sbom-formats,omitempty"`
}
type ConfigExtensionLicense struct {
Type string `toml:"type" json:"type"`
URI string `toml:"uri" json:"uri"`
}
func EncodeExtensionConfig(writer io.Writer, extensionConfig ExtensionConfig) error {
content, err := json.Marshal(extensionConfig)
if err != nil {
return err
}
c := map[string]interface{}{}
err = json.Unmarshal(content, &c)
if err != nil {
return err
}
return toml.NewEncoder(writer).Encode(c)
}
func DecodeExtensionConfig(reader io.Reader, extensionConfig *ExtensionConfig) error {
var c map[string]interface{}
_, err := toml.NewDecoder(reader).Decode(&c)
if err != nil {
return err
}
content, err := json.Marshal(c)
if err != nil {
return err
}
return json.Unmarshal(content, extensionConfig)
}
func (cd ConfigExtensionMetadataDependency) HasStack(stack string) bool {
for _, s := range cd.Stacks {
if s == stack {
return true
}
}
return false
}