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 {
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{}
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)