Skip to content
Snippets Groups Projects

Fix wrong type assertion for gnmi version within capabilities

Merged Malte Bauch requested to merge fix-capabilities into master
All threads resolved!
1 file
+ 6
22
Compare changes
  • Side-by-side
  • Inline
@@ -17,11 +17,8 @@ limitations under the License.
@@ -17,11 +17,8 @@ limitations under the License.
package gnmiserver
package gnmiserver
import (
import (
"bytes"
"compress/gzip"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io"
"reflect"
"reflect"
"strconv"
"strconv"
"time"
"time"
@@ -39,7 +36,6 @@ import (
@@ -39,7 +36,6 @@ import (
"code.fbi.h-da.de/danet/gnmi-target/handler"
"code.fbi.h-da.de/danet/gnmi-target/handler"
not "code.fbi.h-da.de/danet/gnmi-target/internal/notifications"
not "code.fbi.h-da.de/danet/gnmi-target/internal/notifications"
dpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/gnmi/proto/gnmi"
pb "github.com/openconfig/gnmi/proto/gnmi"
pb "github.com/openconfig/gnmi/proto/gnmi"
)
)
@@ -415,23 +411,11 @@ func (s *Server) toGoStruct(jsonTree map[string]interface{}) (ygot.ValidatedGoSt
@@ -415,23 +411,11 @@ func (s *Server) toGoStruct(jsonTree map[string]interface{}) (ygot.ValidatedGoSt
// TODO: Fix the deprecated path.GetElement
// TODO: Fix the deprecated path.GetElement
//
//
//nolint:all
//nolint:all
func getGNMIServiceVersion() (*string, error) {
func getGNMIServiceVersion() (string, error) {
gzB, _ := (&pb.Update{}).Descriptor()
gzB := (&pb.Update{}).ProtoReflect().Descriptor()
r, err := gzip.NewReader(bytes.NewReader(gzB))
parentOptions := gzB.Parent().Options()
if err != nil {
ver := proto.GetExtension(parentOptions, pb.E_GnmiService)
return nil, fmt.Errorf("error in initializing gzip reader: %w", err)
return ver.(string), nil
}
defer r.Close() //nolint:errcheck
b, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("error in reading gzip data: %w", err)
}
desc := &dpb.FileDescriptorProto{}
if err := proto.Unmarshal(b, desc); err != nil {
return nil, fmt.Errorf("error in unmarshaling proto: %w", err)
}
ver := proto.GetExtension(desc.Options, pb.E_GnmiService)
return ver.(*string), nil
}
}
// deleteKeyedListEntry deletes the keyed list entry from node that matches the
// deleteKeyedListEntry deletes the keyed list entry from node that matches the
@@ -572,7 +556,7 @@ func (s *Server) Capabilities(ctx context.Context, req *pb.CapabilityRequest) (*
@@ -572,7 +556,7 @@ func (s *Server) Capabilities(ctx context.Context, req *pb.CapabilityRequest) (*
return &pb.CapabilityResponse{
return &pb.CapabilityResponse{
SupportedModels: s.model.modelData,
SupportedModels: s.model.modelData,
SupportedEncodings: supportedEncodings,
SupportedEncodings: supportedEncodings,
GNMIVersion: *ver,
GNMIVersion: ver,
}, nil
}, nil
}
}
Loading