Skip to content

Commit

Permalink
Make sansshell service easier to follow. (#165)
Browse files Browse the repository at this point in the history
This was confusing since the server def was stuffed into logging along with the Version var.

Put Version with version.go
Move generic server parts into server.go
  • Loading branch information
sfc-gh-jchacon authored Sep 23, 2022
1 parent 18d5130 commit 5b3889d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
29 changes: 0 additions & 29 deletions services/sansshell/server/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,14 @@ package server

import (
"context"
"sync"

"github.com/go-logr/logr"
"github.com/go-logr/stdr"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/Snowflake-Labs/sansshell/services"
pb "github.com/Snowflake-Labs/sansshell/services/sansshell"
)

var (
// Version is the value returned by the Version RPC service.
// This should likely be set as a linker option from external
// input such as a git SHA or RPM version number.
// go build -ldflags="-X github.com/Snowflake-Labs/sansshell/services/sansshell/server.Version=..."
//
// NOTE: This is a var so the linker can set it but in reality it's a const so treat as such.
Version string
)

// Server is used to implement the gRPC Server
type Server struct {
mu sync.RWMutex
lastVal int32
}

// SetVerbosity sets the logging level and returns the last value before this was called.
func (s *Server) SetVerbosity(ctx context.Context, req *pb.SetVerbosityRequest) (*pb.VerbosityReply, error) {
s.mu.Lock()
Expand All @@ -66,13 +47,3 @@ func (s *Server) GetVerbosity(ctx context.Context, req *emptypb.Empty) (*pb.Verb
defer s.mu.RUnlock()
return &pb.VerbosityReply{Level: s.lastVal}, nil
}

// Register is called to expose this handler to the gRPC server
func (s *Server) Register(gs *grpc.Server) {
pb.RegisterLoggingServer(gs, s)
pb.RegisterStateServer(gs, s)
}

func init() {
services.RegisterSansShellService(&Server{})
}
43 changes: 43 additions & 0 deletions services/sansshell/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright (c) 2019 Snowflake Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

// Package server implements the sansshell 'Logging' service.
package server

import (
"sync"

"google.golang.org/grpc"

"github.com/Snowflake-Labs/sansshell/services"
pb "github.com/Snowflake-Labs/sansshell/services/sansshell"
)

// Server is used to implement the gRPC Server
type Server struct {
mu sync.RWMutex
lastVal int32
}

// Register is called to expose this handler to the gRPC server
func (s *Server) Register(gs *grpc.Server) {
pb.RegisterLoggingServer(gs, s)
pb.RegisterStateServer(gs, s)
}

func init() {
services.RegisterSansShellService(&Server{})
}
10 changes: 10 additions & 0 deletions services/sansshell/server/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ import (
pb "github.com/Snowflake-Labs/sansshell/services/sansshell"
)

var (
// Version is the value returned by the Version RPC service.
// This should likely be set as a linker option from external
// input such as a git SHA or RPM version number.
// go build -ldflags="-X github.com/Snowflake-Labs/sansshell/services/sansshell/server.Version=..."
//
// NOTE: This is a var so the linker can set it but in reality it's a const so treat as such.
Version string
)

func (s *Server) Version(ctx context.Context, req *emptypb.Empty) (*pb.VersionResponse, error) {
return &pb.VersionResponse{
Version: Version,
Expand Down

0 comments on commit 5b3889d

Please sign in to comment.