forked from raystack/frontier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespace.go
64 lines (54 loc) · 1.34 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
61
62
63
64
package namespace
import (
"context"
"fmt"
"time"
)
const AuditEntity = "namespace"
type Repository interface {
Get(ctx context.Context, id string) (Namespace, error)
Upsert(ctx context.Context, ns Namespace) (Namespace, error)
List(ctx context.Context) ([]Namespace, error)
Update(ctx context.Context, ns Namespace) (Namespace, error)
}
type Namespace struct {
ID string
Name string
Backend string
ResourceType string
CreatedAt time.Time
UpdatedAt time.Time
}
type LogData struct {
Entity string `mapstructure:"entity"`
ID string `mapstructure:"id"`
Name string `mapstructure:"name"`
Backend string `mapstructure:"backend"`
ResourceType string `mapstructure:"resource_type"`
}
func (namespace Namespace) ToLogData() LogData {
return LogData{
Entity: AuditEntity,
ID: namespace.ID,
Name: namespace.Name,
Backend: namespace.Backend,
ResourceType: namespace.ResourceType,
}
}
func strListHas(list []string, a string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func IsSystemNamespaceID(nsID string) bool {
return strListHas(systemIdsDefinition, nsID)
}
func CreateID(backend, resourceType string) string {
if resourceType == "" {
return backend
}
return fmt.Sprintf("%s/%s", backend, resourceType)
}