github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/charmhub/transport/refresh.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package transport 5 6 import ( 7 "time" 8 ) 9 10 // RefreshRequest defines a typed request for making refresh queries, containing 11 // both a series of context and actions, this powerful setup should allow for 12 // making batch queries where possible. 13 type RefreshRequest struct { 14 // Context can be empty (for install and download for example), but has to 15 // be always present and hence the no omitempty. 16 Context []RefreshRequestContext `json:"context"` 17 Actions []RefreshRequestAction `json:"actions"` 18 Fields []string `json:"fields,omitempty"` 19 Metrics RequestMetrics `json:"metrics,omitempty"` 20 } 21 22 // RequestMetrics are a map of key value pairs of metrics for the controller 23 // and the model in the request. 24 type RequestMetrics map[string]map[string]string 25 26 // RefreshRequestContext can request a given context for making multiple 27 // requests to one given entity. 28 type RefreshRequestContext struct { 29 InstanceKey string `json:"instance-key"` 30 ID string `json:"id"` 31 32 Revision int `json:"revision"` 33 Base Base `json:"base,omitempty"` 34 TrackingChannel string `json:"tracking-channel,omitempty"` 35 RefreshedDate *time.Time `json:"refresh-date,omitempty"` 36 Metrics ContextMetrics `json:"metrics,omitempty"` 37 } 38 39 // ContextMetrics are a map of key value pairs of metrics for the specific 40 // charm/application in the context. 41 type ContextMetrics map[string]string 42 43 // RefreshRequestAction defines a action to perform against the Refresh API. 44 type RefreshRequestAction struct { 45 // Action can be install, download or refresh. 46 Action string `json:"action"` 47 // InstanceKey should be unique for every action, as results may not be 48 // ordered in the same way, so it is expected to use this to ensure 49 // completeness and ordering. 50 InstanceKey string `json:"instance-key"` 51 ID *string `json:"id,omitempty"` 52 Name *string `json:"name,omitempty"` 53 Channel *string `json:"channel,omitempty"` 54 Revision *int `json:"revision,omitempty"` 55 Base *Base `json:"base"` 56 ResourceRevisions []RefreshResourceRevision `json:"resource-revisions,omitempty"` 57 } 58 59 // RefreshResponses holds a series of typed RefreshResponse or a series of 60 // errors if the query performed failed for some reason. 61 type RefreshResponses struct { 62 Results []RefreshResponse `json:"results,omitempty"` 63 ErrorList APIErrors `json:"error-list,omitempty"` 64 } 65 66 // RefreshResponse defines a typed response for the refresh query. 67 type RefreshResponse struct { 68 Entity RefreshEntity `json:"charm"` // TODO: Pick up new naming of this. 69 EffectiveChannel string `json:"effective-channel"` 70 Error *APIError `json:"error,omitempty"` 71 ID string `json:"id"` 72 InstanceKey string `json:"instance-key"` 73 Name string `json:"name"` 74 Result string `json:"result"` 75 76 // Officially the released-at is ISO8601, but go's version of time.Time is 77 // both RFC3339 and ISO8601 (the latter makes the T optional). 78 ReleasedAt time.Time `json:"released-at"` 79 } 80 81 // RefreshEntity is a typed refresh entity. 82 // This can either be a charm or a bundle, the type of the refresh entity 83 // doesn't actually matter in this circumstance. 84 type RefreshEntity struct { 85 Type Type `json:"type"` 86 Download Download `json:"download"` 87 ID string `json:"id"` 88 License string `json:"license"` 89 Name string `json:"name"` 90 Publisher map[string]string `json:"publisher,omitempty"` 91 Resources []ResourceRevision `json:"resources"` 92 Bases []Base `json:"bases,omitempty"` 93 Revision int `json:"revision"` 94 Summary string `json:"summary"` 95 Version string `json:"version"` 96 CreatedAt time.Time `json:"created-at"` 97 98 // The minimum set of metadata required for deploying a charm. 99 MetadataYAML string `json:"metadata-yaml,omitempty"` 100 ConfigYAML string `json:"config-yaml,omitempty"` 101 } 102 103 // RefreshResourceRevision represents a resource name revision pair for 104 // install by revision. 105 type RefreshResourceRevision struct { 106 Name string `json:"name"` 107 Revision int `json:"revision"` 108 }