github.com/juju/charmrepo/v7@v7.0.1/csclient/params/params.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the LGPLv3, see LICENCE file for details.
     3  
     4  // The params package holds types that are a part of the charm store's external
     5  // contract - they will be marshalled (or unmarshalled) as JSON
     6  // and delivered through the HTTP API.
     7  package params // import "github.com/juju/charmrepo/v7/csclient/params"
     8  
     9  import (
    10  	"encoding/json"
    11  	"time"
    12  
    13  	"github.com/juju/charm/v9"
    14  	"gopkg.in/macaroon.v2"
    15  )
    16  
    17  const (
    18  	// ContentHashHeader specifies the header attribute
    19  	// that will hold the content hash for archive GET responses.
    20  	ContentHashHeader = "Content-Sha384"
    21  
    22  	// EntityIdHeader specifies the header attribute that will hold the
    23  	// id of the entity for archive GET responses.
    24  	EntityIdHeader = "Entity-Id"
    25  )
    26  
    27  // Special user/group names.
    28  const (
    29  	Everyone = "everyone"
    30  	Admin    = "admin"
    31  )
    32  
    33  // Channel is the name of a channel in which an entity may be published.
    34  type Channel string
    35  
    36  const (
    37  	// EdgeChannel is the channel used for charms or bundles under development.
    38  	EdgeChannel Channel = "edge"
    39  
    40  	// BetaChannel is the channel used for beta charms or bundles.
    41  	BetaChannel Channel = "beta"
    42  
    43  	// CandidateChannel is the channel used for charms or bundles release
    44  	// candidates.
    45  	CandidateChannel Channel = "candidate"
    46  
    47  	// StableChannel is the channel used for stable charms or bundles.
    48  	StableChannel Channel = "stable"
    49  
    50  	// UnpublishedChannel is the default channel to which charms are uploaded.
    51  	UnpublishedChannel Channel = "unpublished"
    52  
    53  	// NoChannel represents where no channel has been specifically requested.
    54  	NoChannel Channel = ""
    55  
    56  	// DevelopmentChannel is only defined for backward compatibility.
    57  	DevelopmentChannel Channel = "development"
    58  )
    59  
    60  // OrderedChannels holds the list of valid channels in order of publishing
    61  // status, most stable first.
    62  var OrderedChannels = []Channel{
    63  	StableChannel,
    64  	CandidateChannel,
    65  	BetaChannel,
    66  	EdgeChannel,
    67  	UnpublishedChannel,
    68  }
    69  
    70  // ValidChannels holds the set of all allowed channels for an entity.
    71  var ValidChannels = func() map[Channel]bool {
    72  	channels := make(map[Channel]bool, len(OrderedChannels))
    73  	for _, ch := range OrderedChannels {
    74  		channels[ch] = true
    75  	}
    76  	return channels
    77  }()
    78  
    79  // MetaAnyResponse holds the result of a meta/any request.
    80  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetaany
    81  type MetaAnyResponse EntityResult
    82  
    83  // ArchiveUploadResponse holds the result of a post or a put to /id/archive.
    84  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#post-idarchive
    85  type ArchiveUploadResponse struct {
    86  	Id            *charm.URL
    87  	PromulgatedId *charm.URL `json:",omitempty"`
    88  }
    89  
    90  // Constants for the StatsUpdateRequest
    91  type StatsUpdateType string
    92  
    93  const (
    94  	UpdateDownload StatsUpdateType = "download" // Accesses with non listed clients and web browsers.
    95  	UpdateTraffic  StatsUpdateType = "traffic"  // Bots and unknown clients.
    96  	UpdateDeploy   StatsUpdateType = "deploy"   // known clients like juju client.
    97  )
    98  
    99  // StatsUpdateRequest holds the parameters for a put to /stats/update.
   100  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#stats-update
   101  type StatsUpdateRequest struct {
   102  	Entries []StatsUpdateEntry
   103  }
   104  
   105  // StatsUpdateEntry holds an entry of the StatsUpdateRequest for a put to /stats/update.
   106  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#stats-update
   107  type StatsUpdateEntry struct {
   108  	Timestamp      time.Time       // Time when the update did happen.
   109  	Type           StatsUpdateType // One of the constant Download, Traffic or Deploy.
   110  	CharmReference *charm.URL      // The charm to be updated.
   111  }
   112  
   113  // ExpandedId holds a charm or bundle fully qualified id.
   114  // A slice of ExpandedId is used as response for
   115  // id/expand-id GET requests.
   116  type ExpandedId struct {
   117  	Id string
   118  }
   119  
   120  // ArchiveSizeResponse holds the result of an
   121  // id/meta/archive-size GET request.
   122  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetaarchive-size
   123  type ArchiveSizeResponse struct {
   124  	Size int64
   125  }
   126  
   127  // HashResponse holds the result of id/meta/hash and id/meta/hash256 GET
   128  // requests.
   129  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetahash
   130  // and https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetahash256
   131  type HashResponse struct {
   132  	Sum string
   133  }
   134  
   135  // ManifestFile holds information about a charm or bundle file.
   136  // A slice of ManifestFile is used as response for
   137  // id/meta/manifest GET requests.
   138  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetamanifest
   139  type ManifestFile struct {
   140  	Name string
   141  	Size int64
   142  }
   143  
   144  // ArchiveUploadTimeResponse holds the result of an id/meta/archive-upload-time
   145  // GET request. See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetaarchive-upload-time
   146  type ArchiveUploadTimeResponse struct {
   147  	UploadTime time.Time
   148  }
   149  
   150  // RelatedResponse holds the result of an id/meta/charm-related GET request.
   151  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetacharm-related
   152  type RelatedResponse struct {
   153  	// Requires holds an entry for each interface provided by
   154  	// the charm, containing all charms that require that interface.
   155  	Requires map[string][]EntityResult `json:",omitempty"`
   156  
   157  	// Provides holds an entry for each interface required by the
   158  	// the charm, containing all charms that provide that interface.
   159  	Provides map[string][]EntityResult `json:",omitempty"`
   160  }
   161  
   162  // RevisionInfoResponse holds the result of an id/meta/revision-info GET
   163  // request. See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetarevision-info
   164  type RevisionInfoResponse struct {
   165  	Revisions []*charm.URL
   166  }
   167  
   168  // SupportedSeries holds the result of an id/meta/supported-series GET
   169  // request. See See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetasupported-series
   170  type SupportedSeriesResponse struct {
   171  	SupportedSeries []string
   172  }
   173  
   174  // BundleCount holds the result of an id/meta/bundle-unit-count
   175  // or bundle-machine-count GET request.
   176  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetabundle-unit-count
   177  // and https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetabundle-machine-count
   178  type BundleCount struct {
   179  	Count int
   180  }
   181  
   182  // TagsResponse holds the result of an id/meta/tags GET request.
   183  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetatags
   184  type TagsResponse struct {
   185  	Tags []string
   186  }
   187  
   188  // Published holds the result of a changes/published GET request.
   189  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-changespublished
   190  type Published struct {
   191  	Id          *charm.URL
   192  	PublishTime time.Time
   193  }
   194  
   195  // DebugStatus holds the result of the status checks.
   196  // This is defined for backward compatibility: new clients should use
   197  // debugstatus.CheckResult directly.
   198  type DebugStatus struct {
   199  	// Name is the human readable name for the check.
   200  	Name string
   201  
   202  	// Value is the check result.
   203  	Value string
   204  
   205  	// Passed reports whether the check passed.
   206  	Passed bool
   207  
   208  	// Duration holds the duration that the
   209  	// status check took to run.
   210  	Duration time.Duration
   211  }
   212  
   213  // EntityResult holds a the resolved entity ID along with any requested metadata.
   214  type EntityResult struct {
   215  	Id *charm.URL
   216  	// Meta holds at most one entry for each meta value
   217  	// specified in the include flags, holding the
   218  	// data that would be returned by reading /meta/meta?id=id.
   219  	// Metadata not relevant to a particular result will not
   220  	// be included.
   221  	Meta map[string]interface{} `json:",omitempty"`
   222  }
   223  
   224  // SearchResponse holds the response from a search operation.
   225  type SearchResponse struct {
   226  	SearchTime time.Duration
   227  	Total      int
   228  	Results    []EntityResult
   229  }
   230  
   231  // ListResponse holds the response from a list operation.
   232  type ListResponse struct {
   233  	Results []EntityResult
   234  }
   235  
   236  // IdUserResponse holds the result of an id/meta/id-user GET request.
   237  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetaid-user
   238  type IdUserResponse struct {
   239  	User string
   240  }
   241  
   242  // IdSeriesResponse holds the result of an id/meta/id-series GET request.
   243  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetaid-series
   244  type IdSeriesResponse struct {
   245  	Series string
   246  }
   247  
   248  // IdNameResponse holds the result of an id/meta/id-name GET request.
   249  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetaid-name
   250  type IdNameResponse struct {
   251  	Name string
   252  }
   253  
   254  // IdRevisionResponse holds the result of an id/meta/id-revision GET request.
   255  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetaid-revision
   256  type IdRevisionResponse struct {
   257  	Revision int
   258  }
   259  
   260  // IdResponse holds the result of an id/meta/id GET request.
   261  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetaid
   262  type IdResponse struct {
   263  	Id       *charm.URL
   264  	User     string `json:",omitempty"`
   265  	Series   string `json:",omitempty"`
   266  	Name     string
   267  	Revision int
   268  }
   269  
   270  // AllPermsResponse holds the resource of an id/allperms GET
   271  // request.
   272  type AllPermsResponse struct {
   273  	Perms map[Channel]PermResponse
   274  }
   275  
   276  // PermResponse holds the result of an id/meta/perm GET request.
   277  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetaperm
   278  type PermResponse struct {
   279  	Read  []string
   280  	Write []string
   281  }
   282  
   283  // PermRequest holds the request of an id/meta/perm PUT request.
   284  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#put-idmetaperm
   285  type PermRequest struct {
   286  	Read  []string
   287  	Write []string
   288  }
   289  
   290  // PromulgatedResponse holds the result of an id/meta/promulgated GET request.
   291  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetapromulgated
   292  type PromulgatedResponse struct {
   293  	Promulgated bool
   294  }
   295  
   296  // CanIngestResponse holds the result of an id/meta/can-ingest GET request.
   297  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetacan-ingest
   298  type CanIngestResponse struct {
   299  	CanIngest bool
   300  }
   301  
   302  // CanWriteResponse holds the result of an id/meta/can-write GET request.
   303  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-idmetacan-write
   304  type CanWriteResponse struct {
   305  	CanWrite bool
   306  }
   307  
   308  // PromulgateRequest holds the request of an id/promulgate PUT request.
   309  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#put-idpromulgate
   310  type PromulgateRequest struct {
   311  	Promulgated bool
   312  }
   313  
   314  // PublishRequest holds the request of an id/publish PUT request.
   315  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#put-idpublish
   316  type PublishRequest struct {
   317  	Channels []Channel
   318  	// Resources defines the resource revisions to use for the charm.
   319  	// Each resource in the charm's metadata.yaml (if any) must have its
   320  	// name mapped to a revision. That revision must be one of the
   321  	// existing revisions for that resource.
   322  	Resources map[string]int `json:",omitempty"`
   323  }
   324  
   325  // PublishResponse holds the result of an id/publish PUT request.
   326  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#put-idpublish
   327  type PublishResponse struct {
   328  	Id            *charm.URL
   329  	PromulgatedId *charm.URL `json:",omitempty"`
   330  }
   331  
   332  // PublishedResponse holds the result of an id/meta/published GET request.
   333  type PublishedResponse struct {
   334  	// Channels holds an entry for each channel that the
   335  	// entity has been published to.
   336  	Info []PublishedInfo
   337  }
   338  
   339  // PublishedInfo holds information on a channel that an entity
   340  // has been published to.
   341  type PublishedInfo struct {
   342  	// Channel holds the value of the channel that
   343  	// the entity has been published to.
   344  	// This will never be "unpublished" as entities
   345  	// cannot be published to that channel.
   346  	Channel Channel
   347  
   348  	// Current holds whether the entity is the most
   349  	// recently published member of the channel.
   350  	Current bool
   351  }
   352  
   353  // WhoAmIResponse holds the result of a whoami GET request.
   354  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#whoami
   355  type WhoAmIResponse struct {
   356  	User   string
   357  	Groups []string
   358  }
   359  
   360  // Resource describes a resource in the charm store.
   361  type Resource struct {
   362  	// Name identifies the resource.
   363  	Name string
   364  
   365  	// Type is the name of the resource type.
   366  	Type string
   367  
   368  	// Path is where the resource will be stored.
   369  	Path string
   370  
   371  	// Description contains user-facing info about the resource.
   372  	Description string `json:",omitempty"`
   373  
   374  	// Revision is the revision, if applicable.
   375  	Revision int
   376  
   377  	// Fingerprint is the SHA-384 checksum for the resource blob.
   378  	Fingerprint []byte
   379  
   380  	// Size is the size of the resource, in bytes.
   381  	Size int64
   382  }
   383  
   384  // ResourceUploadResponse holds the result of a post or a put to /id/resources/name.
   385  type ResourceUploadResponse struct {
   386  	Revision int
   387  }
   388  
   389  // DockerResourceUploadRequest holds the body of a POST to /:id/resources/:name
   390  // when the resource is a docker image.
   391  type DockerResourceUploadRequest struct {
   392  	// ImageName holds the image name when it's an external image not
   393  	// contained within the charm store's registry. If this is empty, the
   394  	// image should have been uploaded to the charm store's registry.
   395  	ImageName string
   396  	// Digest holds the digest of the image, in the form "sha256:hexbytes".
   397  	Digest string
   398  }
   399  
   400  // DockerInfoResponse holds the result of a get of /:id/resources/:name/docker-info
   401  type DockerInfoResponse struct {
   402  	// ImageName holds the image name (including host) of the resource in the docker registry.
   403  	ImageName string
   404  
   405  	// Username holds the username to use in the docker auth information.
   406  	// (see https://docs.docker.com/registry/spec/auth/token/#requesting-a-token).
   407  	Username string
   408  
   409  	// Password holds the password to use in the docker auth information.
   410  	Password string
   411  }
   412  
   413  // CharmRevision holds the revision number of a charm and any error
   414  // encountered in retrieving it.
   415  type CharmRevision struct {
   416  	Revision int
   417  	Sha256   string
   418  	Err      error
   419  }
   420  
   421  const (
   422  	// BzrDigestKey is the extra-info key used to store the Bazaar digest
   423  	BzrDigestKey = "bzr-digest"
   424  
   425  	// LegacyDownloadStats is the extra-info key used to store the legacy
   426  	// download counts, and to retrieve them when
   427  	// charmstore.LegacyDownloadCountsEnabled is set to true.
   428  	// TODO (frankban): remove this constant when removing the legacy counts
   429  	// logic.
   430  	LegacyDownloadStats = "legacy-download-stats"
   431  )
   432  
   433  // Log holds the representation of a log message.
   434  // This is used by clients to store log events in the charm store.
   435  type Log struct {
   436  	// Data holds the log message as a JSON-encoded value.
   437  	Data *json.RawMessage
   438  
   439  	// Level holds the log level as a string.
   440  	Level LogLevel
   441  
   442  	// Type holds the log type as a string.
   443  	Type LogType
   444  
   445  	// URLs holds a slice of entity URLs associated with the log message.
   446  	URLs []*charm.URL `json:",omitempty"`
   447  }
   448  
   449  // LogResponse represents a single log message and is used in the responses
   450  // to /log GET requests.
   451  // See https://github.com/juju/charmstore/blob/v5-unstable/docs/API.md#get-log
   452  type LogResponse struct {
   453  	// Data holds the log message as a JSON-encoded value.
   454  	Data json.RawMessage
   455  
   456  	// Level holds the log level as a string.
   457  	Level LogLevel
   458  
   459  	// Type holds the log type as a string.
   460  	Type LogType
   461  
   462  	// URLs holds a slice of entity URLs associated with the log message.
   463  	URLs []*charm.URL `json:",omitempty"`
   464  
   465  	// Time holds the time of the log.
   466  	Time time.Time
   467  }
   468  
   469  // LogLevel defines log levels (e.g. "info" or "error") to be used in log
   470  // requests and responses.
   471  type LogLevel string
   472  
   473  const (
   474  	InfoLevel    LogLevel = "info"
   475  	WarningLevel LogLevel = "warning"
   476  	ErrorLevel   LogLevel = "error"
   477  )
   478  
   479  // LogType defines log types (e.g. "ingestion") to be used in log requests and
   480  // responses.
   481  type LogType string
   482  
   483  const (
   484  	IngestionType        LogType = "ingestion"
   485  	LegacyStatisticsType LogType = "legacyStatistics"
   486  
   487  	IngestionStart    = "ingestion started"
   488  	IngestionComplete = "ingestion completed"
   489  
   490  	LegacyStatisticsImportStart    = "legacy statistics import started"
   491  	LegacyStatisticsImportComplete = "legacy statistics import completed"
   492  )
   493  
   494  // SetAuthCookie holds the parameters used to make a set-auth-cookie request
   495  // to the charm store.
   496  type SetAuthCookie struct {
   497  	// Macaroons holds a slice of macaroons.
   498  	Macaroons macaroon.Slice
   499  }
   500  
   501  // NewUploadResponse holds the response from a POST request to /upload.
   502  // TODO remove this when the charmstore code no longer requires it.
   503  type NewUploadResponse UploadInfoResponse
   504  
   505  // Parts holds a list of all the parts that are required by a multipart
   506  // upload, as required by a PUT request to /upload/$upload-id.
   507  type Parts struct {
   508  	Parts []Part
   509  }
   510  
   511  // Part represents one part of a multipart blob.
   512  // When a set of parts is returned from an upload
   513  // query GET, those with zero sizes should
   514  // be considered non-existent.
   515  type Part struct {
   516  	// Hash holds the SHA384 hash of the part.
   517  	Hash string `json:",omitempty"`
   518  	// Size holds the size of the part.
   519  	Size int64 `json:",omitempty"`
   520  	// Offset holds the offset of the part from the start
   521  	// of the file.
   522  	Offset int64 `json:",omitempty"`
   523  	// Complete holds whether the part has been
   524  	// successfully uploaded.
   525  	Complete bool `json:",omitempty"`
   526  }
   527  
   528  func (p Part) Valid() bool {
   529  	return p.Size > 0
   530  }
   531  
   532  // FinishUploadResponse holds the response to a put /upload/upload-id/part-number request.
   533  type FinishUploadResponse struct {
   534  	// Hash holds the SHA384 hash of the complete blob. (hex-encoded)
   535  	Hash string
   536  }
   537  
   538  // UploadInfoResponse holds the response to a get /upload/upload-id request.
   539  type UploadInfoResponse struct {
   540  	// UploadId holds the id of the upload.
   541  	UploadId string
   542  
   543  	// Parts holds all the known parts of the upload.
   544  	// Parts that haven't been uploaded yet will have nil
   545  	// elements.
   546  	Parts Parts
   547  
   548  	// Expires holds when the upload will expire.
   549  	Expires time.Time
   550  
   551  	// MinPartSize holds the minimum size of a part that may
   552  	// be uploaded (not including the last part).
   553  	MinPartSize int64
   554  
   555  	// MaxPartSize holds the maximum size of a part that may
   556  	// be uploaded.
   557  	MaxPartSize int64
   558  
   559  	// MaxParts holds the maximum number of parts.
   560  	MaxParts int
   561  }