github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/core/charm/repository.go (about)

     1  // Copyright 2020 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package charm
     5  
     6  import (
     7  	"net/url"
     8  
     9  	"github.com/juju/charm/v12"
    10  	charmresource "github.com/juju/charm/v12/resource"
    11  )
    12  
    13  // Repository describes an API for querying charm/bundle information and
    14  // downloading them from a store.
    15  type Repository interface {
    16  	// GetDownloadURL returns a url from which a charm can be downloaded
    17  	// based on the given charm url and charm origin.  A charm origin
    18  	// updated with the ID and hash for the download is also returned.
    19  	GetDownloadURL(string, Origin) (*url.URL, Origin, error)
    20  
    21  	// DownloadCharm retrieves specified charm from the store and saves its
    22  	// contents to the specified path.
    23  	DownloadCharm(charmName string, requestedOrigin Origin, archivePath string) (CharmArchive, Origin, error)
    24  
    25  	// ResolveWithPreferredChannel verified that the charm with the requested
    26  	// channel exists.  If no channel is specified, the latests, most stable is
    27  	// used. It returns a charm URL which includes the most current revision,
    28  	// if none was provided, a charm origin, and a slice of series supported by
    29  	// this charm.
    30  	ResolveWithPreferredChannel(string, Origin) (*charm.URL, Origin, []Platform, error)
    31  
    32  	// GetEssentialMetadata resolves each provided MetadataRequest and
    33  	// returns back a slice with the results. The results include the
    34  	// minimum set of metadata that is required for deploying each charm.
    35  	GetEssentialMetadata(...MetadataRequest) ([]EssentialMetadata, error)
    36  
    37  	// ListResources returns a list of resources associated with a given charm.
    38  	ListResources(string, Origin) ([]charmresource.Resource, error)
    39  
    40  	// ResolveResources looks at the provided repository and backend (already
    41  	// downloaded) resources to determine which to use. Provided (uploaded) take
    42  	// precedence. If charmhub has a newer resource than the back end, use that.
    43  	ResolveResources(resources []charmresource.Resource, id CharmID) ([]charmresource.Resource, error)
    44  
    45  	// ResolveForDeploy does the same thing as ResolveWithPreferredChannel
    46  	// returning EssentialMetadata also. Resources are returned if a
    47  	// charm revision was not provided in the CharmID.
    48  	ResolveForDeploy(CharmID) (ResolvedDataForDeploy, error)
    49  }
    50  
    51  // RepositoryFactory is a factory for charm Repositories.
    52  type RepositoryFactory interface {
    53  	GetCharmRepository(src Source) (Repository, error)
    54  }
    55  
    56  // CharmArchive provides information about a downloaded charm archive.
    57  type CharmArchive interface {
    58  	charm.Charm
    59  
    60  	Version() string
    61  	LXDProfile() *charm.LXDProfile
    62  }
    63  
    64  // MetadataRequest encapsulates the arguments for a charm essential metadata
    65  // resolution request.
    66  type MetadataRequest struct {
    67  	CharmName string
    68  	Origin    Origin
    69  }
    70  
    71  // EssentialMetadata encapsulates the essential metadata required for deploying
    72  // a particular charm.
    73  type EssentialMetadata struct {
    74  	ResolvedOrigin Origin
    75  
    76  	Meta     *charm.Meta
    77  	Manifest *charm.Manifest
    78  	Config   *charm.Config
    79  }
    80  
    81  // CharmID encapsulates data for identifying a unique charm in a charm repository.
    82  type CharmID struct {
    83  	// URL is the url of the charm.
    84  	URL *charm.URL
    85  
    86  	// Origin holds the original source of a charm, including its channel.
    87  	Origin Origin
    88  
    89  	// Metadata is optional extra information about a particular model's
    90  	// "in-theatre" use of the charm.
    91  	Metadata map[string]string
    92  }
    93  
    94  // ResolvedDataForDeploy is the response data from ResolveForDeploy
    95  type ResolvedDataForDeploy struct {
    96  	URL *charm.URL
    97  
    98  	EssentialMetadata EssentialMetadata
    99  
   100  	// Resources is a map of resource names to their current repository revision
   101  	// based on the supplied origin
   102  	Resources map[string]charmresource.Resource
   103  }