-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespace.go
60 lines (49 loc) · 1.41 KB
/
namespace.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package v2
import (
"fmt"
"net/url"
"path"
)
const (
// NamespaceTypeAll represents an empty namespace, used to represent a request
// across all namespaces
NamespaceTypeAll = ""
// NamespacesResource is the name of this resource type
NamespacesResource = "namespaces"
)
// StorePrefix returns the path prefix to this resource in the store
func (n *Namespace) StorePrefix() string {
return NamespacesResource
}
// URIPath returns the path component of a Namespace URI.
func (n *Namespace) URIPath() string {
return path.Join(URLPrefix, "namespaces", url.PathEscape(n.Name))
}
// Validate returns an error if the namespace does not pass validation tests
func (n *Namespace) Validate() error {
if err := ValidateName(n.Name); err != nil {
return fmt.Errorf("namespace name %s", err)
}
return nil
}
// FixtureNamespace returns a mocked namespace
func FixtureNamespace(name string) *Namespace {
return &Namespace{
Name: name,
}
}
// GetObjectMeta only exists here to fulfil the requirements of Resource
func (n *Namespace) GetObjectMeta() ObjectMeta {
return ObjectMeta{Name: n.Name}
}
// NamespaceFields returns a set of fields that represent that resource
func NamespaceFields(r Resource) map[string]string {
resource := r.(*Namespace)
return map[string]string{
"namespace.name": resource.Name,
}
}
// SetNamespace sets the namespace of the resource.
func (n *Namespace) SetNamespace(namespace string) {
return
}