~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/names.v2/cloudcredential.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import (
7
7
        "fmt"
 
8
        "net/url"
8
9
        "regexp"
9
10
        "strings"
10
11
)
12
13
const CloudCredentialTagKind = "cloudcred"
13
14
 
14
15
var (
15
 
        cloudCredentialNameSnippet = "[a-zA-Z][a-zA-Z0-9.-]*"
 
16
        cloudCredentialNameSnippet = "[a-zA-Z][a-zA-Z0-9.@_-]*"
16
17
        validCloudCredentialName   = regexp.MustCompile("^" + cloudCredentialNameSnippet + "$")
17
18
        validCloudCredential       = regexp.MustCompile(
18
19
                "^" +
37
38
        return t.id(false)
38
39
}
39
40
 
 
41
func quoteCredentialSeparator(in string) string {
 
42
        return strings.Replace(in, "_", `%5f`, -1)
 
43
}
 
44
 
40
45
// String is part of the Tag interface.
41
46
func (t CloudCredentialTag) String() string {
42
 
        return fmt.Sprintf("%s-%s_%s_%s", t.Kind(), t.cloud.Id(), t.owner.Id(), t.name)
 
47
        return fmt.Sprintf("%s-%s_%s_%s", t.Kind(),
 
48
                quoteCredentialSeparator(t.cloud.Id()),
 
49
                quoteCredentialSeparator(t.owner.Id()),
 
50
                quoteCredentialSeparator(t.name))
43
51
}
44
52
 
45
53
// Canonical returns the cloud credential ID in canonical form.
109
117
        return validCloudCredentialName.MatchString(name)
110
118
}
111
119
 
112
 
func cloudCredentialTagSuffixToId(s string) string {
113
 
        return strings.Replace(s, "_", "/", -1)
 
120
func cloudCredentialTagSuffixToId(s string) (string, error) {
 
121
        s = strings.Replace(s, "_", "/", -1)
 
122
        return url.QueryUnescape(s)
114
123
}