From: Michael Cambria Date: Tue, 16 Apr 2019 18:44:46 +0000 (-0400) Subject: Removed original ping service X-Git-Url: https://git.halfball.org/?a=commitdiff_plain;h=7b4fc73734381777270545bb55ddf2f6a4dc279e;p=demo-grpc.git Removed original ping service --- diff --git a/api/api.proto b/api/api.proto index 81596ca..11dc5af 100644 --- a/api/api.proto +++ b/api/api.proto @@ -3,23 +3,14 @@ package api; import "google/api/annotations.proto"; -message PingMessage { - string greeting = 1; -} - -service Ping { - rpc SayHello(PingMessage) returns (PingMessage) { - option (google.api.http) = { - post: "/1/ping" - body: "*" - }; - } -} - - service CNIserver { // Process CNI message - rpc CNIop (CNImsg) returns (CNIresult) {} + rpc CNIop (CNImsg) returns (CNIresult) { + option (google.api.http) = { + post: "/1/cni" + body: "*" + }; + } } enum CmdType { diff --git a/api/handler.go b/api/handler.go index 5026e61..07023cb 100644 --- a/api/handler.go +++ b/api/handler.go @@ -6,16 +6,6 @@ import ( "golang.org/x/net/context" ) -// Server represents the gRPC server -type Server struct { -} - -// SayHello generates response to a Ping request -func (s *Server) SayHello(ctx context.Context, in *PingMessage) (*PingMessage, error) { - log.Printf("Receive message %s", in.Greeting) - return &PingMessage{Greeting: "bar"}, nil -} - // Server represents the gRPC server type CNIServer struct { } diff --git a/client/main.go b/client/main.go index d28af2d..a2fc3db 100644 --- a/client/main.go +++ b/client/main.go @@ -50,16 +50,6 @@ func main() { } defer conn.Close() -/* - c := api.NewPingClient(conn) - - response, err := c.SayHello(context.Background(), &api.PingMessage{Greeting: "foo"}) - if err != nil { - log.Fatalf("error when calling SayHello: %s", err) - } - log.Printf("Response from server: %s", response.Greeting) -*/ - // CNI Test cni := api.NewCNIserverClient(conn) diff --git a/server/main.go b/server/main.go index 162b303..658e889 100644 --- a/server/main.go +++ b/server/main.go @@ -31,44 +31,6 @@ func credMatcher(headerName string) (mdName string, ok bool) { return "", false } -/* -// authenticateAgent check the client credentials -func authenticateClient(ctx context.Context, s *api.Server) (string, error) { - if md, ok := metadata.FromIncomingContext(ctx); ok { - clientLogin := strings.Join(md["login"], "") - clientPassword := strings.Join(md["password"], "") - - if clientLogin != "john" { - return "", fmt.Errorf("unknown user %s", clientLogin) - } - if clientPassword != "doe" { - return "", fmt.Errorf("bad password %s", clientPassword) - } - - log.Printf("authenticated client: %s", clientLogin) - - return "42", nil - } - return "", fmt.Errorf("missing credentials") -} - -// unaryInterceptor call authenticateClient with current context -func unaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - s, ok := info.Server.(*api.Server) - if !ok { - return nil, fmt.Errorf("unable to cast server") - } - clientID, err := authenticateClient(ctx, s) - if err != nil { - return nil, err - } - - ctx = context.WithValue(ctx, clientIDKey, clientID) - - return handler(ctx, req) -} -*/ - // authenticateAgent check the client credentials func authenticateClient(ctx context.Context, s *api.CNIServer) (string, error) { if md, ok := metadata.FromIncomingContext(ctx); ok { @@ -112,34 +74,6 @@ func startGRPCServer(address, certFile, keyFile string) error { return fmt.Errorf("failed to listen: %v", err) } -/* - // create a server instance - s := api.Server{} - - // Create the TLS credentials - creds, err := credentials.NewServerTLSFromFile(certFile, keyFile) - if err != nil { - return fmt.Errorf("could not load TLS keys: %s", err) - } - - // Create an array of gRPC options with the credentials - opts := []grpc.ServerOption{grpc.Creds(creds), - grpc.UnaryInterceptor(unaryInterceptor)} - - // create a gRPC server object - grpcServer := grpc.NewServer(opts...) - - // attach the Ping service to the server - api.RegisterPingServer(grpcServer, &s) -*/ -/* - // Original - log.Printf("starting HTTP/2 gRPC server on %s", address) - if err := grpcServer.Serve(lis); err != nil { - return fmt.Errorf("failed to serve: %s", err) - } -*/ - // create a CNI server instance cni := api.CNIServer{} @@ -184,9 +118,10 @@ func startRESTServer(address, grpcAddress, certFile string) error { opts := []grpc.DialOption{grpc.WithTransportCredentials(creds)} // Register ping - err = api.RegisterPingHandlerFromEndpoint(ctx, mux, grpcAddress, opts) + //err = api.RegisterPingHandlerFromEndpoint(ctx, mux, grpcAddress, opts) + err = api.RegisterCNIserverHandlerFromEndpoint(ctx, mux, grpcAddress, opts) if err != nil { - return fmt.Errorf("could not register service Ping: %s", err) + return fmt.Errorf("could not register service CNI: %s", err) } log.Printf("starting HTTP/1.1 REST server on %s", address)