Skip to content

Commit

Permalink
feat: Add service key to HTTP Server (#679)
Browse files Browse the repository at this point in the history
* feat: add service key to http server

* fix: update ozServiceName generation

* fix: use a constant for prefix and remove unused constant

Signed-off-by: dovholuknf <[email protected]>
  • Loading branch information
dovholuknf authored Mar 20, 2024
1 parent 8d0240b commit 29e6be3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions bootstrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ const (
appServicesKey = "app-services"
deviceServicesKey = "device-services"

SecurityModeKey = "Mode"
OpenZitiServiceNameKey = "OpenZitiServiceName"
SecurityModeKey = "Mode"
)

var invalidRemoteHostsError = errors.New("-rsh/--remoteServiceHosts must contain 3 and only 3 comma seperated host names")
Expand Down
11 changes: 7 additions & 4 deletions bootstrap/handlers/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type HttpServer struct {
router *echo.Echo
isRunning bool
doListenAndServe bool
serverKey string
}

type ZitiContext struct {
Expand All @@ -59,11 +60,12 @@ type ZitiContext struct {
type OpenZitiIdentityKey struct{}

// NewHttpServer is a factory method that returns an initialized HttpServer receiver struct.
func NewHttpServer(router *echo.Echo, doListenAndServe bool) *HttpServer {
func NewHttpServer(router *echo.Echo, doListenAndServe bool, serviceKey string) *HttpServer {
return &HttpServer{
router: router,
isRunning: false,
doListenAndServe: doListenAndServe,
serverKey: serviceKey,
}
}

Expand Down Expand Up @@ -214,10 +216,11 @@ func (b *HttpServer) BootstrapHandler(
break
}

serviceName := bootstrapConfig.Service.SecurityOptions[config.OpenZitiServiceNameKey]
ln, listenErr := zitiCtx.Listen(serviceName)
ozServiceName := zerotrust.OpenZitiServicePrefix + b.serverKey
lc.Infof("Using OpenZiti service name: %s", ozServiceName)
ln, listenErr := zitiCtx.Listen(ozServiceName)
if listenErr != nil {
err = fmt.Errorf("could not bind service " + serviceName + ": " + listenErr.Error())
err = fmt.Errorf("could not bind service " + ozServiceName + ": " + listenErr.Error())
break
}

Expand Down
1 change: 1 addition & 0 deletions bootstrap/zerotrust/zerotrust.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
const (
OpenZitiControllerKey = "OpenZitiController"
ZeroTrustMode = "zerotrust"
OpenZitiServicePrefix = "edgex."
)

func AuthToOpenZiti(ozController, jwt string) (ziti.Context, error) {
Expand Down

0 comments on commit 29e6be3

Please sign in to comment.