github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/resource/interfaces.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package resource 5 6 import ( 7 "context" 8 "io" 9 "net/url" 10 11 charmresource "github.com/juju/charm/v12/resource" 12 13 "github.com/juju/juju/charmhub" 14 "github.com/juju/juju/charmhub/transport" 15 "github.com/juju/juju/core/resources" 16 "github.com/juju/juju/state" 17 ) 18 19 // Resources represents the methods used by the resource opener from state.Resources. 20 type Resources interface { 21 // GetResource returns the identified resource. 22 GetResource(applicationID, name string) (resources.Resource, error) 23 // OpenResource returns the metadata for a resource and a reader for the resource. 24 OpenResource(applicationID, name string) (resources.Resource, io.ReadCloser, error) 25 // OpenResourceForUniter returns the metadata for a resource and a reader for the resource. 26 OpenResourceForUniter(unitName, resName string) (resources.Resource, io.ReadCloser, error) 27 // SetResource adds the resource to blob storage and updates the metadata. 28 SetResource(applicationID, userID string, res charmresource.Resource, r io.Reader, _ state.IncrementCharmModifiedVersionType) (resources.Resource, error) 29 } 30 31 // ResourceGetter provides the functionality for getting a resource file. 32 type ResourceGetter interface { 33 // GetResource returns a reader for the resource's data. That data 34 // is streamed from the charm store. The charm's revision, if any, 35 // is ignored. If the identified resource is not in the charm store 36 // then errors.NotFound is returned. 37 // 38 // But if you write any code that assumes a NotFound error returned 39 // from this method means that the resource was not found, you fail 40 // basic logic. 41 GetResource(ResourceRequest) (ResourceData, error) 42 } 43 44 // CharmHub represents methods required from a charmhub client talking to the 45 // charmhub api used by the local CharmHubClient 46 type CharmHub interface { 47 DownloadResource(ctx context.Context, resourceURL *url.URL) (r io.ReadCloser, err error) 48 Refresh(ctx context.Context, config charmhub.RefreshConfig) ([]transport.RefreshResponse, error) 49 } 50 51 type Logger interface { 52 Tracef(string, ...interface{}) 53 }