From b7a2d9c63c4758ac69a88a10c7d3d8935943e333 Mon Sep 17 00:00:00 2001 From: steiler Date: Wed, 28 Jan 2026 16:30:12 +0100 Subject: [PATCH 1/4] implement the target path prefix --- go.mod | 1 + pkg/config/datastore.go | 3 ++- pkg/datastore/target/gnmi/gnmi.go | 3 +++ pkg/server/datastore.go | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 23656402..a9159084 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/sdcio/data-server go 1.24.0 replace github.com/openconfig/goyang v1.6.0 => github.com/sdcio/goyang v1.6.2-2 +replace github.com/sdcio/sdc-protos => /home/mava/projects/sdc-protos require ( github.com/AlekSi/pointer v1.2.0 diff --git a/pkg/config/datastore.go b/pkg/config/datastore.go index d914baae..08069e21 100644 --- a/pkg/config/datastore.go +++ b/pkg/config/datastore.go @@ -76,7 +76,8 @@ type SBI struct { } type SBIGnmiOptions struct { - Encoding string `yaml:"encoding,omitempty" json:"encoding,omitempty"` + Encoding string `yaml:"encoding,omitempty" json:"encoding,omitempty"` + TargetName string `yaml:"target,omitempty" json:"target,omitempty"` } type SBINetconfOptions struct { diff --git a/pkg/datastore/target/gnmi/gnmi.go b/pkg/datastore/target/gnmi/gnmi.go index 9dccc65a..c7128ee1 100644 --- a/pkg/datastore/target/gnmi/gnmi.go +++ b/pkg/datastore/target/gnmi/gnmi.go @@ -216,6 +216,9 @@ func (t *gnmiTarget) Set(ctx context.Context, source targetTypes.TargetSource) ( setReq := &gnmi.SetRequest{ Delete: make([]*gnmi.Path, 0, len(deletes)), Update: make([]*gnmi.Update, 0, len(upds)), + Prefix: &gnmi.Path{ + Target: t.cfg.GnmiOptions.TargetName, + }, } for _, del := range deletes { gdel := utils.ToGNMIPath(del) diff --git a/pkg/server/datastore.go b/pkg/server/datastore.go index de1b3550..ebdd8e6f 100644 --- a/pkg/server/datastore.go +++ b/pkg/server/datastore.go @@ -128,7 +128,8 @@ func (s *Server) CreateDataStore(ctx context.Context, req *sdcpb.CreateDataStore case "gnmi": sbi.GnmiOptions = &config.SBIGnmiOptions{ - Encoding: req.GetTarget().GetGnmiOpts().GetEncoding(), + Encoding: req.GetTarget().GetGnmiOpts().GetEncoding(), + TargetName: req.GetTarget().GetGnmiOpts().GetTargetName(), } default: log.Error(nil, "unknowm targetconnection protocol type", "type", req.GetTarget().GetType()) From 03438c32f951b338a32980d669b08dc48bac40ca Mon Sep 17 00:00:00 2001 From: steiler Date: Thu, 29 Jan 2026 14:16:21 +0100 Subject: [PATCH 2/4] add the Target Prefix conditionally --- pkg/datastore/target/gnmi/gnmi.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/datastore/target/gnmi/gnmi.go b/pkg/datastore/target/gnmi/gnmi.go index c7128ee1..5974eff2 100644 --- a/pkg/datastore/target/gnmi/gnmi.go +++ b/pkg/datastore/target/gnmi/gnmi.go @@ -216,10 +216,13 @@ func (t *gnmiTarget) Set(ctx context.Context, source targetTypes.TargetSource) ( setReq := &gnmi.SetRequest{ Delete: make([]*gnmi.Path, 0, len(deletes)), Update: make([]*gnmi.Update, 0, len(upds)), - Prefix: &gnmi.Path{ - Target: t.cfg.GnmiOptions.TargetName, - }, } + + // check if the target name is set, then add the prefix field + if t.cfg.GnmiOptions.TargetName != "" { + setReq.Prefix = &gnmi.Path{Target: t.cfg.GnmiOptions.TargetName} + } + for _, del := range deletes { gdel := utils.ToGNMIPath(del) setReq.Delete = append(setReq.Delete, gdel) From 6299bef4b51a2cb9f4950e6c156feeaed61f7c69 Mon Sep 17 00:00:00 2001 From: steiler Date: Tue, 3 Feb 2026 14:03:24 +0100 Subject: [PATCH 3/4] update mod (sdc-protos) --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index a9159084..23656402 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/sdcio/data-server go 1.24.0 replace github.com/openconfig/goyang v1.6.0 => github.com/sdcio/goyang v1.6.2-2 -replace github.com/sdcio/sdc-protos => /home/mava/projects/sdc-protos require ( github.com/AlekSi/pointer v1.2.0 From 43029033e49f732785c004f25ed50ddf7c75717e Mon Sep 17 00:00:00 2001 From: steiler Date: Mon, 9 Feb 2026 09:31:24 +0100 Subject: [PATCH 4/4] remove repetitive call chains --- pkg/server/datastore.go | 49 ++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/pkg/server/datastore.go b/pkg/server/datastore.go index ebdd8e6f..10746556 100644 --- a/pkg/server/datastore.go +++ b/pkg/server/datastore.go @@ -102,53 +102,56 @@ func (s *Server) CreateDataStore(ctx context.Context, req *sdcpb.CreateDataStore return nil, status.Errorf(codes.InvalidArgument, "datastore %s already exists", name) } + reqTarget := req.GetTarget() sbi := &config.SBI{ - Type: req.GetTarget().GetType(), - Port: req.GetTarget().GetPort(), - Address: req.GetTarget().GetAddress(), + Type: reqTarget.GetType(), + Port: reqTarget.GetPort(), + Address: reqTarget.GetAddress(), } - switch strings.ToLower(req.GetTarget().GetType()) { + switch strings.ToLower(reqTarget.GetType()) { case "netconf": + netconfOpts := reqTarget.GetNetconfOpts() commitDatastore := "candidate" - switch req.GetTarget().GetNetconfOpts().GetCommitCandidate() { + switch netconfOpts.GetCommitCandidate() { case sdcpb.CommitCandidate_COMMIT_CANDIDATE: case sdcpb.CommitCandidate_COMMIT_RUNNING: commitDatastore = "running" default: - log.Error(nil, "unknown commitDatastore", "datastore", req.GetTarget().GetNetconfOpts().GetCommitCandidate()) - return nil, fmt.Errorf("unknown commitDatastore: %v", req.GetTarget().GetNetconfOpts().GetCommitCandidate()) + log.Error(nil, "unknown commitDatastore", "datastore", netconfOpts.GetCommitCandidate()) + return nil, fmt.Errorf("unknown commitDatastore: %v", netconfOpts.GetCommitCandidate()) } sbi.NetconfOptions = &config.SBINetconfOptions{ - IncludeNS: req.GetTarget().GetNetconfOpts().GetIncludeNs(), - OperationWithNamespace: req.GetTarget().GetNetconfOpts().GetOperationWithNs(), - UseOperationRemove: req.GetTarget().GetNetconfOpts().GetUseOperationRemove(), + IncludeNS: netconfOpts.GetIncludeNs(), + OperationWithNamespace: netconfOpts.GetOperationWithNs(), + UseOperationRemove: netconfOpts.GetUseOperationRemove(), CommitDatastore: commitDatastore, } case "gnmi": + gnmiOpts := reqTarget.GetGnmiOpts() sbi.GnmiOptions = &config.SBIGnmiOptions{ - Encoding: req.GetTarget().GetGnmiOpts().GetEncoding(), - TargetName: req.GetTarget().GetGnmiOpts().GetTargetName(), + Encoding: gnmiOpts.GetEncoding(), + TargetName: gnmiOpts.GetTargetName(), } default: - log.Error(nil, "unknowm targetconnection protocol type", "type", req.GetTarget().GetType()) - return nil, fmt.Errorf("unknowm targetconnection protocol type %s", req.GetTarget().GetType()) + log.Error(nil, "unknowm targetconnection protocol type", "type", reqTarget.GetType()) + return nil, fmt.Errorf("unknowm targetconnection protocol type %s", reqTarget.GetType()) } - if req.GetTarget().GetTls() != nil { + if tls := reqTarget.GetTls(); tls != nil { sbi.TLS = &config.TLS{ - CA: req.GetTarget().GetTls().GetCa(), - Cert: req.GetTarget().GetTls().GetCert(), - Key: req.GetTarget().GetTls().GetKey(), - SkipVerify: req.GetTarget().GetTls().GetSkipVerify(), + CA: tls.GetCa(), + Cert: tls.GetCert(), + Key: tls.GetKey(), + SkipVerify: tls.GetSkipVerify(), } } - if req.GetTarget().GetCredentials() != nil { + if creds := reqTarget.GetCredentials(); creds != nil { sbi.Credentials = &config.Creds{ - Username: req.GetTarget().GetCredentials().GetUsername(), - Password: req.GetTarget().GetCredentials().GetPassword(), - Token: req.GetTarget().GetCredentials().GetToken(), + Username: creds.GetUsername(), + Password: creds.GetPassword(), + Token: creds.GetToken(), } }