Skip to content

Commit

Permalink
replace holder for gnoi os server implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdwhdw committed Jan 21, 2025
1 parent 56ad495 commit 36c5498
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
39 changes: 22 additions & 17 deletions gnmi_server/gnoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
gnoi_system_pb "github.com/openconfig/gnoi/system"
gnoi_file_pb "github.com/openconfig/gnoi/file"
gnoi_os_pb "github.com/openconfig/gnoi/os"
log "github.com/golang/glog"
"time"
spb "github.com/sonic-net/sonic-gnmi/proto/gnoi"
Expand Down Expand Up @@ -115,6 +116,10 @@ func KillOrRestartProcess(restart bool, serviceName string) error {
return err
}

func (src *OSServer) Verify(ctx context.Context, req *gnoi_os_pb.VerifyRequest) (*gnoi_os_pb.VerifyResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "")
}

func (srv *SystemServer) KillProcess(ctx context.Context, req *gnoi_system_pb.KillProcessRequest) (*gnoi_system_pb.KillProcessResponse, error) {
_, err := authenticate(srv.config, ctx, true)
if err != nil {
Expand Down Expand Up @@ -286,7 +291,7 @@ func (srv *Server) Authenticate(ctx context.Context, req *spb_jwt.AuthenticateRe
return &spb_jwt.AuthenticateResponse{Token: tokenResp(req.Username, roles)}, nil
}
}

}
return nil, status.Errorf(codes.PermissionDenied, "Invalid Username or Password")

Expand Down Expand Up @@ -314,7 +319,7 @@ func (srv *Server) Refresh(ctx context.Context, req *spb_jwt.RefreshRequest) (*s
if time.Unix(claims.ExpiresAt, 0).Sub(time.Now()) > JwtRefreshInt {
return nil, status.Errorf(codes.InvalidArgument, "Invalid JWT Token")
}

return &spb_jwt.RefreshResponse{Token: tokenResp(claims.Username, claims.Roles)}, nil

}
Expand Down Expand Up @@ -357,13 +362,13 @@ func (srv *Server) CopyConfig(ctx context.Context, req *spb.CopyConfigRequest) (
return nil, err
}
log.V(1).Info("gNOI: Sonic CopyConfig")

resp := &spb.CopyConfigResponse{
Output: &spb.SonicOutput {

},
}

reqstr, err := json.Marshal(req)
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
Expand All @@ -373,12 +378,12 @@ func (srv *Server) CopyConfig(ctx context.Context, req *spb.CopyConfigRequest) (
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
}

err = json.Unmarshal(jsresp, resp)
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
}

return resp, nil
}

Expand All @@ -388,7 +393,7 @@ func (srv *Server) ShowTechsupport(ctx context.Context, req *spb.TechsupportRequ
return nil, err
}
log.V(1).Info("gNOI: Sonic ShowTechsupport")

resp := &spb.TechsupportResponse{
Output: &spb.TechsupportResponse_Output {

Expand All @@ -404,13 +409,13 @@ func (srv *Server) ShowTechsupport(ctx context.Context, req *spb.TechsupportRequ
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
}

err = json.Unmarshal(jsresp, resp)
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
}


return resp, nil
}

Expand All @@ -420,7 +425,7 @@ func (srv *Server) ImageInstall(ctx context.Context, req *spb.ImageInstallReques
return nil, err
}
log.V(1).Info("gNOI: Sonic ImageInstall")

resp := &spb.ImageInstallResponse{
Output: &spb.SonicOutput {

Expand All @@ -436,13 +441,13 @@ func (srv *Server) ImageInstall(ctx context.Context, req *spb.ImageInstallReques
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
}

err = json.Unmarshal(jsresp, resp)
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
}


return resp, nil
}

Expand All @@ -452,7 +457,7 @@ func (srv *Server) ImageRemove(ctx context.Context, req *spb.ImageRemoveRequest)
return nil, err
}
log.V(1).Info("gNOI: Sonic ImageRemove")

resp := &spb.ImageRemoveResponse{
Output: &spb.SonicOutput {

Expand All @@ -468,7 +473,7 @@ func (srv *Server) ImageRemove(ctx context.Context, req *spb.ImageRemoveRequest)
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
}

err = json.Unmarshal(jsresp, resp)
if err != nil {
return nil, status.Error(codes.Unknown, err.Error())
Expand All @@ -482,7 +487,7 @@ func (srv *Server) ImageDefault(ctx context.Context, req *spb.ImageDefaultReques
return nil, err
}
log.V(1).Info("gNOI: Sonic ImageDefault")

resp := &spb.ImageDefaultResponse{
Output: &spb.SonicOutput {

Expand All @@ -504,6 +509,6 @@ func (srv *Server) ImageDefault(ctx context.Context, req *spb.ImageDefaultReques
return nil, status.Error(codes.Unknown, err.Error())
}


return resp, nil
}
9 changes: 9 additions & 0 deletions gnmi_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
gnmi_extpb "github.com/openconfig/gnmi/proto/gnmi_ext"
gnoi_system_pb "github.com/openconfig/gnoi/system"
gnoi_file_pb "github.com/openconfig/gnoi/file"
gnoi_os_pb "github.com/openconfig/gnoi/os"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -70,6 +71,14 @@ type SystemServer struct {
gnoi_system_pb.UnimplementedSystemServer
}

// OSServer is the server API for System service.
// All implementations must embed UnimplementedSystemServer
// for forward compatibility
type OSServer struct {
*Server
gnoi_os_pb.UnimplementedOSServer
}

type AuthTypes map[string]bool

// Config is a collection of values for Server
Expand Down

0 comments on commit 36c5498

Please sign in to comment.