forked from juju/names
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environ.go
43 lines (34 loc) · 1.1 KB
/
environ.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2013 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package names
import (
"regexp"
)
const EnvironTagKind = "environment"
type EnvironTag struct {
uuid string
}
var validUUID = regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}`)
// NewEnvironTag returns the tag of an environment with the given environment UUID.
func NewEnvironTag(uuid string) EnvironTag {
return EnvironTag{uuid: uuid}
}
// ParseEnvironTag parses an environ tag string.
func ParseEnvironTag(environTag string) (EnvironTag, error) {
tag, err := ParseTag(environTag)
if err != nil {
return EnvironTag{}, err
}
et, ok := tag.(EnvironTag)
if !ok {
return EnvironTag{}, invalidTagError(environTag, EnvironTagKind)
}
return et, nil
}
func (t EnvironTag) String() string { return t.Kind() + "-" + t.Id() }
func (t EnvironTag) Kind() string { return EnvironTagKind }
func (t EnvironTag) Id() string { return t.uuid }
// IsValidEnvironment returns whether id is a valid environment UUID.
func IsValidEnvironment(id string) bool {
return validUUID.MatchString(id)
}