-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy patharchetype.go
More file actions
69 lines (58 loc) · 2.05 KB
/
Copy patharchetype.go
File metadata and controls
69 lines (58 loc) · 2.05 KB
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
65
66
67
68
69
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package alzlib
import (
"strings"
mapset "github.com/deckarep/golang-set/v2"
)
// Archetype represents an archetype definition that hasn't been assigned to a management group
// The contents of the sets represent the map keys of the corresponding AlzLib maps.
// Do not creaste this struct directly, use NewArchetype instead.
type Archetype struct {
PolicyDefinitions mapset.Set[string]
PolicyAssignments mapset.Set[string]
PolicySetDefinitions mapset.Set[string]
RoleDefinitions mapset.Set[string]
name string
}
// NewArchetype creates a new Archetype with the given name.
func NewArchetype(name string) *Archetype {
return &Archetype{
PolicyDefinitions: mapset.NewThreadUnsafeSet[string](),
PolicyAssignments: mapset.NewThreadUnsafeSet[string](),
PolicySetDefinitions: mapset.NewThreadUnsafeSet[string](),
RoleDefinitions: mapset.NewThreadUnsafeSet[string](),
name: name,
}
}
// Name returns the name of the archetype.
func (a *Archetype) Name() string {
return a.name
}
// copy creates a deep copy of the archetype.
func (a *Archetype) copy() *Archetype {
return &Archetype{
PolicyDefinitions: a.PolicyDefinitions.Clone(),
PolicyAssignments: a.PolicyAssignments.Clone(),
PolicySetDefinitions: a.PolicySetDefinitions.Clone(),
RoleDefinitions: a.RoleDefinitions.Clone(),
name: a.name,
}
}
// SplitNameAndVersion splits a resource reference into its name and version components.
// If no version is present, the second return value will be nil.
func SplitNameAndVersion(ref string) (string, *string) {
split := strings.Split(ref, "@")
if len(split) == 1 {
return split[0], nil
}
return split[0], &split[1]
}
// JoinNameAndVersion joins a resource name and version into a single string.
// If the version is nil, only the name is returned.
func JoinNameAndVersion(name string, version *string) string {
if version == nil {
return name
}
return name + "@" + *version
}