-
Notifications
You must be signed in to change notification settings - Fork 29
/
aaa_user_domain.go
93 lines (83 loc) · 2.51 KB
/
aaa_user_domain.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const (
DnaaaUserDomain = "uni/userext/user-%s/userdomain-%s"
RnaaaUserDomain = "userdomain-%s"
ParentDnaaaUserDomain = "uni/userext/user-%s"
AaauserdomainClassName = "aaaUserDomain"
)
type UserDomain struct {
BaseAttributes
NameAliasAttribute
UserDomainAttributes
}
type UserDomainAttributes struct {
Annotation string `json:",omitempty"`
Name string `json:",omitempty"`
}
func NewUserDomain(aaaUserDomainRn, parentDn, description, nameAlias string, aaaUserDomainAttr UserDomainAttributes) *UserDomain {
dn := fmt.Sprintf("%s/%s", parentDn, aaaUserDomainRn)
return &UserDomain{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: AaauserdomainClassName,
Rn: aaaUserDomainRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
UserDomainAttributes: aaaUserDomainAttr,
}
}
func (aaaUserDomain *UserDomain) ToMap() (map[string]string, error) {
aaaUserDomainMap, err := aaaUserDomain.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
alias, err := aaaUserDomain.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}
for key, value := range alias {
A(aaaUserDomainMap, key, value)
}
A(aaaUserDomainMap, "annotation", aaaUserDomain.Annotation)
A(aaaUserDomainMap, "name", aaaUserDomain.Name)
return aaaUserDomainMap, err
}
func UserDomainFromContainerList(cont *container.Container, index int) *UserDomain {
UserDomainCont := cont.S("imdata").Index(index).S(AaauserdomainClassName, "attributes")
return &UserDomain{
BaseAttributes{
DistinguishedName: G(UserDomainCont, "dn"),
Description: G(UserDomainCont, "descr"),
Status: G(UserDomainCont, "status"),
ClassName: AaauserdomainClassName,
Rn: G(UserDomainCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(UserDomainCont, "nameAlias"),
},
UserDomainAttributes{
Annotation: G(UserDomainCont, "annotation"),
Name: G(UserDomainCont, "name"),
},
}
}
func UserDomainFromContainer(cont *container.Container) *UserDomain {
return UserDomainFromContainerList(cont, 0)
}
func UserDomainListFromContainer(cont *container.Container) []*UserDomain {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*UserDomain, length)
for i := 0; i < length; i++ {
arr[i] = UserDomainFromContainerList(cont, i)
}
return arr
}