-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add TLS support for REST #32
Conversation
isogram
commented
Nov 21, 2023
- added new three env. USE_REST_TLS, REST_TLS_CERT_FILE, REST_TLS_KEY_FILE
- added logic to serve HTTPS for REST
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #32 +/- ##
==========================================
- Coverage 18.66% 18.57% -0.10%
==========================================
Files 41 41
Lines 2454 2466 +12
==========================================
Hits 458 458
- Misses 1981 1993 +12
Partials 15 15 ☔ View full report in Codecov by Sentry. |
@@ -23,6 +23,9 @@ type ( | |||
jaegerMaxPacketSize int | |||
sharedListener cmux.CMux | |||
graphqlOption graphqlserver.Option | |||
tls bool | |||
certFile string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
langsung pake tlsConfig
aja gimana wa @isogram ?
certFile string | |
tlsConfig *tls.Config |
@@ -138,3 +144,24 @@ func AddGraphQLOption(opts ...graphqlserver.OptionFunc) OptionFunc { | |||
MiddlewareExcludeURLPath[o.graphqlOption.RootPath] = struct{}{} | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yg tambahan disini jadi cukup 1 aja
// SetTLSConfig option func | |
func SetTLSConfig(tlsConfig *tls.Config) OptionFunc { | |
return func(o *option) { | |
o.tlsConfig = tlsConfig | |
} | |
} |
@@ -86,10 +92,44 @@ func NewServer(service factory.ServiceFactory, opts ...OptionFunc) factory.AppSe | |||
|
|||
func (s *restServer) Serve() { | |||
var err error | |||
if s.listener != nil { | |||
err = s.httpEngine.Serve(s.listener) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jadi ketika Serve
cukup begini aja
func (s *restServer) Serve() { | |
var err error | |
if s.listener == nil { | |
s.listener, err = net.Listen("tcp", s.httpEngine.Addr) | |
if err != nil { | |
log.Panicf("REST TCP Listener: Unexpected Error: %v", err) | |
} | |
} | |
if s.opt.tlsConfig != nil { | |
s.httpEngine.TLSConfig = s.opt.tlsConfig | |
s.listener = tls.NewListener(s.listener, s.opt.tlsConfig) | |
} | |
err = s.httpEngine.Serve(s.listener) | |
switch err.(type) { | |
case *net.OpError: | |
log.Panicf("REST Server: Unexpected Error: %v", err) | |
} | |
} |
@@ -44,6 +44,13 @@ type Env struct { | |||
UsePostgresListenerWorker bool | |||
// UseRabbitMQWorker env | |||
UseRabbitMQWorker bool | |||
// UseRESTTls config | |||
UseRESTTls bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dan jadi gaperlu ada tambahan default env
@@ -16,6 +16,9 @@ func SetupRESTServer(service factory.ServiceFactory, opts ...restserver.OptionFu | |||
restserver.SetSharedListener(service.GetConfig().SharedListener), | |||
restserver.SetDebugMode(env.BaseEnv().DebugMode), | |||
restserver.SetJaegerMaxPacketSize(env.BaseEnv().JaegerMaxPacketSize), | |||
restserver.SetTlsOption(env.BaseEnv().UseRESTTls), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jadi yg disini udah gaperlu, cukup lewat configs/app_factory.go
dari sisi app-nya saja
(dari sisi app-nya)
restserver.SetTlsOption(env.BaseEnv().UseRESTTls), | |
if env.BaseEnv().UseREST { | |
apps = append(apps, appfactory.SetupRESTServer(service, restserver.SetTLSConfig(getTLSConfig()))) | |
... |
ok gue PR ke changesnya ke development yak @agungdwiprasetyo |