blob: db02d00646de77daa5480e34858ad3668ba7fccb [file] [log] [blame]
David K. Bainbridge528b3182017-01-23 08:51:59 -08001// Copyright 2013 Canonical Ltd.
2// Licensed under the LGPLv3, see LICENCE file for details.
3
4package names
5
6// EnvironTagKind is DEPRECATED: model tags are used instead.
7const EnvironTagKind = "environment"
8
9type EnvironTag struct {
10 uuid string
11}
12
13// NewEnvironTag returns the tag of an environment with the given environment UUID.
14func NewEnvironTag(uuid string) EnvironTag {
15 return EnvironTag{uuid: uuid}
16}
17
18// ParseEnvironTag parses an environ tag string.
19func ParseEnvironTag(environTag string) (EnvironTag, error) {
20 tag, err := ParseTag(environTag)
21 if err != nil {
22 return EnvironTag{}, err
23 }
24 et, ok := tag.(EnvironTag)
25 if !ok {
26 return EnvironTag{}, invalidTagError(environTag, EnvironTagKind)
27 }
28 return et, nil
29}
30
31func (t EnvironTag) String() string { return t.Kind() + "-" + t.Id() }
32func (t EnvironTag) Kind() string { return EnvironTagKind }
33func (t EnvironTag) Id() string { return t.uuid }
34
35// IsValidEnvironment returns whether id is a valid environment UUID.
36func IsValidEnvironment(id string) bool {
37 return validUUID.MatchString(id)
38}