github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/charmhub/transport/common.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package transport 5 6 // The following contains all the common DTOs for a gathering information from 7 // a given store. 8 9 // Type represents the type of payload is expected from the API 10 type Type string 11 12 // Matches attempts to match a string to a given source. 13 func (t Type) Matches(o string) bool { 14 return string(t) == o 15 } 16 17 func (t Type) String() string { 18 return string(t) 19 } 20 21 const ( 22 // CharmType represents the charm payload. 23 CharmType Type = "charm" 24 // BundleType represents the bundle payload. 25 BundleType Type = "bundle" 26 ) 27 28 // Channel defines a unique permutation that corresponds to the track, risk 29 // and base. There can be multiple channels of the same track and risk, but 30 // with different bases. 31 type Channel struct { 32 Name string `json:"name"` 33 Base Base `json:"base"` 34 ReleasedAt string `json:"released-at"` 35 Risk string `json:"risk"` 36 Track string `json:"track"` 37 } 38 39 // Base is a typed tuple for identifying charms or bundles with a matching 40 // architecture, os and channel. 41 type Base struct { 42 Architecture string `json:"architecture"` 43 Name string `json:"name"` 44 Channel string `json:"channel"` 45 } 46 47 // Download represents the download structure from CharmHub. 48 // Elements not used by juju but not used are: "hash-sha3-384" 49 // and "hash-sha-512" 50 type Download struct { 51 HashSHA256 string `json:"hash-sha-256"` 52 HashSHA384 string `json:"hash-sha-384"` 53 Size int `json:"size"` 54 URL string `json:"url"` 55 } 56 57 // Entity holds the information about the charm or bundle, either contains the 58 // information about the charm or bundle or whom owns it. 59 type Entity struct { 60 Categories []Category `json:"categories"` 61 Charms []Charm `json:"contains-charms"` 62 Description string `json:"description"` 63 License string `json:"license"` 64 Publisher map[string]string `json:"publisher"` 65 Summary string `json:"summary"` 66 UsedBy []string `json:"used-by"` 67 StoreURL string `json:"store-url"` 68 } 69 70 // Category defines the category of a given charm or bundle. Akin to a tag. 71 type Category struct { 72 Featured bool `json:"featured"` 73 Name string `json:"name"` 74 } 75 76 // Charm is used to identify charms within a bundle. 77 type Charm struct { 78 Name string `json:"name"` 79 PackageID string `json:"package-id"` 80 StoreURL string `json:"store-url"` 81 }