/
catalog.go
107 lines (90 loc) · 2.5 KB
/
catalog.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
99
100
101
102
103
104
105
106
107
package wfapi
import (
"fmt"
"github.com/ipfs/go-cid"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/node/bindnode"
"github.com/ipld/go-ipld-prime/schema"
_ "github.com/warptools/warpforge/pkg/testutil"
)
type CatalogLineage struct {
Name string
Metadata struct {
Keys []string
Values map[string]string
}
Releases []CatalogRelease
}
type CatalogMirrorsByWare struct {
Keys []WareID
Values map[WareID][]WarehouseAddr
}
type CatalogMirrorsByModule struct {
Keys []ModuleName
Values map[ModuleName]CatalogMirrorsByPacktype
}
type CatalogMirrorsByPacktype struct {
Keys []Packtype
Values map[Packtype][]WarehouseAddr
}
type CatalogMirrorsCapsule struct {
CatalogMirrors *CatalogMirrors
}
type CatalogMirrors struct {
ByWare *CatalogMirrorsByWare
ByModule *CatalogMirrorsByModule
}
type CatalogReleaseCID string
type Catalog struct {
Keys []ModuleName
Values map[ModuleName]CatalogModule
}
type CatalogModuleCapsule struct {
CatalogModule *CatalogModule
}
type CatalogModule struct {
Name ModuleName
Releases struct {
Keys []ReleaseName
Values map[ReleaseName]CatalogReleaseCID
}
Metadata struct {
Keys []string
Values map[string]string
}
}
type CatalogRelease struct {
ReleaseName ReleaseName
Items struct {
Keys []ItemLabel
Values map[ItemLabel]WareID
}
Metadata struct {
Keys []string
Values map[string]string
}
}
func (rel *CatalogRelease) Cid() CatalogReleaseCID {
// convert parsed release to node
nRelease := bindnode.Wrap(rel, TypeSystem.TypeByName("CatalogRelease"))
// compute CID of parsed release data
lsys := cidlink.DefaultLinkSystem()
lnk, errRaw := lsys.ComputeLink(cidlink.LinkPrototype{Prefix: cid.Prefix{
Version: 1, // Usually '1'.
Codec: 0x71, // 0x71 means "dag-cbor" -- See the multicodecs table: https://github.com/multiformats/multicodec/
MhType: 0x20, // 0x20 means "sha2-384" -- See the multicodecs table: https://github.com/multiformats/multicodec/
MhLength: 48, // sha2-384 hash has a 48-byte sum.
}}, nRelease.(schema.TypedNode).Representation())
if errRaw != nil {
// panic! this should never fail unless IPLD is broken
panic(fmt.Sprintf("Fatal IPLD Error: lsys.ComputeLink failed for CatalogRelease: %s", errRaw))
}
cid, errRaw := lnk.(cidlink.Link).StringOfBase('z')
if errRaw != nil {
panic(fmt.Sprintf("Fatal IPLD Error: failed to encode CID for CatalogRelease: %s", errRaw))
}
return CatalogReleaseCID(cid)
}
type ReplayCapsule struct {
Plot *Plot
}