Skip to content

Commit

Permalink
Merge 7f6760c into daf30f6
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCondon committed Feb 11, 2021
2 parents daf30f6 + 7f6760c commit c4b47c2
Show file tree
Hide file tree
Showing 25 changed files with 840 additions and 111 deletions.
28 changes: 19 additions & 9 deletions cmd/onos-config/onos-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/onosproject/onos-config/pkg/northbound/diags"
"github.com/onosproject/onos-config/pkg/northbound/gnmi"
"github.com/onosproject/onos-config/pkg/store/change/device"
"github.com/onosproject/onos-config/pkg/store/change/device/rbac"
"github.com/onosproject/onos-config/pkg/store/change/device/state"
"github.com/onosproject/onos-config/pkg/store/change/network"
devicestore "github.com/onosproject/onos-config/pkg/store/device"
Expand All @@ -66,6 +67,9 @@ import (
// OIDCServerURL - address of an OpenID Connect server
const OIDCServerURL = "OIDC_SERVER_URL"

// RbacVersionedID - the internal device where RBAC rules are configured
const RbacVersionedID = "rbac:1.0.0"

type arrayFlags []string

func (i *arrayFlags) String() string {
Expand Down Expand Up @@ -166,9 +170,23 @@ func main() {
}
log.Infof("Topology service connected with endpoint %s", *topoEndpoint)

authorization := false
var rbacCache rbac.Cache
if oidcURL := os.Getenv(OIDCServerURL); oidcURL != "" {
authorization = true
rbacCache, err = rbac.NewRbacCache(deviceChangesStore, deviceSnapshotStore, RbacVersionedID)
if err != nil {
log.Fatal("Cannot create RBAC cache %v", err)
}
log.Infof("Authorization enabled. %s=%s", OIDCServerURL, oidcURL)
// OIDCServerURL is also referenced in jwt.go (from onos-lib-go)
} else {
log.Infof("Authorization not enabled %s", os.Getenv(OIDCServerURL))
}

mgr := manager.NewManager(leadershipStore, mastershipStore, deviceChangesStore,
deviceStateStore, deviceStore, deviceCache, networkChangesStore, networkSnapshotStore,
deviceSnapshotStore, *allowUnvalidatedConfig)
deviceSnapshotStore, *allowUnvalidatedConfig, rbacCache)
log.Info("Manager created")

defer func() {
Expand All @@ -188,14 +206,6 @@ func main() {
}

mgr.Run()
authorization := false
if oidcURL := os.Getenv(OIDCServerURL); oidcURL != "" {
authorization = true
log.Infof("Authorization enabled. %s=%s", OIDCServerURL, oidcURL)
// OIDCServerURL is also referenced in jwt.go (from onos-lib-go)
} else {
log.Infof("Authorization not enabled %s", os.Getenv(OIDCServerURL))
}

err = startServer(*caPath, *keyPath, *certPath, authorization)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ module github.com/onosproject/onos-config
go 1.14

require (
cloud.google.com/go v0.43.0 // indirect
github.com/Pallinder/go-randomdata v1.2.0
github.com/atomix/go-client v0.4.1
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/docker/docker v1.13.1 // indirect
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.4.4
github.com/golang/protobuf v1.4.3
github.com/google/pprof v0.0.0-20190723021845-34ac40c74b70 // indirect
github.com/google/uuid v1.1.2
github.com/googleapis/gnostic v0.3.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/kr/pty v1.1.8 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/onosproject/config-models/modelplugin/devicesim-1.0.0 v0.0.0-20201130213019-492043aed0df
Expand All @@ -36,7 +33,6 @@ require (
github.com/spf13/viper v1.6.2 // indirect
github.com/stretchr/testify v1.5.1
go.uber.org/multierr v1.4.0 // indirect
golang.org/x/mobile v0.0.0-20190806162312-597adff16ade // indirect
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 // indirect
google.golang.org/grpc v1.33.2
gopkg.in/yaml.v2 v2.2.8
Expand All @@ -45,3 +41,4 @@ require (
)

replace github.com/docker/docker => github.com/docker/engine v1.4.2-0.20200229013735-71373c6105e3

10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,12 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/onosproject/config-models v0.6.9 h1:ebL09o5xkG4pTV2dNDrcYSldt747nGhMSBa/DYNEMpA=
github.com/onosproject/config-models v0.6.9/go.mod h1:cw1HoviQUVAjX1MOHVqHo1oL6rpM52d6ckidRyL1z/I=
github.com/onosproject/config-models/modelplugin/devicesim-1.0.0 v0.0.0-20201130213019-492043aed0df h1:GPl0hkXGTk1c4KV70qmid1ATyHEtLoVJPMWckVjDzU0=
github.com/onosproject/config-models/modelplugin/devicesim-1.0.0 v0.0.0-20201130213019-492043aed0df/go.mod h1:5CH0bqq5FRZorJf9tUd8QLSd7cs/R0y/G2JFe6+1R8E=
github.com/onosproject/config-models/modelplugin/rbac-1.0.0 v0.0.0-20210209141520-685c964e9a9e h1:a3uuy2db3rKzO2aXM9jqRx/MOykjhQETJt4BXyTrO5o=
github.com/onosproject/config-models/modelplugin/rbac-1.0.0 v0.0.0-20210209141520-685c964e9a9e/go.mod h1:3QodL9K+9EwUJ332D8xXv6F725Q5GMcD7j3QKs6TNx4=
github.com/onosproject/config-models/modelplugin/testdevice-1.0.0 v0.0.0-20201130213019-492043aed0df h1:q996V3rkdtAjKEv1Vp5RGcWYDV7DimMiDlDaXES4NW8=
github.com/onosproject/config-models/modelplugin/testdevice-1.0.0 v0.0.0-20201130213019-492043aed0df/go.mod h1:awlBHj+BAaBrWsVUUHbuo3tbUqebfgI4BlY3ppiAPfs=
github.com/onosproject/config-models/modelplugin/testdevice-2.0.0 v0.0.0-20201130213019-492043aed0df h1:7u16PD0HnQlnACqcTEHPayKl2bZodA0fzWYRavm5h50=
Expand All @@ -552,6 +556,7 @@ github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c/go.mod h1:t+O9It+LKzfOAhKTT5O0ehDix+MTqbtT0T9t+7zzOvc=
github.com/openconfig/gnmi v0.0.0-20200414194230-1597cc0f2600/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A=
github.com/openconfig/gnmi v0.0.0-20200508230933-d19cebf5e7be/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A=
github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802 h1:WXFwJlWOJINlwlyAZuNo4GdYZS6qPX36+rRUncLmN8Q=
Expand All @@ -560,6 +565,7 @@ github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0
github.com/openconfig/goyang v0.2.1 h1:TaADsLGzULGQL8xTmvLjmXqZ/J1F73dMzURDqrv9cLs=
github.com/openconfig/goyang v0.2.1/go.mod h1:vX61x01Q46AzbZUzG617vWqh/cB+aisc+RrNkXRd3W8=
github.com/openconfig/ygot v0.6.0/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs=
github.com/openconfig/ygot v0.6.1-0.20200103195725-e3c44fa43926/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs=
github.com/openconfig/ygot v0.8.12 h1:UVYGo51K4DDJwNtJkYF23+gYVj8ZtjErrnzTY6YfK0w=
github.com/openconfig/ygot v0.8.12/go.mod h1:Qh/F0ycMLXJlZn4cR+5iuefEMthLggO8KBq8wjXYPTY=
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
Expand Down Expand Up @@ -764,6 +770,7 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU
golang.org/x/mobile v0.0.0-20190806162312-597adff16ade/go.mod h1:AlhUtkH4DA4asiFC5RgK7ZKmauvtkAVcy9L0epCzlWo=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -830,6 +837,7 @@ golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -867,6 +875,7 @@ golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200113040837-eac381796e91/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 h1:SjQ2+AKWgZLc1xej6WSzL+Dfs5Uyd5xcZH1mGC411IA=
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand All @@ -893,6 +902,7 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn
google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/genproto v0.0.0-20200519141106-08726f379972/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/getconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (m *Manager) GetTargetConfig(deviceID devicetype.ID, version devicetype.Ver
return configValues, nil
}
filteredValues := make([]*devicechange.PathValue, 0)
pathRegexp := utils.MatchWildcardRegexp(path)
pathRegexp := utils.MatchWildcardRegexp(path, false)
for _, cv := range configValues {
if pathRegexp.MatchString(cv.Path) {
filteredValues = append(filteredValues, cv)
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/getstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (m *Manager) GetTargetState(target string, path string) []*devicechange.Pat
log.Info("Getting State for ", target, path)
configValues := make([]*devicechange.PathValue, 0)
//First check the cache, if it's not empty for this path we read that and return,
pathRegexp := utils.MatchWildcardRegexp(path)
pathRegexp := utils.MatchWildcardRegexp(path, false)
m.OperationalStateCacheLock.RLock()
for pathCache, value := range m.OperationalStateCache[topodevice.ID(target)] {
if pathRegexp.MatchString(pathCache) {
Expand Down
42 changes: 5 additions & 37 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package manager

import (
"fmt"
"github.com/onosproject/onos-config/pkg/store/change/device/rbac"
"sync"

devicechange "github.com/onosproject/onos-api/go/onos/config/change/device"
Expand Down Expand Up @@ -72,14 +73,15 @@ type Manager struct {
Dispatcher *dispatcher.Dispatcher
OperationalStateCache map[topodevice.ID]devicechange.TypedValueMap
OperationalStateCacheLock *sync.RWMutex
RbacCache rbac.Cache
allowUnvalidatedConfig bool
}

// NewManager initializes the network config manager subsystem.
func NewManager(leadershipStore leadership.Store, mastershipStore mastership.Store, deviceChangesStore device.Store,
deviceStateStore state.Store, deviceStore devicestore.Store, deviceCache cache.Cache,
networkChangesStore network.Store, networkSnapshotStore networksnap.Store,
deviceSnapshotStore devicesnap.Store, allowUnvalidatedConfig bool) *Manager {
deviceSnapshotStore devicesnap.Store, allowUnvalidatedConfig bool, rbacCache rbac.Cache) *Manager {
log.Info("Creating Manager")

modelReg := &modelregistry.ModelRegistry{
Expand Down Expand Up @@ -110,7 +112,9 @@ func NewManager(leadershipStore leadership.Store, mastershipStore mastership.Sto
OperationalStateCache: make(map[topodevice.ID]devicechange.TypedValueMap),
OperationalStateCacheLock: &sync.RWMutex{},
allowUnvalidatedConfig: allowUnvalidatedConfig,
RbacCache: rbacCache,
}

return &mgr
}

Expand Down Expand Up @@ -186,42 +190,6 @@ func GetManager() *Manager {
return &mgr
}

// ComputeDeviceChange computes a given device change the given updates and deletes, according to the path
// on the configuration for the specified target
func (m *Manager) ComputeDeviceChange(deviceName devicetype.ID, version devicetype.Version,
deviceType devicetype.Type, updates devicechange.TypedValueMap,
deletes []string, description string) (*devicechange.Change, error) {

var newChanges = make([]*devicechange.ChangeValue, 0)
//updates
for path, value := range updates {
updateValue, err := devicechange.NewChangeValue(path, value, false)
if err != nil {
log.Warnf("Error creating value for %s %v", path, err)
continue
}
newChanges = append(newChanges, updateValue)
}
//deletes
for _, path := range deletes {
deleteValue, _ := devicechange.NewChangeValue(path, devicechange.NewTypedValueEmpty(), true)
newChanges = append(newChanges, deleteValue)
}
//description := fmt.Sprintf("Originally created as part of %s", description)
//if description == "" {
// description = fmt.Sprintf("Created at %s", time.Now().Format(time.RFC3339))
//}
//TODO lost description of Change
changeElement := &devicechange.Change{
DeviceID: deviceName,
DeviceVersion: version,
DeviceType: deviceType,
Values: newChanges,
}

return changeElement, nil
}

// CheckCacheForDevice checks against the device cache (of the device change store
// to see if a device of that name is already present)
func (m *Manager) CheckCacheForDevice(target devicetype.ID, deviceType devicetype.Type,
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/manager_deep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func setUpDeepTest(t *testing.T) (*Manager, *AllMocks) {
assert.NilError(t, err)

mgrTest = NewManager(leadershipStore, mastershipStore, deviceChangesStore, deviceStateStore,
mockDeviceStore, deviceCache, networkChangesStore, networkSnapshotStore, deviceSnapshotStore, true)
mockDeviceStore, deviceCache, networkChangesStore, networkSnapshotStore, deviceSnapshotStore, true, nil)

modelData1 := gnmi.ModelData{
Name: "test1",
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ func setUp(t *testing.T) (*Manager, *AllMocks) {
mockNetworkChangesStore,
mockNetworkSnapshotStore,
mockDeviceSnapshotStore,
true)
true,
nil)

mgrTest.Run()

Expand Down
42 changes: 39 additions & 3 deletions pkg/manager/setconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const SetConfigAlreadyApplied = "Already applied:"
func (m *Manager) ValidateNetworkConfig(deviceName devicetype.ID, version devicetype.Version,
deviceType devicetype.Type, updates devicechange.TypedValueMap, deletes []string, lastWrite networkchange.Revision) error {

chg, err := m.ComputeDeviceChange(deviceName, version, deviceType, updates, deletes, "Generated for validation")
chg, err := computeDeviceChange(deviceName, version, deviceType, updates, deletes, "Generated for validation")
if err != nil {
return err
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func (m *Manager) computeNetworkConfig(targetUpdates map[devicetype.ID]devicecha
//FIXME this is a sequential job, not parallelized
version := deviceInfo[target].Version
deviceType := deviceInfo[target].Type
newChange, err := m.ComputeDeviceChange(
newChange, err := computeDeviceChange(
target, version, deviceType, updates, targetRemoves[target], description)
if err != nil {
log.Error("Error in setting config: ", newChange, " for target ", err)
Expand All @@ -143,7 +143,7 @@ func (m *Manager) computeNetworkConfig(targetUpdates map[devicetype.ID]devicecha
for target, removes := range targetRemoves {
version := deviceInfo[target].Version
deviceType := deviceInfo[target].Type
newChange, err := m.ComputeDeviceChange(
newChange, err := computeDeviceChange(
target, version, deviceType, make(devicechange.TypedValueMap), removes, description)
if err != nil {
log.Error("Error in setting config: ", newChange, " for target ", err)
Expand All @@ -154,3 +154,39 @@ func (m *Manager) computeNetworkConfig(targetUpdates map[devicetype.ID]devicecha
}
return deviceChanges, nil
}

// computeDeviceChange computes a given device change the given updates and deletes, according to the path
// on the configuration for the specified target
func computeDeviceChange(deviceName devicetype.ID, version devicetype.Version,
deviceType devicetype.Type, updates devicechange.TypedValueMap,
deletes []string, description string) (*devicechange.Change, error) {

var newChanges = make([]*devicechange.ChangeValue, 0)
//updates
for path, value := range updates {
updateValue, err := devicechange.NewChangeValue(path, value, false)
if err != nil {
log.Warnf("Error creating value for %s %v", path, err)
continue
}
newChanges = append(newChanges, updateValue)
}
//deletes
for _, path := range deletes {
deleteValue, _ := devicechange.NewChangeValue(path, devicechange.NewTypedValueEmpty(), true)
newChanges = append(newChanges, deleteValue)
}
//description := fmt.Sprintf("Originally created as part of %s", description)
//if description == "" {
// description = fmt.Sprintf("Created at %s", time.Now().Format(time.RFC3339))
//}
//TODO lost description of Change
changeElement := &devicechange.Change{
DeviceID: deviceName,
DeviceVersion: version,
DeviceType: deviceType,
Values: newChanges,
}

return changeElement, nil
}
6 changes: 4 additions & 2 deletions pkg/modelregistry/jsonvalues/jsonToValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ func indicesOfPath(modelROpaths modelregistry.ReadOnlyPathMap,
pathNoIndices := modelregistry.RemovePathIndices(path)
// Find a short path
if pathNoIndices[:strings.LastIndex(pathNoIndices, slash)] == searchpathNoIndices {
return modelregistry.ExtractIndexNames(path)
idxNames, _ := modelregistry.ExtractIndexNames(path)
return idxNames
}
}

Expand All @@ -500,7 +501,8 @@ func indicesOfPath(modelROpaths modelregistry.ReadOnlyPathMap,
pathNoIndices := modelregistry.RemovePathIndices(fullpath)
// Find a short path
if pathNoIndices[:strings.LastIndex(pathNoIndices, slash)] == searchpathNoIndices {
return modelregistry.ExtractIndexNames(fullpath)
idxNames, _ := modelregistry.ExtractIndexNames(fullpath)
return idxNames
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func ExtractPaths(deviceEntry *yang.Entry, parentState yang.TriState, parentPath
// Need to copy the index of the list across to the RO list too
roIdxName := k[:strings.LastIndex(k, "/")]
roIdxSubPath := k[strings.LastIndex(k, "/"):]
indices := ExtractIndexNames(itemPath[strings.LastIndex(itemPath, "/"):])
indices, _ := ExtractIndexNames(itemPath[strings.LastIndex(itemPath, "/"):])
kIsIdxAttr := false
for _, idx := range indices {
if roIdxSubPath == fmt.Sprintf("/%s", idx) {
Expand Down Expand Up @@ -403,14 +403,17 @@ func RemovePathIndices(path string) string {
}

// ExtractIndexNames - get an ordered array of index names
func ExtractIndexNames(path string) []string {
func ExtractIndexNames(path string) ([]string, []string) {
indexNames := make([]string, 0)
indexValues := make([]string, 0)
jsonMatches := rOnIndex.FindAllStringSubmatch(path, -1)
for _, m := range jsonMatches {
idxName := m[1][1:strings.LastIndex(m[1], "=")]
indexNames = append(indexNames, idxName)
idxValue := m[1][strings.LastIndex(m[1], "=")+1 : len(m[1])-1]
indexValues = append(indexValues, idxValue)
}
return indexNames
return indexNames, indexValues
}

func formatName(dirEntry *yang.Entry, isList bool, parentPath string, subpathPrefix string) string {
Expand Down

0 comments on commit c4b47c2

Please sign in to comment.