-
Notifications
You must be signed in to change notification settings - Fork 30
/
pki_ep.go
93 lines (83 loc) · 2.55 KB
/
pki_ep.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 (
DnpkiEp = "uni/userext/pkiext"
RnpkiEp = "pkiext"
ParentDnpkiEp = "uni/userext"
PkiepClassName = "pkiEp"
)
type PublicKeyManagement struct {
BaseAttributes
NameAliasAttribute
PublicKeyManagementAttributes
}
type PublicKeyManagementAttributes struct {
Annotation string `json:",omitempty"`
Name string `json:",omitempty"`
}
func NewPublicKeyManagement(pkiEpRn, parentDn, description, nameAlias string, pkiEpAttr PublicKeyManagementAttributes) *PublicKeyManagement {
dn := fmt.Sprintf("%s/%s", parentDn, pkiEpRn)
return &PublicKeyManagement{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: PkiepClassName,
Rn: pkiEpRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
PublicKeyManagementAttributes: pkiEpAttr,
}
}
func (pkiEp *PublicKeyManagement) ToMap() (map[string]string, error) {
pkiEpMap, err := pkiEp.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
alias, err := pkiEp.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}
for key, value := range alias {
A(pkiEpMap, key, value)
}
A(pkiEpMap, "annotation", pkiEp.Annotation)
A(pkiEpMap, "name", pkiEp.Name)
return pkiEpMap, err
}
func PublicKeyManagementFromContainerList(cont *container.Container, index int) *PublicKeyManagement {
PublicKeyManagementCont := cont.S("imdata").Index(index).S(PkiepClassName, "attributes")
return &PublicKeyManagement{
BaseAttributes{
DistinguishedName: G(PublicKeyManagementCont, "dn"),
Description: G(PublicKeyManagementCont, "descr"),
Status: G(PublicKeyManagementCont, "status"),
ClassName: PkiepClassName,
Rn: G(PublicKeyManagementCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(PublicKeyManagementCont, "nameAlias"),
},
PublicKeyManagementAttributes{
Annotation: G(PublicKeyManagementCont, "annotation"),
Name: G(PublicKeyManagementCont, "name"),
},
}
}
func PublicKeyManagementFromContainer(cont *container.Container) *PublicKeyManagement {
return PublicKeyManagementFromContainerList(cont, 0)
}
func PublicKeyManagementListFromContainer(cont *container.Container) []*PublicKeyManagement {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*PublicKeyManagement, length)
for i := 0; i < length; i++ {
arr[i] = PublicKeyManagementFromContainerList(cont, i)
}
return arr
}