server, service: added running as effective user
This commit is contained in:
+6
-22
@@ -4,12 +4,10 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"helmet/app/logger"
|
||||
|
||||
"helmet/app/handler"
|
||||
"helmet/app/logger"
|
||||
"helmet/app/operator"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
@@ -22,8 +20,7 @@ import (
|
||||
type ServiceConfig struct {
|
||||
Handler *handler.Handler
|
||||
Operator *operator.Operator
|
||||
PortNum uint32
|
||||
Hostname string
|
||||
Listener net.Listener
|
||||
X509Cert []byte
|
||||
X509Key []byte
|
||||
}
|
||||
@@ -33,11 +30,7 @@ type Service struct {
|
||||
hand *handler.Handler
|
||||
oper *operator.Operator
|
||||
log *logger.Logger
|
||||
portnum uint32
|
||||
hostname string
|
||||
|
||||
username string
|
||||
password string
|
||||
listen net.Listener
|
||||
x509Cert []byte
|
||||
x509Key []byte
|
||||
}
|
||||
@@ -46,8 +39,7 @@ func NewService(conf *ServiceConfig) *Service {
|
||||
svc := Service{
|
||||
hand: conf.Handler,
|
||||
oper: conf.Operator,
|
||||
portnum: conf.PortNum,
|
||||
hostname: conf.Hostname,
|
||||
listen: conf.Listener,
|
||||
x509Cert: conf.X509Cert,
|
||||
x509Key: conf.X509Key,
|
||||
}
|
||||
@@ -60,12 +52,6 @@ func (svc *Service) Run() error {
|
||||
var err error
|
||||
svc.log.Infof("Service run")
|
||||
|
||||
listenSpec := fmt.Sprintf(":%d", svc.portnum)
|
||||
listener, err := net.Listen("tcp", listenSpec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tlsCert, err := tls.X509KeyPair(svc.x509Cert, svc.x509Key)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -75,7 +61,6 @@ func (svc *Service) Run() error {
|
||||
ClientAuth: tls.NoClientCert,
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
||||
tlsCredentials := credentials.NewTLS(&tlsConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -87,14 +72,13 @@ func (svc *Service) Run() error {
|
||||
gsrvOpts := []grpc.ServerOption{
|
||||
grpc.Creds(tlsCredentials),
|
||||
grpc.ChainUnaryInterceptor(interceptors...),
|
||||
//grpc.UnaryInterceptor(svc.authInterceptor),
|
||||
}
|
||||
svc.gsrv = grpc.NewServer(gsrvOpts...)
|
||||
|
||||
svc.hand.Register(svc.gsrv)
|
||||
|
||||
svc.log.Infof("Service listening at %v", listener.Addr())
|
||||
err = svc.gsrv.Serve(listener)
|
||||
svc.log.Infof("Service listening at %v", svc.listen.Addr())
|
||||
err = svc.gsrv.Serve(svc.listen)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user