~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/charmrepo.v2-unstable/charmstore_going_away.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package charmrepo // import "gopkg.in/juju/charmrepo.v2-unstable"
 
5
 
 
6
// This file may go away once Juju stops using anything here.
 
7
 
 
8
import (
 
9
        "net/http"
 
10
 
 
11
        "gopkg.in/errgo.v1"
 
12
        "gopkg.in/juju/charm.v6-unstable"
 
13
 
 
14
        "gopkg.in/juju/charmrepo.v2-unstable/csclient"
 
15
        "gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
 
16
)
 
17
 
 
18
// URL returns the root endpoint URL of the charm store.
 
19
func (s *CharmStore) URL() string {
 
20
        return s.client.ServerURL()
 
21
}
 
22
 
 
23
// Latest returns the most current revision for each of the identified
 
24
// charms. The revision in the provided charm URLs is ignored.
 
25
func (s *CharmStore) Latest(curls ...*charm.URL) ([]CharmRevision, error) {
 
26
        results, err := s.client.Latest(curls)
 
27
        if err != nil {
 
28
                return nil, err
 
29
        }
 
30
 
 
31
        var responses []CharmRevision
 
32
        for i, result := range results {
 
33
                response := CharmRevision{
 
34
                        Revision: result.Revision,
 
35
                        Sha256:   result.Sha256,
 
36
                        Err:      result.Err,
 
37
                }
 
38
                if errgo.Cause(result.Err) == params.ErrNotFound {
 
39
                        curl := curls[i].WithRevision(-1)
 
40
                        response.Err = CharmNotFound(curl.String())
 
41
                }
 
42
                responses = append(responses, response)
 
43
        }
 
44
        return responses, nil
 
45
}
 
46
 
 
47
// WithTestMode returns a repository Interface where test mode is enabled,
 
48
// meaning charm store download stats are not increased when charms are
 
49
// retrieved.
 
50
func (s *CharmStore) WithTestMode() *CharmStore {
 
51
        newRepo := *s
 
52
        newRepo.client.DisableStats()
 
53
        return &newRepo
 
54
}
 
55
 
 
56
// JujuMetadataHTTPHeader is the HTTP header name used to send Juju metadata
 
57
// attributes to the charm store.
 
58
const JujuMetadataHTTPHeader = csclient.JujuMetadataHTTPHeader
 
59
 
 
60
// WithJujuAttrs returns a repository Interface with the Juju metadata
 
61
// attributes set.
 
62
func (s *CharmStore) WithJujuAttrs(attrs map[string]string) *CharmStore {
 
63
        newRepo := *s
 
64
        header := make(http.Header)
 
65
        for k, v := range attrs {
 
66
                header.Add(JujuMetadataHTTPHeader, k+"="+v)
 
67
        }
 
68
        newRepo.client.SetHTTPHeader(header)
 
69
        return &newRepo
 
70
}