Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Kelp GUI: add support for providing TLS certificates for KaaS server
Browse files Browse the repository at this point in the history
nikhilsaraf committed Apr 15, 2021
1 parent 3f3d74f commit 5c36ead
Showing 3 changed files with 19 additions and 15 deletions.
23 changes: 11 additions & 12 deletions cmd/server_amd64.go
Original file line number Diff line number Diff line change
@@ -69,6 +69,8 @@ type serverInputOptions struct {
noElectron *bool
disablePubnet *bool
enableKaas *bool
tlsCertFile *string
tlsKeyFile *string
}

// String is the stringer method impl.
@@ -89,6 +91,8 @@ func init() {
options.noElectron = serverCmd.Flags().Bool("no-electron", false, "open in browser instead of using electron, only applies when not in KaaS mode")
options.disablePubnet = serverCmd.Flags().Bool("disable-pubnet", false, "disable pubnet option")
options.enableKaas = serverCmd.Flags().Bool("enable-kaas", false, "enable kelp-as-a-service (KaaS) mode, which does not bring up browser or electron")
options.tlsCertFile = serverCmd.Flags().String("tls-cert-file", "", "path to TLS certificate file")
options.tlsKeyFile = serverCmd.Flags().String("tls-key-file", "", "path to TLS key file")

serverCmd.Run = func(ccmd *cobra.Command, args []string) {
isLocalMode := env == envDev
@@ -404,21 +408,16 @@ func init() {
// gui.FS is automatically compiled based on whether this is a local or deployment build
gui.FileServer(r, "/", gui.FS)

portString := fmt.Sprintf(":%d", *options.port)
log.Printf("starting server on port %d\n", *options.port)

webServer, e := networking.MakeServer()
if e != nil {
log.Fatal(e)
}
threadTracker := multithreading.MakeThreadTracker()
e = threadTracker.TriggerGoroutine(func(inputs []interface{}) {
if isLocalMode {
e1 := http.ListenAndServe(portString, r)
if e1 != nil {
log.Fatal(e1)
}
} else {
e1 := http.ListenAndServe(portString, r)
if e1 != nil {
log.Fatal(e1)
}
e1 := webServer.StartServer(*options.port, *options.tlsCertFile, *options.tlsKeyFile)
if e1 != nil {
log.Fatal(e1)
}
}, nil)
if e != nil {
2 changes: 1 addition & 1 deletion cmd/trade.go
Original file line number Diff line number Diff line change
@@ -873,7 +873,7 @@ func startMonitoringServer(l logger.Logger, botConfig trader.BotConfig) error {
for _, email := range strings.Split(botConfig.AcceptableEmails, ",") {
serverConfig.PermittedEmails[email] = true
}
server, e := networking.MakeServer(serverConfig, []networking.Endpoint{healthEndpoint, metricsEndpoint})
server, e := networking.MakeServerWithGoogleAuth(serverConfig, []networking.Endpoint{healthEndpoint, metricsEndpoint})
if e != nil {
return fmt.Errorf("unable to initialize the metrics server: %s", e)
}
9 changes: 7 additions & 2 deletions support/networking/server.go
Original file line number Diff line number Diff line change
@@ -39,8 +39,13 @@ type server struct {
permittedEmails map[string]bool
}

// MakeServer creates a WebServer that's responsible for serving all the endpoints passed into it.
func MakeServer(cfg *Config, endpoints []Endpoint) (WebServer, error) {
// MakeServer creates a WebServer
func MakeServer() (WebServer, error) {
return MakeServerWithGoogleAuth(&Config{}, []Endpoint{})
}

// MakeServerWithGoogleAuth creates a WebServer that's responsible for serving all the endpoints passed into it with google authentication.
func MakeServerWithGoogleAuth(cfg *Config, endpoints []Endpoint) (WebServer, error) {
mux := new(http.ServeMux)
s := &server{
router: mux,

0 comments on commit 5c36ead

Please sign in to comment.