From 217a0caec3a1dc80606b22b27b24121519081d8e Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 24 Feb 2023 09:21:07 -0500 Subject: [PATCH] hackery --- controller/usageAgent.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/controller/usageAgent.go b/controller/usageAgent.go index 92b7f896..d469313d 100644 --- a/controller/usageAgent.go +++ b/controller/usageAgent.go @@ -12,17 +12,19 @@ import ( "github.com/openziti/fabric/event" "github.com/openziti/fabric/pb/mgmt_pb" "github.com/openziti/identity" + "github.com/openziti/sdk-golang/ziti/constants" "github.com/pkg/errors" "github.com/sirupsen/logrus" "io" "net/http" + "net/url" "time" ) type usageAgent struct{} func RunUsageAgent(cfg *Config) error { - wsUrl := "wss://127.0.0.1:1280/ws-api" + wsUrl := "wss://127.0.0.1:1280/fabric/v1/ws-api" caCerts, err := rest_util.GetControllerWellKnownCas(cfg.Ziti.ApiEndpoint) if err != nil { @@ -33,6 +35,17 @@ func RunUsageAgent(cfg *Config) error { caPool.AddCert(ca) } + authenticator := rest_util.NewAuthenticatorUpdb(cfg.Ziti.Username, cfg.Ziti.Password) + authenticator.RootCas = caPool + ctrlUrl, err := url.Parse(cfg.Ziti.ApiEndpoint) + if err != nil { + return err + } + apiSession, err := authenticator.Authenticate(ctrlUrl) + if err != nil { + return err + } + dialer := &websocket.Dialer{ TLSClientConfig: &tls.Config{ RootCAs: caPool, @@ -40,7 +53,7 @@ func RunUsageAgent(cfg *Config) error { HandshakeTimeout: 5 * time.Second, } - conn, resp, err := dialer.Dial(wsUrl, http.Header{}) + conn, resp, err := dialer.Dial(wsUrl, http.Header{constants.ZitiSession: []string{*apiSession.Token}}) if err != nil { if resp != nil { if body, rerr := io.ReadAll(resp.Body); rerr == nil {