Search
K

Migrating from legacy service extensions

Legacy service extensions imported a lot of the functionality via globals defined at the package level. The new configuration sources all inputs from the orchestrator.Orchestrator interface.
The following code snippets are meant only as examples to demonstrate the changes and updates between the legacy and new service extension interfaces.

Logging

New Config
Legacy Config
// import "github.com/strata-io/service-extension/orchestrator"
// api orchestrator.Orchestrator
logger := api.Logger()
logger.Info("se", "this is an info log")
logger.Error("se", "this is an error log")
logger.Debug("se", "this is a debug log")
// import "maverics/log"
log.Info("se", "this is an info log")
log.Error("se", "this is an error log")
log.Debug("se", "this is a debug log")

Secret Provider

New Config
Legacy Config
// import "github.com/strata-io/service-extension/orchestrator"
// api orchestrator.Orchestrator
secret := api.SecretProvider()
secret.GetString("app1OIDCClientSecret")
// import "maverics/secret"
secret.GetString("app1OIDCClientSecret")

Identity Provider

New Config
Legacy Config
// import "github.com/strata-io/service-extension/orchestrator"
// api orchestrator.Orchestrator
azure, err := api.IdentityProvider("azure")
azure.Login(rw, req)
// import "maverics/app"
// ag *app.AppGateway
azure, ok := ag.IDPs["azure"]
azure.CreateRequest().Login(rw, req)

Attribute Provider

New Config
Legacy Config
// import "github.com/strata-io/service-extension/orchestrator"
// api orchestrator.Orchestrator
ldap, err := api.AttributeProvider("ldap")
attrs, err := ldap.Query(mail, []string{"cn", "sn", "mobile"})
// import "maverics/app"
// ag *app.AppGateway
ldap, ok := ag.AttrProviders["ldap"]
attrs, err := ldap.Query(mail, []string{"cn", "sn", "mobile"})

Session

New Config
Legacy Config
// import "github.com/strata-io/service-extension/orchestrator"
// api orchestrator.Orchestrator
session, err := api.Session()
isAzureAuth, err := session.GetString("azure.authenticated")
// Now saving information to the session is a two-step process.
err = session.SetString(k, v)
err = session.Save()
// import "maverics/session"
isAuth := session.GetString(req, "authenticated")
session.SetString(req, "authenticated", "true")

Registering Routes

New Config
Legacy Config
// import "github.com/strata-io/service-extension/orchestrator"
// api orchestrator.Orchestrator
router := api.Router()
router.HandleFunc("/error", func(rw http.ResponseWriter, req *http.Request){})
// import "net/http"
http.HandleFunc("/error", func(rw http.ResponseWriter, req *http.Request){})