Skip to content

Commit

Permalink
feat: Add new go build tag no_openziti to reduce build size
Browse files Browse the repository at this point in the history
realetd to edgexfoundry/go-mod-bootstrap#795

As go-mod-bootstrap is updated with new build tag no_openziti with some
code refactor, the app-functions-sdk-go also needs to be updated per the
refactor.

Signed-off-by: Jude Hung <jude@iotechsys.com>
  • Loading branch information
judehung committed Nov 9, 2024
1 parent 374b1e2 commit f0bbda1
Showing 1 changed file with 1 addition and 43 deletions.
44 changes: 1 addition & 43 deletions internal/webserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ package webserver
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"strings"
"time"

"github.com/edgexfoundry/app-functions-sdk-go/v4/internal"
Expand All @@ -30,8 +28,6 @@ import (
"github.com/edgexfoundry/app-functions-sdk-go/v4/pkg/interfaces"
bootstrapContainer "github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/container"
"github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/controller"

bscfg "github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/config"
bootstrapHandlers "github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/handlers"
"github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/utils"
"github.com/edgexfoundry/go-mod-bootstrap/v4/bootstrap/zerotrust"
Expand Down Expand Up @@ -127,45 +123,7 @@ func (webserver *WebServer) listenAndServe(serviceTimeout time.Duration, errChan
}
addr := fmt.Sprintf("%s:%d", bindAddress, config.Service.Port)

var ln net.Listener
var err error
listenMode := strings.ToLower(config.Service.SecurityOptions[bscfg.SecurityModeKey])
switch listenMode {
case zerotrust.ZeroTrustMode:
ozUrl := config.Service.SecurityOptions["OpenZitiController"]

secretProvider := bootstrapContainer.SecretProviderExtFrom(webserver.dic.Get)
ozToken, jwtErr := secretProvider.GetSelfJWT()
if jwtErr != nil {
lc.Errorf("zero trust mode enabled, but could not load jwt: %v", jwtErr)
errChannel <- jwtErr
return
}

ctx, authErr := zerotrust.AuthToOpenZiti(ozUrl, ozToken)
if authErr != nil {
lc.Errorf("could not authenticate to OpenZiti: %v", authErr)
errChannel <- authErr
return
}

ozServiceName := zerotrust.OpenZitiServicePrefix + webserver.serviceName
lc.Infof("Using OpenZiti service name: %s", ozServiceName)
lc.Infof("listening on overlay network. ListenMode '%s' at %s", listenMode, addr)
ln, err = ctx.Listen(ozServiceName)

if err != nil {
lc.Errorf("could not bind service %s: %v", ozServiceName, err)
errChannel <- err
return
}

case "http":
fallthrough
default:
lc.Infof("listening on underlay network. ListenMode '%s' at %s", listenMode, addr)
ln, err = net.Listen("tcp", addr)
}
ln, err := zerotrust.SetupWebListener(config.Service, webserver.serviceName, addr, webserver.dic)
if err != nil {
lc.Errorf("could not start web listener: %v", err)
errChannel <- err
Expand Down

0 comments on commit f0bbda1

Please sign in to comment.