-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for tacacs-source (#147)
* Added support for tacacs-source * Updated Model
- v2.31.0
- v2.30.1
- v2.30.0
- v2.29.0
- v2.28.2
- v2.28.1
- v2.28.0
- v2.27.0
- v2.26.0
- v2.25.2
- v2.25.1
- v2.25.0
- v2.24.0
- v2.23.0
- v2.22.1
- v2.22.0
- v2.21.0
- v2.20.0
- v2.19.0
- v2.18.0
- v2.17.0
- v2.16.0
- v2.15.0
- v2.14.0
- v2.13.0
- v2.12.0
- v2.11.1
- v2.11.0
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.5
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.0
- v2.4.0
- v2.2.0
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.54.0
- v1.53.2
- v1.53.1
- v1.53.0
- v1.52.0
- v1.51.0
- v1.50.0
- v1.49.0
- v1.48.0
- v1.47.0
- v1.46.0
- v1.45.3
- v1.45.2
- v1.45.1
- v1.45.0
- v1.44.0
- v1.43.0
- v1.42.0
- v1.41.0
- v1.40.0
- v1.39.1
- v1.39.0
- v1.38.1
- v1.38.0
- v1.37.0
- v1.36.1
- v1.36.0
- v1.35.2
- v1.35.1
- v1.35.0
- v1.34.1
- v1.34.0
- v1.33.0
- v1.32.0
- v1.31.0
- v1.30.0
- v1.29.1
- v1.29.0
- v1.28.0
- v1.27.0
- v1.26.2
- v1.26.1
- v1.26.0
- v1.25.1
- v1.25.0
- v1.24.1
- v1.24.0
- v1.23.2
- v1.23.1
- v1.23.0
- v1.22.0
- v1.21.1
- v1.21.0
- v1.20.4
- v1.20.3
- v1.20.2
- v1.20.1
- v1.20.0
- v1.19.2
- v1.19.1
- v1.19.0
- v1.18.0
1 parent
0a21b23
commit 2697c2a
Showing
2 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/container" | ||
"github.com/ciscoecosystem/aci-go-client/models" | ||
) | ||
|
||
func (sm *ServiceManager) CreateTACACSSource(name string, monitoring_target_scope string, monitoring_policy string, tenant string, description string, nameAlias string, tacacsSrcAttr models.TACACSSourceAttributes) (*models.TACACSSource, error) { | ||
rn := fmt.Sprintf(models.RntacacsSrc, name) | ||
parentDn := fmt.Sprintf(models.ParentDntacacsSrc, tenant, monitoring_policy, monitoring_target_scope, monitoring_policy) | ||
tacacsSrc := models.NewTACACSSource(rn, parentDn, description, nameAlias, tacacsSrcAttr) | ||
err := sm.Save(tacacsSrc) | ||
return tacacsSrc, err | ||
} | ||
|
||
func (sm *ServiceManager) ReadTACACSSource(name string, monitoring_target_scope string, monitoring_policy string, tenant string) (*models.TACACSSource, error) { | ||
dn := fmt.Sprintf(models.DntacacsSrc, tenant, monitoring_policy, monitoring_target_scope, monitoring_policy, name) | ||
cont, err := sm.Get(dn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tacacsSrc := models.TACACSSourceFromContainer(cont) | ||
return tacacsSrc, nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteTACACSSource(name string, monitoring_target_scope string, monitoring_policy string, tenant string) error { | ||
dn := fmt.Sprintf(models.DntacacsSrc, tenant, monitoring_policy, monitoring_target_scope, monitoring_policy, name) | ||
return sm.DeleteByDn(dn, models.TacacssrcClassName) | ||
} | ||
|
||
func (sm *ServiceManager) UpdateTACACSSource(name string, monitoring_target_scope string, monitoring_policy string, tenant string, description string, nameAlias string, tacacsSrcAttr models.TACACSSourceAttributes) (*models.TACACSSource, error) { | ||
rn := fmt.Sprintf(models.RntacacsSrc, name) | ||
parentDn := fmt.Sprintf(models.ParentDntacacsSrc, tenant, monitoring_policy, monitoring_target_scope, monitoring_policy) | ||
tacacsSrc := models.NewTACACSSource(rn, parentDn, description, nameAlias, tacacsSrcAttr) | ||
tacacsSrc.Status = "modified" | ||
err := sm.Save(tacacsSrc) | ||
return tacacsSrc, err | ||
} | ||
|
||
func (sm *ServiceManager) ListTACACSSource(monitoring_target_scope string, monitoring_policy string, tenant string) ([]*models.TACACSSource, error) { | ||
dnUrl := fmt.Sprintf("%s/uni/tn-%s/monepg-%s/tarepg-%s/tacacsSrc.json", models.BaseurlStr, tenant, monitoring_policy, monitoring_target_scope, monitoring_policy) | ||
cont, err := sm.GetViaURL(dnUrl) | ||
list := models.TACACSSourceListFromContainer(cont) | ||
return list, err | ||
} | ||
|
||
func (sm *ServiceManager) CreateRelationtacacsRsDestGroup(parentDn, annotation, tDn string) error { | ||
dn := fmt.Sprintf("%s/rsdestGroup", parentDn) | ||
containerJSON := []byte(fmt.Sprintf(`{ | ||
"%s": { | ||
"attributes": { | ||
"dn": "%s", | ||
"annotation": "%s", | ||
"tDn": "%s" | ||
} | ||
} | ||
}`, "tacacsRsDestGroup", dn, annotation, tDn)) | ||
|
||
jsonPayload, err := container.ParseJSON(containerJSON) | ||
if err != nil { | ||
return err | ||
} | ||
req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true) | ||
if err != nil { | ||
return err | ||
} | ||
cont, _, err := sm.client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%+v", cont) | ||
return nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteRelationtacacsRsDestGroup(parentDn string) error { | ||
dn := fmt.Sprintf("%s/rsdestGroup", parentDn) | ||
return sm.DeleteByDn(dn, "tacacsRsDestGroup") | ||
} | ||
|
||
func (sm *ServiceManager) ReadRelationtacacsRsDestGroup(parentDn string) (interface{}, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "tacacsRsDestGroup") | ||
cont, err := sm.GetViaURL(dnUrl) | ||
contList := models.ListFromContainer(cont, "tacacsRsDestGroup") | ||
|
||
if len(contList) > 0 { | ||
dat := models.G(contList[0], "tDn") | ||
return dat, err | ||
} else { | ||
return nil, err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/container" | ||
) | ||
|
||
const ( | ||
DntacacsSrc = "uni/tn-%s/monepg-%s/tarepg-%s/tacacssrc-%s" | ||
RntacacsSrc = "tacacssrc-%s" | ||
ParentDntacacsSrc = "uni/tn-%s/monepg-%s/tarepg-%s" | ||
TacacssrcClassName = "tacacsSrc" | ||
) | ||
|
||
type TACACSSource struct { | ||
BaseAttributes | ||
NameAliasAttribute | ||
TACACSSourceAttributes | ||
} | ||
|
||
type TACACSSourceAttributes struct { | ||
Annotation string `json:",omitempty"` | ||
Incl string `json:",omitempty"` | ||
MinSev string `json:",omitempty"` | ||
Name string `json:",omitempty"` | ||
} | ||
|
||
func NewTACACSSource(tacacsSrcRn, parentDn, description, nameAlias string, tacacsSrcAttr TACACSSourceAttributes) *TACACSSource { | ||
dn := fmt.Sprintf("%s/%s", parentDn, tacacsSrcRn) | ||
return &TACACSSource{ | ||
BaseAttributes: BaseAttributes{ | ||
DistinguishedName: dn, | ||
Description: description, | ||
Status: "created, modified", | ||
ClassName: TacacssrcClassName, | ||
Rn: tacacsSrcRn, | ||
}, | ||
NameAliasAttribute: NameAliasAttribute{ | ||
NameAlias: nameAlias, | ||
}, | ||
TACACSSourceAttributes: tacacsSrcAttr, | ||
} | ||
} | ||
|
||
func (tacacsSrc *TACACSSource) ToMap() (map[string]string, error) { | ||
tacacsSrcMap, err := tacacsSrc.BaseAttributes.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
alias, err := tacacsSrc.NameAliasAttribute.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for key, value := range alias { | ||
A(tacacsSrcMap, key, value) | ||
} | ||
A(tacacsSrcMap, "annotation", tacacsSrc.Annotation) | ||
A(tacacsSrcMap, "incl", tacacsSrc.Incl) | ||
A(tacacsSrcMap, "minSev", tacacsSrc.MinSev) | ||
A(tacacsSrcMap, "name", tacacsSrc.Name) | ||
return tacacsSrcMap, err | ||
} | ||
|
||
func TACACSSourceFromContainerList(cont *container.Container, index int) *TACACSSource { | ||
TACACSSourceCont := cont.S("imdata").Index(index).S(TacacssrcClassName, "attributes") | ||
return &TACACSSource{ | ||
BaseAttributes{ | ||
DistinguishedName: G(TACACSSourceCont, "dn"), | ||
Description: G(TACACSSourceCont, "descr"), | ||
Status: G(TACACSSourceCont, "status"), | ||
ClassName: TacacssrcClassName, | ||
Rn: G(TACACSSourceCont, "rn"), | ||
}, | ||
NameAliasAttribute{ | ||
NameAlias: G(TACACSSourceCont, "nameAlias"), | ||
}, | ||
TACACSSourceAttributes{ | ||
Annotation: G(TACACSSourceCont, "annotation"), | ||
Incl: G(TACACSSourceCont, "incl"), | ||
MinSev: G(TACACSSourceCont, "minSev"), | ||
Name: G(TACACSSourceCont, "name"), | ||
}, | ||
} | ||
} | ||
|
||
func TACACSSourceFromContainer(cont *container.Container) *TACACSSource { | ||
return TACACSSourceFromContainerList(cont, 0) | ||
} | ||
|
||
func TACACSSourceListFromContainer(cont *container.Container) []*TACACSSource { | ||
length, _ := strconv.Atoi(G(cont, "totalCount")) | ||
arr := make([]*TACACSSource, length) | ||
for i := 0; i < length; i++ { | ||
arr[i] = TACACSSourceFromContainerList(cont, i) | ||
} | ||
return arr | ||
} |