Skip to content

Commit

Permalink
feat: support HTTPS in webui (#247)
Browse files Browse the repository at this point in the history
* add HTTPS feature

Signed-off-by: Patricia Reinoso <[email protected]>

* remove tls condition to initialize http2 service

Signed-off-by: Patricia Reinoso <[email protected]>

* create minor release

Signed-off-by: Patricia Reinoso <[email protected]>

---------

Signed-off-by: Patricia Reinoso <[email protected]>
  • Loading branch information
patriciareinoso authored Nov 13, 2024
1 parent 7374518 commit 4d520d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.3-dev
1.8.0
9 changes: 4 additions & 5 deletions backend/factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@ type Info struct {
}

type Configuration struct {
WebServer *WebServer `yaml:"WebServer,omitempty"`
Mongodb *Mongodb `yaml:"mongodb"`
RocEnd *RocEndpt `yaml:"managedByConfigPod,omitempty"` // fetch config during bootup
LteEnd []*LteEndpt `yaml:"endpoints,omitempty"` // LTE endpoints are configured and not auto-detected
TLS *TLS `yaml:"tls"`
Mode5G bool `yaml:"mode5G,omitempty"`
SdfComp bool `yaml:"spec-compliant-sdf"`
EnableAuthentication bool `yaml:"enableAuthentication,omitempty"`
CfgPort int `yaml:"cfgport,omitempty"`
}

type WebServer struct {
Scheme string `yaml:"scheme"`
IP string `yaml:"ipv4Address"`
PORT string `yaml:"port"`
type TLS struct {
PEM string `yaml:"pem,omitempty"`
Key string `yaml:"key,omitempty"`
}

type Mongodb struct {
Expand Down
6 changes: 6 additions & 0 deletions backend/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func InitConfigFactory(f string) error {
if yamlErr := yaml.Unmarshal(content, WebUIConfig); yamlErr != nil {
return fmt.Errorf("[Configuration] %+v", yamlErr)
}
if WebUIConfig.Configuration.TLS != nil {
if WebUIConfig.Configuration.TLS.Key == "" ||
WebUIConfig.Configuration.TLS.PEM == "" {
return fmt.Errorf("[Configuration] TLS Key and PEM must be set")
}
}
if WebUIConfig.Configuration.Mongodb.AuthUrl == "" {
authUrl := WebUIConfig.Configuration.Mongodb.Url
WebUIConfig.Configuration.Mongodb.AuthUrl = authUrl
Expand Down
9 changes: 6 additions & 3 deletions backend/webui_service/webui_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,22 @@ func (webui *WEBUI) Start() {
go func() {
httpAddr := ":" + strconv.Itoa(factory.WebUIConfig.Configuration.CfgPort)
logger.InitLog.Infoln("Webui HTTP addr", httpAddr)
tlsConfig := factory.WebUIConfig.Configuration.TLS
if factory.WebUIConfig.Info.HttpVersion == 2 {
server, err := http2_util.NewServer(httpAddr, "", subconfig_router)
if server == nil {
logger.InitLog.Errorln("initialize HTTP-2 server failed:", err)
return
}

if err != nil {
logger.InitLog.Warnln("initialize HTTP-2 server:", err)
return
}

err = server.ListenAndServe()
if tlsConfig != nil {
err = server.ListenAndServeTLS(tlsConfig.PEM, tlsConfig.Key)
} else {
err = server.ListenAndServe()
}
if err != nil {
logger.InitLog.Fatalln("HTTP server setup failed:", err)
return
Expand Down

0 comments on commit 4d520d7

Please sign in to comment.