1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/errors"
10
"gopkg.in/juju/charmrepo.v2-unstable"
13
// JujuMetadata holds Juju-specific information that will be provided
14
// to the charm store.
15
type JujuMetadata struct {
16
// ModelUUID identifies the Juju model to the charm store.
20
// IsZero indicates whether or not the metadata is the zero value.
21
func (meta JujuMetadata) IsZero() bool {
22
return meta.ModelUUID == ""
25
func (meta JujuMetadata) asAttrs() map[string]string {
26
return map[string]string{
27
"environment_uuid": meta.ModelUUID,
31
func (meta JujuMetadata) addToHeader(header http.Header) {
32
attrs := meta.asAttrs()
33
for k, v := range attrs {
34
header.Add(charmrepo.JujuMetadataHTTPHeader, k+"="+v)
38
type httpHeaderSetter interface {
39
// SetHTTPHeader sets custom HTTP headers that will be sent to thei
40
// charm store on each request.
41
SetHTTPHeader(header http.Header)
44
// setOnClient sets custom HTTP headers that will be sent to the charm
45
// store on each request.
46
func (meta JujuMetadata) setOnClient(client BaseClient) error {
47
setter, ok := client.(httpHeaderSetter)
49
return errors.NotValidf("charm store client (missing SetHTTPHeader method)")
52
header := make(http.Header)
53
meta.addToHeader(header)
54
setter.SetHTTPHeader(header)