David K. Bainbridge | 528b318 | 2017-01-23 08:51:59 -0800 | [diff] [blame^] | 1 | // Copyright 2013 Canonical Ltd. |
| 2 | // Licensed under the LGPLv3, see LICENCE file for details. |
| 3 | |
| 4 | package names |
| 5 | |
| 6 | // EnvironTagKind is DEPRECATED: model tags are used instead. |
| 7 | const EnvironTagKind = "environment" |
| 8 | |
| 9 | type EnvironTag struct { |
| 10 | uuid string |
| 11 | } |
| 12 | |
| 13 | // NewEnvironTag returns the tag of an environment with the given environment UUID. |
| 14 | func NewEnvironTag(uuid string) EnvironTag { |
| 15 | return EnvironTag{uuid: uuid} |
| 16 | } |
| 17 | |
| 18 | // ParseEnvironTag parses an environ tag string. |
| 19 | func 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 | |
| 31 | func (t EnvironTag) String() string { return t.Kind() + "-" + t.Id() } |
| 32 | func (t EnvironTag) Kind() string { return EnvironTagKind } |
| 33 | func (t EnvironTag) Id() string { return t.uuid } |
| 34 | |
| 35 | // IsValidEnvironment returns whether id is a valid environment UUID. |
| 36 | func IsValidEnvironment(id string) bool { |
| 37 | return validUUID.MatchString(id) |
| 38 | } |