1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
9
"github.com/juju/utils"
13
// PayloadTagKind is used as the prefix for the string
14
// representation of payload tags.
15
PayloadTagKind = "payload"
17
// This can be expanded later, as needed.
18
payloadClass = "([a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)"
21
var validPayload = regexp.MustCompile("^" + payloadClass + "$")
23
// IsValidPayload returns whether id is a valid Juju ID for
24
// a charm payload. The ID must be a valid alpha-numeric (plus hyphens).
25
func IsValidPayload(id string) bool {
26
return validPayload.MatchString(id)
29
// For compatibility with Juju 1.25, UUIDs are also supported.
30
func isValidPayload(id string) bool {
31
return IsValidPayload(id) || utils.IsValidUUIDString(id)
34
// PayloadTag represents a charm payload.
35
type PayloadTag struct {
39
// NewPayloadTag returns the tag for a charm's payload with the given id.
40
func NewPayloadTag(id string) PayloadTag {
46
// ParsePayloadTag parses a payload tag string.
47
// So ParsePayloadTag(tag.String()) === tag.
48
func ParsePayloadTag(tag string) (PayloadTag, error) {
49
t, err := ParseTag(tag)
51
return PayloadTag{}, err
53
pt, ok := t.(PayloadTag)
55
return PayloadTag{}, invalidTagError(tag, PayloadTagKind)
60
// Kind implements Tag.
61
func (t PayloadTag) Kind() string {
65
// Id implements Tag.Id. It always returns the same ID with which
66
// it was created. So NewPayloadTag(x).Id() == x for all valid x.
67
func (t PayloadTag) Id() string {
71
// String implements Tag.
72
func (t PayloadTag) String() string {