diff --git a/core/pkg/runtime/from_config.go b/core/pkg/runtime/from_config.go index cccf8df3d..9146def35 100644 --- a/core/pkg/runtime/from_config.go +++ b/core/pkg/runtime/from_config.go @@ -75,12 +75,6 @@ func FromConfig(logger *logger.Logger, config Config) (*Runtime, error) { func (r *Runtime) setService(logger *logger.Logger) { r.Service = &service.ConnectService{ - ConnectServiceConfiguration: &service.ConnectServiceConfiguration{ - ServerKeyPath: r.config.ServiceKeyPath, - ServerCertPath: r.config.ServiceCertPath, - ServerSocketPath: r.config.ServiceSocketPath, - CORS: r.config.CORS, - }, Logger: logger.WithFields( zap.String("component", "service"), ), diff --git a/core/pkg/runtime/runtime.go b/core/pkg/runtime/runtime.go index ccfb2f929..db305e473 100644 --- a/core/pkg/runtime/runtime.go +++ b/core/pkg/runtime/runtime.go @@ -95,6 +95,10 @@ func (r *Runtime) Start() error { Port: r.config.ServicePort, MetricsPort: r.config.MetricsPort, ServiceName: r.serviceName, + KeyPath: r.config.ServiceKeyPath, + CertPath: r.config.ServiceCertPath, + SocketPath: r.config.ServiceSocketPath, + CORS: r.config.CORS, }) }) <-gCtx.Done() diff --git a/core/pkg/service/flag-evaluation/connect_service.go b/core/pkg/service/flag-evaluation/connect_service.go index 42382f713..9e1d3bd53 100644 --- a/core/pkg/service/flag-evaluation/connect_service.go +++ b/core/pkg/service/flag-evaluation/connect_service.go @@ -26,18 +26,11 @@ import ( const ErrorPrefix = "FlagdError:" type ConnectService struct { - ConnectServiceConfiguration *ConnectServiceConfiguration - Eval eval.IEvaluator - Logger *logger.Logger - Metrics *otel.MetricsRecorder - eventingConfiguration *eventingConfiguration - server http.Server -} -type ConnectServiceConfiguration struct { - ServerCertPath string - ServerKeyPath string - ServerSocketPath string - CORS []string + Logger *logger.Logger + Eval eval.IEvaluator + Metrics *otel.MetricsRecorder + eventingConfiguration *eventingConfiguration + server http.Server } func (s *ConnectService) Serve(ctx context.Context, eval eval.IEvaluator, svcConf service.Configuration) error { @@ -54,11 +47,11 @@ func (s *ConnectService) Serve(ctx context.Context, eval eval.IEvaluator, svcCon errChan := make(chan error, 1) go func() { s.Logger.Info(fmt.Sprintf("Flag Evaluation listening at %s", lis.Addr())) - if s.ConnectServiceConfiguration.ServerCertPath != "" && s.ConnectServiceConfiguration.ServerKeyPath != "" { + if svcConf.CertPath != "" && svcConf.KeyPath != "" { if err := s.server.ServeTLS( lis, - s.ConnectServiceConfiguration.ServerCertPath, - s.ConnectServiceConfiguration.ServerKeyPath, + svcConf.CertPath, + svcConf.KeyPath, ); err != nil && !errors.Is(err, http.ErrServerClosed) { errChan <- err } @@ -84,8 +77,8 @@ func (s *ConnectService) setupServer(svcConf service.Configuration) (net.Listene var lis net.Listener var err error mux := http.NewServeMux() - if s.ConnectServiceConfiguration.ServerSocketPath != "" { - lis, err = net.Listen("unix", s.ConnectServiceConfiguration.ServerSocketPath) + if svcConf.SocketPath != "" { + lis, err = net.Listen("unix", svcConf.SocketPath) } else { address := fmt.Sprintf(":%d", svcConf.Port) lis, err = net.Listen("tcp", address) @@ -110,11 +103,11 @@ func (s *ConnectService) setupServer(svcConf service.Configuration) (net.Listene go bindMetrics(s, svcConf) - if s.ConnectServiceConfiguration.ServerCertPath != "" && s.ConnectServiceConfiguration.ServerKeyPath != "" { - handler = s.newCORS().Handler(h) + if svcConf.CertPath != "" && svcConf.KeyPath != "" { + handler = s.newCORS(svcConf).Handler(h) } else { handler = h2c.NewHandler( - s.newCORS().Handler(h), + s.newCORS(svcConf).Handler(h), &http2.Server{}, ) } @@ -133,7 +126,7 @@ func (s *ConnectService) Notify(n service.Notification) { } } -func (s *ConnectService) newCORS() *cors.Cors { +func (s *ConnectService) newCORS(svcConf service.Configuration) *cors.Cors { return cors.New(cors.Options{ AllowedMethods: []string{ http.MethodHead, @@ -143,7 +136,7 @@ func (s *ConnectService) newCORS() *cors.Cors { http.MethodPatch, http.MethodDelete, }, - AllowedOrigins: s.ConnectServiceConfiguration.CORS, + AllowedOrigins: svcConf.CORS, AllowedHeaders: []string{"*"}, ExposedHeaders: []string{ // Content-Type is in the default safelist. diff --git a/core/pkg/service/flag-evaluation/connect_service_test.go b/core/pkg/service/flag-evaluation/connect_service_test.go index e879946fd..84668c2b7 100644 --- a/core/pkg/service/flag-evaluation/connect_service_test.go +++ b/core/pkg/service/flag-evaluation/connect_service_test.go @@ -76,9 +76,6 @@ func TestConnectService_UnixConnection(t *testing.T) { exp := metric.NewManualReader() metricRecorder := otel.NewOTelRecorder(exp, tt.name) svc := ConnectService{ - ConnectServiceConfiguration: &ConnectServiceConfiguration{ - ServerSocketPath: tt.socketPath, - }, Logger: logger.NewLogger(nil, false), Metrics: metricRecorder, } @@ -86,6 +83,7 @@ func TestConnectService_UnixConnection(t *testing.T) { ReadinessProbe: func() bool { return true }, + SocketPath: tt.socketPath, } ctx := context.Background() ctx, cancel := context.WithTimeout(ctx, 5*time.Second) diff --git a/core/pkg/service/iservice.go b/core/pkg/service/iservice.go index 72d08f873..271d31e12 100644 --- a/core/pkg/service/iservice.go +++ b/core/pkg/service/iservice.go @@ -26,6 +26,10 @@ type Configuration struct { Port uint16 MetricsPort uint16 ServiceName string + CertPath string + KeyPath string + SocketPath string + CORS []string } /*