/
org_org.go
83 lines (62 loc) · 1.92 KB
/
org_org.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
package models
import (
"fmt"
"github.com/beevik/etree"
)
const OrgOrgClassName = "orgOrg"
type OrgOrg struct {
BaseAttributes
OrgOrgAttributes
}
type OrgOrgAttributes struct{
Child_action string `xml:",omitempty"`
Flt_aggr string `xml:",omitempty"`
Level string `xml:",omitempty"`
Perm_access string `xml:",omitempty"`
Sacl string `xml:",omitempty"`
}
func NewOrgOrg(orgOrgRn,parentDn,description string, orgOrgAttributes OrgOrgAttributes) *OrgOrg {
dn := fmt.Sprintf("%s/%s", parentDn, orgOrgRn)
return &OrgOrg{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
ClassName: OrgOrgClassName,
Status: "created, modified",
Description: description,
},
OrgOrgAttributes: orgOrgAttributes,
}
}
func (orgOrg *OrgOrg) ToMap() (map[string]string, error) {
orgOrgMap, err := orgOrg.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
orgOrgMap["childAction"] = orgOrg.Child_action
orgOrgMap["fltAggr"] = orgOrg.Flt_aggr
orgOrgMap["level"] = orgOrg.Level
orgOrgMap["permAccess"] = orgOrg.Perm_access
orgOrgMap["sacl"] = orgOrg.Sacl
return orgOrgMap, nil
}
func OrgOrgFromDoc(doc *etree.Document, rootClass string) *OrgOrg {
element, err := GetMoElement(doc, rootClass, OrgOrgClassName)
if err != nil {
return nil
}
return &OrgOrg{
BaseAttributes: BaseAttributes{
DistinguishedName: element.SelectAttrValue("dn", ""),
ClassName: OrgOrgClassName,
Description: element.SelectAttrValue("descr", ""),
Status: element.SelectAttrValue("status", ""),
},
OrgOrgAttributes: OrgOrgAttributes{
Child_action: element.SelectAttrValue("childAction", ""),
Flt_aggr: element.SelectAttrValue("fltAggr", ""),
Level: element.SelectAttrValue("level", ""),
Perm_access: element.SelectAttrValue("permAccess", ""),
Sacl: element.SelectAttrValue("sacl", ""),
},
}
}