charmstore

package
v5.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2018 License: AGPL-3.0 Imports: 51 Imported by: 0

Documentation

Overview

This is the internal version of the charmstore package. It exposes details to the various API packages that we do not wish to expose to the world at large.

Index

Constants

View Source
const StatsGranularity = time.Minute

StatsGranularity holds the time granularity of statistics gathering. IncCounter(Async) calls within this duration may be aggregated.

Variables

View Source
var ErrPublishResourceMismatch = errgo.Newf("charm published with incorrect resources")
View Source
var (
	ErrTooManySessions = errgo.New("too many mongo sessions in use")
)

Functions

func EntityResolvedURL

func EntityResolvedURL(e *mongodoc.Entity) *router.ResolvedURL

EntityResolvedURL returns the ResolvedURL for the entity. It requires that the PromulgatedURL field has been filled out in the entity.

func EntityStatsKey

func EntityStatsKey(url *charm.URL, kind string) []string

EntityStatsKey returns a stats key for the given charm or bundle reference and the given kind. Entity stats keys are generated using the following schema:

kind:series:name:user:revision

where user can be empty (for promulgated charms/bundles) and revision is optional (e.g. when uploading an entity the revision is not specified). For instance, entities' stats can then be retrieved like the following:

  • kind:utopic:* -> all charms of a specific series;
  • kind:trusty:django:* -> all revisions and user variations of a charm;
  • kind:trusty:django::* -> all revisions of a promulgated charm;
  • kind:trusty:django::42 -> a specific promulgated charm;
  • kind:trusty:django:who:* -> all revisions of a user owned charm;
  • kind:trusty:django:who:42 -> a specific user owned charm;

The above also applies to bundles (where the series is "bundle").

func FieldSelector

func FieldSelector(fields ...string) map[string]int

FieldSelector returns a field selector that will select the given fields, or all fields if none are specified.

func IsKubernetesCharm added in v5.1.0

func IsKubernetesCharm(meta *charm.Meta) bool

func NewZipFile

func NewZipFile(f *zip.File) (mongodoc.ZipFile, error)

NewZipFile returns a new mongodoc zip file reference to the given zip file.

func ReaderAtSeeker

func ReaderAtSeeker(r io.ReadSeeker) io.ReaderAt

ReaderAtSeeker adapts r so that it can be used as a ReaderAt. Note that, contrary to the io.ReaderAt contract, it is not OK to use concurrently.

func ZipFileReader

func ZipFileReader(zipr io.ReadSeeker, f mongodoc.ZipFile) (io.Reader, error)

ZipFileReader returns a reader that will read content referred to by f within zipr, which should refer to the contents of a zip file,

Types

type APIHandlerParams added in v5.1.0

type APIHandlerParams struct {
	ServerParams

	// Pool contains the Pool from which Stores should be collected.
	Pool *Pool

	// IDMClient contains an IDMClient for use by the API handler.
	IDMClient *idmclient.Client

	// Path contains the absolute path within the server for the
	// handler.
	Path string
}

An APIHandlerParams contains the parameters provided when calling a NewAPIHandlerFunc.

type AggregatedCounts

type AggregatedCounts struct {
	LastDay, LastWeek, LastMonth, Total int64
}

AggregatedCounts contains counts for a statistic aggregated over the lastDay, lastWeek, lastMonth and all time.

type ArchiverTo

type ArchiverTo interface {
	ArchiveTo(io.Writer) error
}

ArchiverTo can be used to archive a charm or bundle's contents to a writer. It is implemented by *charm.CharmArchive and *charm.BundleArchive.

type Blob

type Blob struct {
	blobstore.ReadSeekCloser

	// Size holds the total size of the blob.
	Size int64

	// Hash holds the hash checksum of the blob.
	Hash string
}

Blob represents a blob of data from the charm store.

type Counter

type Counter struct {
	Key    []string
	Prefix bool
	Count  int64
	Time   time.Time
}

type CounterRequest

type CounterRequest struct {
	// Key and Prefix determine the counter keys to match.
	// If Prefix is false, Key must match exactly. Otherwise, counters
	// must begin with Key and have at least one more key token.
	Key    []string
	Prefix bool

	// If List is true, matching counters are aggregated under their
	// prefixes instead of being returned as a single overall sum.
	//
	// For example, given the following counts:
	//
	//   {"a", "b"}: 1,
	//   {"a", "c"}: 3
	//   {"a", "c", "d"}: 5
	//   {"a", "c", "e"}: 7
	//
	// and assuming that Prefix is true, the following keys will
	// present the respective results if List is true:
	//
	//        {"a"} => {{"a", "b"}, 1, false},
	//                 {{"a", "c"}, 3, false},
	//                 {{"a", "c"}, 12, true}
	//   {"a", "c"} => {{"a", "c", "d"}, 3, false},
	//                 {{"a", "c", "e"}, 5, false}
	//
	// If List is false, the same key prefixes will present:
	//
	//        {"a"} => {{"a"}, 16, true}
	//   {"a", "c"} => {{"a", "c"}, 12, false}
	//
	List bool

	// By defines the period covered by each aggregated data point.
	// If unspecified, it defaults to ByAll, which aggregates all
	// matching data points in a single entry.
	By CounterRequestBy

	// Start, if provided, changes the query so that only data points
	// ocurring at the given time or afterwards are considered.
	Start time.Time

	// Stop, if provided, changes the query so that only data points
	// ocurring at the given time or before are considered.
	Stop time.Time
}

CounterRequest represents a request to aggregate counter values.

type CounterRequestBy

type CounterRequestBy int
const (
	ByAll CounterRequestBy = iota
	ByDay
	ByWeek
)

type HTTPCloseHandler

type HTTPCloseHandler interface {
	Close()
	http.Handler
}

HTTPCloseHandler represents a HTTP handler that must be closed after use.

type ListQuery

type ListQuery struct {
	// contains filtered or unexported fields
}

ListQuery holds a list query from which an iterator can be created.

func (*ListQuery) Iter

func (lq *ListQuery) Iter(fields map[string]int) *mgo.Iter

type ListResult

type ListResult struct {
	Results []*mongodoc.Entity
}

ListResult represents the result of performing a list.

type NewAPIHandlerFunc

type NewAPIHandlerFunc func(APIHandlerParams) (HTTPCloseHandler, error)

NewAPIHandlerFunc is a function that returns a new API handler that uses the given Store. The absPath parameter holds the root path of the API handler.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool holds a connection to the underlying charm and blob data stores. Calling its Store method returns a new Store from the pool that can be used to process short-lived requests to access and modify the store.

func NewPool

func NewPool(db *mgo.Database, si *SearchIndex, bakeryParams *bakery.NewServiceParams, config ServerParams) (*Pool, error)

NewPool returns a Pool that uses the given database and search index. If bakeryParams is not nil, the Bakery field in the resulting Store will be set to a new Service that stores macaroons in mongo.

The pool must be closed (with the Close method) after use.

func (*Pool) Close

func (p *Pool) Close()

Close closes the pool. This must be called when the pool is finished with.

func (*Pool) RequestStore

func (p *Pool) RequestStore() (*Store, error)

RequestStore returns a store for a client request. It returns an error with a ErrTooManySessions cause if too many mongo sessions are in use.

func (*Pool) Store

func (p *Pool) Store() *Store

Store returns a Store that can be used to access the database.

It must be closed (with the Close method) after use.

type SearchDoc

type SearchDoc struct {
	*mongodoc.Entity
	TotalDownloads int64
	ReadACLs       []string
	Series         []string

	// SingleSeries is true if the document referes to an entity that
	// describes a single series. This will either be a bundle, a
	// single-series charm or an expanded record for a multi-series
	// charm.
	SingleSeries bool

	// AllSeries is true if the document referes to an entity that
	// describes all series supported by the entity. This will either
	// be a bundle, a single-series charm or the canonical record for
	// a multi-series charm.
	AllSeries bool
}

SearchDoc is a mongodoc.Entity with additional fields useful for searching. This is the document that is stored in the search index.

type SearchIndex

type SearchIndex struct {
	*elasticsearch.Database
	Index string
}

func (*SearchIndex) GetSearchDocument

func (si *SearchIndex) GetSearchDocument(id *charm.URL) (*SearchDoc, error)

GetSearchDocument retrieves the current search record for the charm reference id.

type SearchParams

type SearchParams struct {
	// The text to use in the full text search query.
	Text string
	// If autocomplete is specified, the search will return only charms and
	// bundles with a name that has text as a prefix.
	AutoComplete bool
	// Limit the search to items with attributes that match the specified filter value.
	Filters map[string][]string
	// Limit the number of returned items to the specified count.
	Limit int
	// Include the following metadata items in the search results.
	Include []string
	// Start the the returned items at a specific offset.
	Skip int
	// ACL values to search in addition to everyone. ACL values may represent user names
	// or group names.
	Groups []string
	// Admin searches will not filter on the ACL and will show results for all matching
	// charms.
	Admin bool
	// Sort the returned items.
	Sort []SortParam
	// ExpandedMultiSeries returns a number of entries for
	// multi-series charms, one for each entity.
	ExpandedMultiSeries bool
}

SearchParams represents the search parameters used to search the store.

func (*SearchParams) ParseSortFields

func (sp *SearchParams) ParseSortFields(f ...string) error

type SearchResult

type SearchResult struct {
	SearchTime time.Duration
	Total      int
	Results    []*mongodoc.Entity
}

SearchResult represents the result of performing a search. The entites in Results will have the following fields completed:

  • URL
  • SupportedSeries
  • PromulgatedURL
  • PromulgatedRevision

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(db *mgo.Database, si *SearchIndex, config ServerParams, versions map[string]NewAPIHandlerFunc) (*Server, error)

NewServer returns a handler that serves the given charm store API versions using db to store that charm store data. An optional elasticsearch configuration can be specified in si. If elasticsearch is not being used then si can be set to nil. The key of the versions map is the version name. The handler configuration is provided to all version handlers.

The returned Server should be closed after use.

func (*Server) Close

func (s *Server) Close()

Close closes the server. It must be called when the server is finished with.

func (*Server) Pool

func (s *Server) Pool() *Pool

Pool returns the Pool used by the server.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler.ServeHTTP.

type ServerParams

type ServerParams struct {
	// AuthUsername and AuthPassword hold the credentials
	// used for HTTP basic authentication.
	AuthUsername string
	AuthPassword string

	// IdentityLocation holds the location of the third party authorization
	// service to use when creating third party caveats,
	// for example: http://api.jujucharms.com/identity
	IdentityLocation string

	// TermsLocations holds the location of the
	// terms service, which knows about user agreements to
	// Terms and Conditions required by the charm.
	TermsLocation string

	// PublicKeyLocator holds a public key store.
	// It may be nil.
	PublicKeyLocator bakery.PublicKeyLocator

	// AgentUsername and AgentKey hold the credentials used for agent
	// authentication.
	AgentUsername string
	AgentKey      *bakery.KeyPair

	// StatsCacheMaxAge is the maximum length of time between
	// refreshes of entities in the stats cache.
	StatsCacheMaxAge time.Duration

	// SearchCacheMaxAge is the maximum length of time between
	// refreshes of entities in the search cache.
	SearchCacheMaxAge time.Duration

	// MaxMgoSessions specifies a soft limit on the maximum
	// number of mongo sessions used. Each concurrent
	// HTTP request will use one session.
	MaxMgoSessions int

	// HTTPRequestWaitDuration holds the amount of time
	// that an HTTP request will wait for a free connection
	// when the MaxConcurrentHTTPRequests limit is reached.
	HTTPRequestWaitDuration time.Duration

	// AuditLogger optionally holds the logger which will be used to
	// write audit log entries.
	AuditLogger *lumberjack.Logger

	// RootKeyPolicy holds the default policy used when creating
	// macaroon root keys.
	RootKeyPolicy mgostorage.Policy

	// MinUploadPartSize holds the minimum size of
	// an upload part. If it's zero, a default value will be used.
	MinUploadPartSize int64

	// MaxUploadPartSize holds the maximum size of
	// an upload part. If it's zero, a default value will be used.
	MaxUploadPartSize int64

	// MaxUploadParts holds the maximum number of upload
	// parts that can be uploaded in a single upload.
	// If it's zero, a default value will be used.
	MaxUploadParts int

	// RunBlobStoreGC holds whether the server will run
	// the blobstore garbage collector worker.
	RunBlobStoreGC bool

	// NewBlobBackend returns a new blobstore backend
	// that may use the given MongoDB database.
	// If this is nil, a MongoDB backend will be used.
	NewBlobBackend func(db *mgo.Database) blobstore.Backend

	// DockerRegistryAddress contains the address of the docker
	// registry associated with the charmstore.
	DockerRegistryAddress string

	// DockerRegistryAuthCertificates contains the chain of
	// certificates used to validate the DockerRegistryAuthKey.
	DockerRegistryAuthCertificates []*x509.Certificate

	// DockerRegistryAuthKey contains the key to use to sign
	// docker registry authorization tokens.
	DockerRegistryAuthKey crypto.Signer

	// DockerRegistryTokenDuration is the time a docker registry
	// token will be valid for after it is created.
	DockerRegistryTokenDuration time.Duration
}

ServerParams holds configuration for a new internal API server.

type SortParam

type SortParam struct {
	Field      string
	Descending bool
}

SortParam represents a field and direction on which results should be sorted.

type Store

type Store struct {
	DB        StoreDatabase
	BlobStore *blobstore.Store
	ES        *SearchIndex
	Bakery    *bakery.Service
	// contains filtered or unexported fields
}

Store holds a connection to the underlying charm and blob data stores that is appropriate for short term use.

func (*Store) AddAudit

func (s *Store) AddAudit(entry audit.Entry)

AddAudit adds the given entry to the audit log.

func (*Store) AddBundleWithArchive

func (s *Store) AddBundleWithArchive(url *router.ResolvedURL, b charm.Bundle) error

AddBundleWithArchive adds the given bundle, which must be either a *charm.BundleDir or implement ArchiverTo, to the charmstore under the given URL.

This method is provided for testing purposes only.

func (*Store) AddCharmWithArchive

func (s *Store) AddCharmWithArchive(url *router.ResolvedURL, ch charm.Charm) error

AddCharmWithArchive adds the given charm, which must be either a *charm.CharmDir or implement ArchiverTo, to the charmstore under the given URL.

This method is provided for testing purposes only.

func (*Store) AddDockerResource added in v5.1.0

func (s *Store) AddDockerResource(id *router.ResolvedURL, resourceName, imageName, digest string) (*mongodoc.Resource, error)

AddDockerResource adds a docker resource to the Kubernetes charm with the given id. The image name should be non-empty only if the image is held outside the charm store's associated registry. The digest holds the hash of the image, in "sha256:abcdabcd" format.

func (*Store) AddEntityWithArchive

func (s *Store) AddEntityWithArchive(url *router.ResolvedURL, archive interface{}) error

AddEntityWithArchive provides the implementation for both AddCharmWithArchive and AddBundleWithArchive. It accepts charm.Charm or charm.Bundle implementations defined in the charm package, and any that implement ArchiverTo.

func (*Store) AddLog

func (s *Store) AddLog(data *json.RawMessage, logLevel mongodoc.LogLevel, logType mongodoc.LogType, urls []*charm.URL) error

AddLog adds a log message to the database.

func (*Store) AddResourceWithUploadId

func (s *Store) AddResourceWithUploadId(id *router.ResolvedURL, name string, uploadId string) (*mongodoc.Resource, error)

AddResourceWithUploadId is like UploadResource except that it associates the resource with an already-uploaded multipart upload.

func (*Store) AddRevision

func (s *Store) AddRevision(id *router.ResolvedURL) error

AddRevision records a new revision of the given id, meaning that any subequent NewRevision call for the id will return a higher revision number.

func (*Store) ArchiveDownloadCounts

func (s *Store) ArchiveDownloadCounts(id *charm.URL, refresh bool) (thisRevision, allRevisions AggregatedCounts, err error)

ArchiveDownloadCounts calculates the aggregated download counts for a charm or bundle.

func (*Store) BakeryWithPolicy

func (s *Store) BakeryWithPolicy(policy mgostorage.Policy) *bakery.Service

BakeryWithPolicy returns a copy of the Store's Bakery with a macaroon storage that returns root keys conforming to the given policy.

If there is no configured bakery, it returns nil.

func (*Store) BlobStoreGC

func (s *Store) BlobStoreGC(before time.Time) error

BlobStoreGC runs the blobstore garbage collector, deleting all blobs that have not been referenced since the given time.

func (*Store) Close

func (s *Store) Close()

Close closes the store instance.

func (*Store) Copy

func (s *Store) Copy() *Store

Copy returns a new store with a lifetime independent of s. Use this method if you need to use a store in an independent goroutine.

It must be closed (with the Close method) after use.

func (*Store) Counters

func (s *Store) Counters(req *CounterRequest) ([]Counter, error)

Counters aggregates and returns counter values according to the provided request.

func (*Store) DeleteEntity

func (s *Store) DeleteEntity(id *router.ResolvedURL) error

DeleteEntity deletes the entity with the given id from the store. If the entity is the current published revision for any channel or the last revision with the same base entity, it returns an error with an ErrForbidden cause.

func (*Store) EntitiesQuery

func (s *Store) EntitiesQuery(url *charm.URL) *mgo.Query

EntitiesQuery creates a mgo.Query object that can be used to find entities matching the given URL. If the given URL has no user then the produced query will only match promulgated entities.

func (*Store) FindBaseEntity

func (s *Store) FindBaseEntity(url *charm.URL, fields map[string]int) (*mongodoc.BaseEntity, error)

FindBaseEntity finds the base entity in the store using the given URL, which can either represent a fully qualified entity or a base id. If fields is not nil, only those fields will be populated in the returned base entity.

func (*Store) FindBestEntity

func (s *Store) FindBestEntity(url *charm.URL, channel params.Channel, fields map[string]int) (*mongodoc.Entity, error)

FindBestEntity finds the entity that provides the preferred match to the given URL, on the given channel. If the given URL has no user then only promulgated entities will be queried. If fields is not nil, only those fields will be populated in the returned entities.

If the URL contains a revision then it is assumed to be fully formed and refer to a single entity; the channel is ignored.

If the URL does not contain a revision then the channel is searched for the best match, here NoChannel will be treated as params.StableChannel.

func (*Store) FindEntities

func (s *Store) FindEntities(url *charm.URL, fields map[string]int) ([]*mongodoc.Entity, error)

FindEntities finds all entities in the store matching the given URL. If the given URL has no user then only promulgated entities will be queried. If the given URL channel does not represent an entity under development then only published entities will be queried. If fields is not nil, only its fields will be populated in the returned entities.

func (*Store) FindEntity

func (s *Store) FindEntity(url *router.ResolvedURL, fields map[string]int) (*mongodoc.Entity, error)

FindEntity finds the entity in the store with the given URL, which must be fully qualified. If the given URL has no user then it is assumed to be a promulgated entity. If fields is not nil, only its fields will be populated in the returned entities.

func (*Store) Go

func (s *Store) Go(f func(*Store))

Go runs the given function in a new goroutine, passing it a copy of s, which will be closed after the function returns.

func (*Store) IncCounter

func (s *Store) IncCounter(key []string) error

IncCounter increases by one the counter associated with the composed key.

func (*Store) IncCounterAsync

func (s *Store) IncCounterAsync(key []string)

IncCounterAsync increases by one the counter associated with the composed key. The action is done in the background using a separate goroutine.

func (*Store) IncCounterAtTime

func (s *Store) IncCounterAtTime(key []string, t time.Time) error

IncCounterAtTime increases by one the counter associated with the composed key, associating it with the given time.

func (*Store) IncrementDownloadCounts

func (s *Store) IncrementDownloadCounts(id *router.ResolvedURL) error

IncrementDownloadCounts updates the download statistics for entity id in both the statistics database and the search database.

func (*Store) IncrementDownloadCountsAsync

func (s *Store) IncrementDownloadCountsAsync(id *router.ResolvedURL)

IncrementDownloadCountsAsync updates the download statistics for entity id in both the statistics database and the search database. The action is done in the background using a separate goroutine.

func (*Store) IncrementDownloadCountsAtTime

func (s *Store) IncrementDownloadCountsAtTime(id *router.ResolvedURL, t time.Time) error

IncrementDownloadCountsAtTime updates the download statistics for entity id in both the statistics database and the search database, associating it with the given time.

func (*Store) ListQuery

func (store *Store) ListQuery(sp SearchParams) (*ListQuery, error)

ListQuery lists entities in the store that conform to the given search parameters. It returns a ListQuery that can be used to iterate through the list.

Sort criteria in the search parameters are ignored - the results are returned in arbitrary order.

func (*Store) ListResources

func (s *Store) ListResources(id *router.ResolvedURL, channel params.Channel) ([]*mongodoc.Resource, error)

ListResources returns the set of resources for the entity with the given id. If the unpublished channel is specified then set is composed of the latest revision for each resource. Otherwise it holds the revisions declared when the charm/channel pair was published.

func (*Store) MatchingInterfacesQuery

func (s *Store) MatchingInterfacesQuery(required, provided []string) *mgo.Query

MatchingInterfacesQuery returns a mongo query that will find any charms that require any interfaces in the required slice or provide any interfaces in the provided slice.

func (*Store) NewRevision

func (s *Store) NewRevision(id *charm.URL) (int, error)

NewRevision returns a new revision number for the given entity URL.

func (*Store) OpenBlob

func (s *Store) OpenBlob(id *router.ResolvedURL) (*Blob, error)

OpenBlob returns the blob associated with the given URL.

func (*Store) OpenBlobFile

func (s *Store) OpenBlobFile(blob *Blob, filePath string) (io.ReadCloser, int64, error)

OpenBlobFile opens the file with the given path from the given blob and returns a reader for its contents, and its size.

If no such file was found, it returns an error with a params.ErrNotFound cause.

If the file is actually a directory in the blob, it returns an error with a params.ErrForbidden cause.

func (*Store) OpenBlobPreV5

func (s *Store) OpenBlobPreV5(id *router.ResolvedURL) (*Blob, error)

OpenBlob returns the blob associated with the given URL. As required by pre-v5 versions of the API, it will return a blob with a hacked-up metadata.yaml that elides the Series field.

func (*Store) OpenCachedBlobFile

func (s *Store) OpenCachedBlobFile(
	entity *mongodoc.Entity,
	fileId mongodoc.FileId,
	isFile func(f *zip.File) bool,
) (_ io.ReadCloser, err error)

OpenCachedBlobFile opens a file from the given entity's archive blob. The file is identified by the provided fileId. If the file has not previously been opened on this entity, the isFile function will be used to determine which file in the zip file to use. The result will be cached for the next time.

When retrieving the entity, at least the BlobHash and Contents fields must be populated.

func (*Store) OpenResourceBlob

func (s *Store) OpenResourceBlob(res *mongodoc.Resource) (*Blob, error)

OpenResourceBlob returns the blob associated with the given resource.

func (*Store) Pool

func (s *Store) Pool() *Pool

Pool returns the pool that the store originally came from.

func (*Store) Publish

func (s *Store) Publish(url *router.ResolvedURL, resources map[string]int, channels ...params.Channel) error

Publish assigns channels to the entity corresponding to the given URL. An error is returned if no channels are provided. See params.ValidChannels for the list of supported channels. The unpublished channel cannot be provided.

If the given resources do not match those expected or they're not found, an error with a ErrPublichResourceMismatch cause will be returned.

func (*Store) ResolveResource

func (s *Store) ResolveResource(url *router.ResolvedURL, name string, revision int, channel params.Channel) (*mongodoc.Resource, error)

ResolveResource finds the resource specified. If a matching resource cannot be found an error with the cause params.ErrNotFound will be returned. If revision is negative, the most recently published revision for the given channel will be returned.

func (*Store) Search

func (store *Store) Search(sp SearchParams) (SearchResult, error)

Search searches the store for the given SearchParams. It returns a SearchResult containing the results of the search.

func (*Store) SetPerms

func (s *Store) SetPerms(id *charm.URL, which string, acl ...string) error

SetPerms sets the ACL specified by which for the base entity with the given id. The which parameter is in the form "channel.operation", where channel is the string corresponding to one of the ValidChannels and operation is one of "read" or "write". If which does not specify a channel then the unpublished ACL is updated. This is only provided for testing.

func (*Store) SetPromulgated

func (s *Store) SetPromulgated(url *router.ResolvedURL, promulgate bool) error

SetPromulgated sets whether the base entity of url is promulgated, If promulgated is true it also unsets promulgated on any other base entity for entities with the same name. It also calculates the next promulgated URL for the entities owned by the new owner and sets those entities appropriately.

Note: This code is known to have some unfortunate (but not dangerous) race conditions. It is possible that if one or more promulgations happens concurrently for the same entity name then it could result in more than one base entity being promulgated. If this happens then uploads to either user will get promulgated names, these names will never clash. This situation is easily remedied by setting the promulgated user for this charm again, even to one of the ones that is already promulgated. It can also result in the latest promulgated revision of the charm not being one created by the promulgated user. This will be remedied when a new charm is uploaded by the promulgated user. As promulgation is a rare operation, it is considered that the chances this will happen are slim.

func (*Store) SetReconnectTimeout

func (s *Store) SetReconnectTimeout(d time.Duration)

SetReconnectTimeout sets the length of time that mongo requests will block waiting to reconnect to a disconnected mongo server. If it is zero, requests may block forever.

func (*Store) SynchroniseElasticsearch

func (s *Store) SynchroniseElasticsearch() error

SynchroniseElasticsearch creates new indexes in elasticsearch and populates them with the current data from the mongodb database.

func (*Store) UpdateBaseEntity

func (s *Store) UpdateBaseEntity(url *router.ResolvedURL, update bson.D) error

UpdateBaseEntity applies the provided update to the base entity of url. If there are no entries in update then no update is performed, and no error is returned.

func (*Store) UpdateEntity

func (s *Store) UpdateEntity(url *router.ResolvedURL, update bson.D) error

UpdateEntity applies the provided update to the entity described by url. If there are no entries in update then no update is performed, and no error is returned.

func (*Store) UpdateSearch

func (s *Store) UpdateSearch(r *router.ResolvedURL) error

UpdateSearch updates the search record for the entity reference r. The search index only includes the latest stable revision of each entity so the latest stable revision of the charm specified by r will be indexed.

func (*Store) UpdateSearchAsync

func (s *Store) UpdateSearchAsync(r *router.ResolvedURL)

UpdateSearchAsync will update the search record for the entity reference r in the backgroud.

func (*Store) UpdateSearchBaseURL

func (s *Store) UpdateSearchBaseURL(baseURL *charm.URL) error

UpdateSearchBaseURL updates the search record for all entities with the specified base URL. It must be called whenever the entry for the given URL in the BaseEntitites collection has changed.

func (*Store) UploadEntity

func (s *Store) UploadEntity(url *router.ResolvedURL, blob io.Reader, blobHash string, size int64, chans []params.Channel) error

UploadEntity reads the given blob, which should have the given hash and size, and uploads it to the charm store, associating it with the given channels (without actually making it current in any of them).

The following error causes may be returned:

params.ErrDuplicateUpload if the URL duplicates an existing entity.
params.ErrEntityIdNotAllowed if the id may not be created.
params.ErrInvalidEntity if the provided blob is invalid.

func (*Store) UploadResource

func (s *Store) UploadResource(id *router.ResolvedURL, name string, blob io.Reader, blobHash string, size int64) (*mongodoc.Resource, error)

UploadResource add blob to the blob store and adds a new resource with the given name to the entity with the given id. The revision of the new resource will be calculated to be one higher than any existing resources.

TODO consider restricting uploads so that if the hash matches the latest revision then a new revision isn't created. This would match the behaviour for charms and bundles.

type StoreDatabase

type StoreDatabase struct {
	*mgo.Database
}

StoreDatabase wraps an mgo.DB ands adds a few convenience methods.

func (StoreDatabase) BaseEntities

func (s StoreDatabase) BaseEntities() *mgo.Collection

BaseEntities returns the mongo collection where base entities are stored.

func (StoreDatabase) Close

func (s StoreDatabase) Close()

Close closes the store database's underlying session.

func (StoreDatabase) Collections

func (s StoreDatabase) Collections() []*mgo.Collection

Collections returns a slice of all the collections used by the charm store.

func (StoreDatabase) Entities

func (s StoreDatabase) Entities() *mgo.Collection

Entities returns the mongo collection where entities are stored.

func (StoreDatabase) Logs

func (s StoreDatabase) Logs() *mgo.Collection

Logs returns the Mongo collection where charm store logs are stored.

func (StoreDatabase) Macaroons

func (s StoreDatabase) Macaroons() *mgo.Collection

func (StoreDatabase) Migrations

func (s StoreDatabase) Migrations() *mgo.Collection

Migrations returns the Mongo collection where the migration info is stored.

func (StoreDatabase) Resources

func (s StoreDatabase) Resources() *mgo.Collection

Resources returns the mongo collection where resources are stored.

func (StoreDatabase) Revisions

func (s StoreDatabase) Revisions() *mgo.Collection

Revisions holds the mongo collection where the latest revision numbers are stored.

func (StoreDatabase) StatCounters

func (s StoreDatabase) StatCounters() *mgo.Collection

func (StoreDatabase) StatTokens

func (s StoreDatabase) StatTokens() *mgo.Collection

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL