Skip to content

Commit

Permalink
Revert "feat: add new non TLS grpc server for healthcheck"
Browse files Browse the repository at this point in the history
This reverts commit 9184d0e.
  • Loading branch information
Siddhanta Rath committed Dec 19, 2023
1 parent 9184d0e commit a32d2a1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 77 deletions.
3 changes: 0 additions & 3 deletions config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type serverWs struct {

type serverGRPC struct {
Port string
TLSPort string
TLSEnabled bool
TLSCertPath string
TLSPublicKey string
Expand Down Expand Up @@ -76,13 +75,11 @@ func serverWsConfigLoader() {

func serverGRPCConfigLoader() {
viper.SetDefault("SERVER_GRPC_PORT", "8081")
viper.SetDefault("SERVER_GRPC_TLS_PORT", "8443")
viper.SetDefault("SERVER_GRPC_TLS_ENABLED", false)
viper.SetDefault("SERVER_GRPC_TLS_CERT_PATH", "cert/server.crt")
viper.SetDefault("SERVER_GRPC_TLS_PUBLIC_KEY", "cert/server.key")
ServerGRPC = serverGRPC{
Port: util.MustGetString("SERVER_GRPC_PORT"),
TLSPort: util.MustGetString("SERVER_GRPC_TLS_PORT"),
TLSEnabled: util.MustGetBool("SERVER_GRPC_TLS_ENABLED"),
TLSCertPath: util.MustGetString("SERVER_GRPC_TLS_CERT_PATH"),
TLSPublicKey: util.MustGetString("SERVER_GRPC_TLS_PUBLIC_KEY"),
Expand Down
19 changes: 19 additions & 0 deletions services/grpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package grpc

import (
"context"
"crypto/tls"
"fmt"
"google.golang.org/grpc/credentials"
"net"

pbgrpc "buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/raccoon/v1beta1/raccoonv1beta1grpc"
Expand Down Expand Up @@ -43,5 +45,22 @@ func (s *Service) Shutdown(context.Context) error {
}

func newGRPCServer() *grpc.Server {
if config.ServerGRPC.TLSEnabled {
return grpc.NewServer(grpc.Creds(loadTLSCredentials()))
}
return grpc.NewServer()
}

func loadTLSCredentials() credentials.TransportCredentials {
serverCert, err := tls.LoadX509KeyPair(config.ServerGRPC.TLSCertPath, config.ServerGRPC.TLSPublicKey)
if err != nil {
panic("failed to load TLS credentials to start grpc server with TLS")
}

config := &tls.Config{
Certificates: []tls.Certificate{serverCert},
ClientAuth: tls.NoClientCert,
}

return credentials.NewTLS(config)
}
62 changes: 0 additions & 62 deletions services/grpc/serviceWithTLS.go

This file was deleted.

12 changes: 0 additions & 12 deletions services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package services

import (
"context"
"github.com/goto/raccoon/config"
"net/http"

"github.com/goto/raccoon/collection"
Expand Down Expand Up @@ -46,17 +45,6 @@ func (s *Services) Shutdown(ctx context.Context) {

func Create(b chan collection.CollectRequest) Services {
c := collection.NewChannelCollector(b)
if config.ServerGRPC.TLSEnabled {
return Services{
b: []bootstrapper{
//running non TLS service to do health check on the probe
grpc.NewGRPCService(c),
grpc.NewGRPCServiceWithTLS(c),
pprof.NewPprofService(),
rest.NewRestService(c),
},
}
}
return Services{
b: []bootstrapper{
grpc.NewGRPCService(c),
Expand Down

0 comments on commit a32d2a1

Please sign in to comment.