everything -> dl (#1078)

This commit is contained in:
Michael Quigley
2025-09-25 13:25:46 -04:00
parent a8a13f1c83
commit d00e4a5290
199 changed files with 1433 additions and 1366 deletions
+3 -3
View File
@@ -26,19 +26,19 @@ conventions and idioms. The log formatting examples for Go are applicable to all
Format log messages that report errors.
```go
logrus.Errorf("tried a thing and failed: %v", err)
dl.Errorf("tried a thing and failed: %v", err)
```
Format in-line information in informational log messages.
```go
logrus.Infof("the expected value '%v' arrived as '%v'", expected, actual)
dl.Infof("the expected value '%v' arrived as '%v'", expected, actual)
```
Format in-line information in error log messages.
```go
logrus.Errorf("the expected value '%v did not compute: %v", value, err)
dl.Errorf("the expected value '%v did not compute: %v", value, err)
```
+ Format log messages with format strings and arguments like 'tried a thing and failed: %s'.
+2 -2
View File
@@ -2,9 +2,9 @@ package canary
import (
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/metrics"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
const ConfigVersion = 1
@@ -22,6 +22,6 @@ func LoadConfig(path string) (*Config, error) {
if cfg.V != ConfigVersion {
return nil, errors.Errorf("expecting canary configuration version '%v', got '%v'", ConfigVersion, cfg.V)
}
logrus.Info(dd.MustInspect(cfg))
dl.Info(dd.MustInspect(cfg))
return cfg, nil
}
+8 -7
View File
@@ -1,11 +1,12 @@
package canary
import (
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/sirupsen/logrus"
"math/rand"
"time"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/sdk/golang/sdk"
)
type DisablerOptions struct {
@@ -34,7 +35,7 @@ func NewDisabler(id uint, opt *DisablerOptions, root env_core.Root) *Disabler {
}
func (d *Disabler) Run() {
defer logrus.Infof("#%d stopping", d.Id)
defer dl.Infof("#%d stopping", d.Id)
defer close(d.Done)
d.dwell()
d.iterate()
@@ -65,20 +66,20 @@ func (d *Disabler) iterate() {
snapshot.Completed = time.Now()
snapshot.Ok = true
logrus.Infof("#%d disabled environment '%v'", d.Id, env.ZitiIdentity)
dl.Infof("#%d disabled environment '%v'", d.Id, env.ZitiIdentity)
} else {
snapshot.Completed = time.Now()
snapshot.Ok = false
snapshot.Error = err
logrus.Errorf("error disabling canary (#%d) environment '%v': %v", d.Id, env.ZitiIdentity, err)
dl.Errorf("error disabling canary (#%d) environment '%v': %v", d.Id, env.ZitiIdentity, err)
}
if d.opt.SnapshotQueue != nil {
d.opt.SnapshotQueue <- snapshot
} else {
logrus.Info(snapshot)
dl.Info(snapshot)
}
}
+8 -7
View File
@@ -2,11 +2,12 @@ package canary
import (
"fmt"
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/sirupsen/logrus"
"math/rand"
"time"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/sdk/golang/sdk"
)
type EnablerOptions struct {
@@ -39,7 +40,7 @@ func NewEnabler(id uint, opt *EnablerOptions, root env_core.Root) *Enabler {
func (e *Enabler) Run() {
defer close(e.Environments)
defer close(e.Done)
defer logrus.Infof("#%d stopping", e.Id)
defer dl.Infof("#%d stopping", e.Id)
e.dwell()
e.iterate()
}
@@ -54,7 +55,7 @@ func (e *Enabler) dwell() {
}
func (e *Enabler) iterate() {
defer logrus.Info("done")
defer dl.Info("done")
for i := uint(0); i < e.opt.Iterations; i++ {
snapshot := NewSnapshot("enable", e.Id, uint64(i))
@@ -65,12 +66,12 @@ func (e *Enabler) iterate() {
if err == nil {
snapshot.Complete().Success()
e.Environments <- env
logrus.Infof("#%d enabled environment '%v'", e.Id, env.ZitiIdentity)
dl.Infof("#%d enabled environment '%v'", e.Id, env.ZitiIdentity)
} else {
snapshot.Complete().Failure(err)
logrus.Errorf("error creating canary (#%d) environment: %v", e.Id, err)
dl.Errorf("error creating canary (#%d) environment: %v", e.Id, err)
}
snapshot.Send(e.opt.SnapshotQueue)
+5 -4
View File
@@ -1,9 +1,10 @@
package canary
import (
"github.com/openziti/zrok/util"
"github.com/sirupsen/logrus"
"time"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/util"
)
type LooperOptions struct {
@@ -47,7 +48,7 @@ func ReportLooperResults(results []*LooperResults) {
totalErrors += result.Errors
totalMismatches += result.Mismatches
totalLoops += result.Loops
logrus.Infof("looper #%d: %d loops, %v, %d errors, %d mismatches, %s/sec", i, result.Loops, util.BytesToSize(int64(result.Bytes)), result.Errors, result.Mismatches, util.BytesToSize(int64(xferRate)))
dl.Infof("looper #%d: %d loops, %v, %d errors, %d mismatches, %s/sec", i, result.Loops, util.BytesToSize(int64(result.Bytes)), result.Errors, result.Mismatches, util.BytesToSize(int64(xferRate)))
}
logrus.Infof("total: %d loops, %v, %d errors, %d mismatches, %s/sec", totalLoops, util.BytesToSize(int64(totalBytes)), totalErrors, totalMismatches, util.BytesToSize(int64(totalXferRate)))
dl.Infof("total: %d loops, %v, %d errors, %d mismatches, %s/sec", totalLoops, util.BytesToSize(int64(totalBytes)), totalErrors, totalMismatches, util.BytesToSize(int64(totalXferRate)))
}
+26 -25
View File
@@ -5,17 +5,18 @@ import (
"context"
cryptorand "crypto/rand"
"encoding/base64"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"io"
"math/rand"
"net"
"net/http"
"time"
"github.com/michaelquigley/df/dl"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/pkg/errors"
)
type PrivateHttpLooper struct {
@@ -44,23 +45,23 @@ func NewPrivateHttpLooper(id uint, opt *LooperOptions, root env_core.Root) *Priv
func (l *PrivateHttpLooper) Run() {
defer close(l.done)
defer logrus.Infof("#%d stopping", l.id)
defer dl.Infof("#%d stopping", l.id)
defer l.shutdown()
logrus.Infof("#%d starting", l.id)
dl.Infof("#%d starting", l.id)
if err := l.startup(); err != nil {
logrus.Fatalf("#%d error starting: %v", l.id, err)
dl.Fatalf("#%d error starting: %v", l.id, err)
}
if err := l.bind(); err != nil {
logrus.Fatalf("#%d error binding: %v", l.id, err)
dl.Fatalf("#%d error binding: %v", l.id, err)
}
l.dwell()
l.iterate()
logrus.Infof("#%d completed", l.id)
dl.Infof("#%d completed", l.id)
}
func (l *PrivateHttpLooper) Abort() {
@@ -113,7 +114,7 @@ func (l *PrivateHttpLooper) startup() error {
snapshotCreateAccess.Success().Send(l.opt.SnapshotQueue)
l.acc = acc
logrus.Infof("#%d allocated share '%v', allocated frontend '%v'", l.id, shr.Token, acc.Token)
dl.Infof("#%d allocated share '%v', allocated frontend '%v'", l.id, shr.Token, acc.Token)
return nil
}
@@ -145,7 +146,7 @@ func (l *PrivateHttpLooper) bind() error {
go func() {
if err := http.Serve(l.listener, l); err != nil {
logrus.Errorf("#%d error in http listener: %v", l.id, err)
dl.Errorf("#%d error in http listener: %v", l.id, err)
}
}()
@@ -186,19 +187,19 @@ func (l *PrivateHttpLooper) iterate() {
if batchPacingDelta > 0 {
batchPacingMs = (rand.Int63() % batchPacingDelta) + l.opt.MinBatchPacing.Milliseconds()
}
logrus.Debugf("sleeping %d ms for batch pacing", batchPacingMs)
dl.Debugf("sleeping %d ms for batch pacing", batchPacingMs)
time.Sleep(time.Duration(batchPacingMs) * time.Millisecond)
}
snapshot := NewSnapshot("private-proxy", l.id, uint64(i))
if i > 0 && i%l.opt.StatusInterval == 0 {
logrus.Infof("#%d: iteration %d", l.id, i)
dl.Infof("#%d: iteration %d", l.id, i)
}
conn, err := sdk.NewDialer(l.shr.Token, l.root)
if err != nil {
logrus.Errorf("#%d: error dialing: %v", l.id, err)
dl.Errorf("#%d: error dialing: %v", l.id, err)
l.results.Errors++
time.Sleep(1 * time.Second)
continue
@@ -218,36 +219,36 @@ func (l *PrivateHttpLooper) iterate() {
client := &http.Client{Timeout: l.opt.Timeout, Transport: &http.Transport{DialContext: connDialer{conn}.Dial}}
if resp, err := client.Do(req); err == nil {
if resp.StatusCode != 200 {
logrus.Errorf("#%d: unexpected status code: %v", l.id, resp.StatusCode)
dl.Errorf("#%d: unexpected status code: %v", l.id, resp.StatusCode)
l.results.Errors++
}
inPayload := new(bytes.Buffer)
io.Copy(inPayload, resp.Body)
inBase64 := inPayload.String()
if inBase64 != outBase64 {
logrus.Errorf("#%d: payload mismatch", l.id)
dl.Errorf("#%d: payload mismatch", l.id)
l.results.Mismatches++
snapshot.Complete().Failure(err)
} else {
l.results.Bytes += uint64(len(outBase64))
logrus.Debugf("#%d: payload match", l.id)
dl.Debugf("#%d: payload match", l.id)
snapshot.Complete().Success()
}
} else {
logrus.Errorf("#%d: error: %v", l.id, err)
dl.Errorf("#%d: error: %v", l.id, err)
l.results.Errors++
}
} else {
logrus.Errorf("#%d: error creating request: %v", l.id, err)
dl.Errorf("#%d: error creating request: %v", l.id, err)
l.results.Errors++
}
snapshot.Send(l.opt.SnapshotQueue)
if err := conn.Close(); err != nil {
logrus.Errorf("#%d: error closing connection: %v", l.id, err)
dl.Errorf("#%d: error closing connection: %v", l.id, err)
}
pacingMs := l.opt.MaxPacing.Milliseconds()
@@ -264,15 +265,15 @@ func (l *PrivateHttpLooper) iterate() {
func (l *PrivateHttpLooper) shutdown() {
if l.listener != nil {
if err := l.listener.Close(); err != nil {
logrus.Errorf("#%d error closing listener: %v", l.id, err)
dl.Errorf("#%d error closing listener: %v", l.id, err)
}
}
if err := sdk.DeleteAccess(l.root, l.acc); err != nil {
logrus.Errorf("#%d error deleting access '%v': %v", l.id, l.acc.Token, err)
dl.Errorf("#%d error deleting access '%v': %v", l.id, l.acc.Token, err)
}
if err := sdk.DeleteShare(l.root, l.shr); err != nil {
logrus.Errorf("#%d error deleting share '%v': %v", l.id, l.shr.Token, err)
dl.Errorf("#%d error deleting share '%v': %v", l.id, l.shr.Token, err)
}
}
+17 -17
View File
@@ -9,12 +9,12 @@ import (
"net/http"
"time"
"github.com/michaelquigley/df/dl"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type PublicHttpLooper struct {
@@ -42,23 +42,23 @@ func NewPublicHttpLooper(id uint, namespace string, opt *LooperOptions, root env
func (l *PublicHttpLooper) Run() {
defer close(l.done)
defer logrus.Infof("#%d stopping", l.id)
defer dl.Infof("#%d stopping", l.id)
defer l.shutdown()
logrus.Infof("#%d starting", l.id)
dl.Infof("#%d starting", l.id)
if err := l.startup(); err != nil {
logrus.Fatalf("#%d error starting: %v", l.id, err)
dl.Fatalf("#%d error starting: %v", l.id, err)
}
if err := l.bind(); err != nil {
logrus.Fatalf("#%d error binding: %v", l.id, err)
dl.Fatalf("#%d error binding: %v", l.id, err)
}
l.dwell()
l.iterate()
logrus.Infof("#%d completed", l.id)
dl.Infof("#%d completed", l.id)
}
func (l *PublicHttpLooper) Abort() {
@@ -95,7 +95,7 @@ func (l *PublicHttpLooper) startup() error {
snapshotCreateShare.Success().Send(l.opt.SnapshotQueue)
l.shr = shr
logrus.Infof("#%d allocated share '%v'", l.id, l.shr.Token)
dl.Infof("#%d allocated share '%v'", l.id, l.shr.Token)
return nil
}
@@ -127,7 +127,7 @@ func (l *PublicHttpLooper) bind() error {
go func() {
if err := http.Serve(l.listener, l); err != nil {
logrus.Errorf("#%d error in http listener: %v", l.id, err)
dl.Errorf("#%d error in http listener: %v", l.id, err)
}
}()
@@ -160,14 +160,14 @@ func (l *PublicHttpLooper) iterate() {
if batchPacingDelta > 0 {
batchPacingMs = (rand.Int63() % batchPacingDelta) + l.opt.MinBatchPacing.Milliseconds()
}
logrus.Debugf("sleeping %d ms for batch pacing", batchPacingMs)
dl.Debugf("sleeping %d ms for batch pacing", batchPacingMs)
time.Sleep(time.Duration(batchPacingMs) * time.Millisecond)
}
snapshot := NewSnapshot("public-proxy", l.id, uint64(i))
if i > 0 && i%l.opt.StatusInterval == 0 {
logrus.Infof("#%d: iteration %d", l.id, i)
dl.Infof("#%d: iteration %d", l.id, i)
}
payloadSize := l.opt.MaxPayload
@@ -184,29 +184,29 @@ func (l *PublicHttpLooper) iterate() {
client := &http.Client{Timeout: l.opt.Timeout}
if resp, err := client.Do(req); err == nil {
if resp.StatusCode != 200 {
logrus.Errorf("#%d: unexpected status code: %v", l.id, resp.StatusCode)
dl.Errorf("#%d: unexpected status code: %v", l.id, resp.StatusCode)
l.results.Errors++
}
inPayload := new(bytes.Buffer)
io.Copy(inPayload, resp.Body)
inBase64 := inPayload.String()
if inBase64 != outBase64 {
logrus.Errorf("#%d: payload mismatch", l.id)
dl.Errorf("#%d: payload mismatch", l.id)
l.results.Mismatches++
snapshot.Complete().Failure(err)
} else {
l.results.Bytes += uint64(len(outBase64))
logrus.Debugf("#%d: payload match", l.id)
dl.Debugf("#%d: payload match", l.id)
snapshot.Complete().Success()
}
} else {
logrus.Errorf("#%d: error: %v", l.id, err)
dl.Errorf("#%d: error: %v", l.id, err)
l.results.Errors++
}
} else {
logrus.Errorf("#%d: error creating request: %v", l.id, err)
dl.Errorf("#%d: error creating request: %v", l.id, err)
l.results.Errors++
}
@@ -226,11 +226,11 @@ func (l *PublicHttpLooper) iterate() {
func (l *PublicHttpLooper) shutdown() {
if l.listener != nil {
if err := l.listener.Close(); err != nil {
logrus.Errorf("#%d error closing listener: %v", l.id, err)
dl.Errorf("#%d error closing listener: %v", l.id, err)
}
}
if err := sdk.DeleteShare(l.root, l.shr); err != nil {
logrus.Errorf("#%d error deleting share '%v': %v", l.id, l.shr.Token, err)
dl.Errorf("#%d error deleting share '%v': %v", l.id, l.shr.Token, err)
}
}
+5 -4
View File
@@ -4,9 +4,10 @@ import (
"context"
"errors"
"fmt"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/influxdata/influxdb-client-go/v2/api"
"github.com/sirupsen/logrus"
"github.com/michaelquigley/df/dl"
)
type SnapshotStreamer struct {
@@ -37,8 +38,8 @@ func NewSnapshotStreamer(ctx context.Context, cfg *Config) (*SnapshotStreamer, e
func (ss *SnapshotStreamer) Run() {
defer close(ss.Closed)
defer ss.ifxClient.Close()
defer logrus.Info("stoping")
logrus.Info("starting")
defer dl.Info("stoping")
dl.Info("starting")
for {
select {
@@ -47,7 +48,7 @@ func (ss *SnapshotStreamer) Run() {
case snapshot := <-ss.InputQueue:
if err := ss.store(snapshot); err != nil {
logrus.Errorf("error storing snapshot: %v", err)
dl.Errorf("error storing snapshot: %v", err)
}
}
}
+4 -4
View File
@@ -5,10 +5,10 @@ import (
"os/signal"
"syscall"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/endpoints/dynamicProxy"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -49,7 +49,7 @@ func (cmd *accessDynamicProxyCommand) run(_ *cobra.Command, args []string) {
cmd.error(err)
}
logrus.Infof("starting dynamicProxy service with config '%v'", cmd.configPath)
dl.Infof("starting dynamicProxy service with config '%v'", cmd.configPath)
go func() {
if err := service.Start(); err != nil {
@@ -61,10 +61,10 @@ func (cmd *accessDynamicProxyCommand) run(_ *cobra.Command, args []string) {
signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGQUIT)
<-c
logrus.Infof("shutting down dynamicProxy service")
dl.Infof("shutting down dynamicProxy service")
if err := service.Stop(); err != nil {
logrus.Errorf("error shutting down: %v", err)
dl.Errorf("error shutting down: %v", err)
}
}
+16 -7
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/url"
"os"
"os/signal"
@@ -14,6 +15,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentClient"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/cmd/zrok/subordinate"
@@ -83,6 +85,9 @@ func newAccessPrivateCommand() *accessPrivateCommand {
func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
if cmd.subordinate {
logrus.SetFormatter(&logrus.JSONFormatter{TimestampFormat: time.RFC3339Nano})
dlOpts := dl.DefaultOptions().SetTrimPrefix(trimPrefix).SetLevel(slog.LevelInfo)
dlOpts.UseJSON = true
dl.Init(dlOpts)
}
root, err := environment.LoadRoot()
@@ -119,9 +124,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
if cmd.templatePath != "" {
if err := proxyUi.ReplaceTemplate(cmd.templatePath); err != nil {
logrus.Fatalf("error loading template '%v': %v", cmd.templatePath, err)
dl.Fatalf("error loading template '%v': %v", cmd.templatePath, err)
}
logrus.Infof("loaded external proxy ui template '%v'", cmd.templatePath)
dl.Infof("loaded external proxy ui template '%v'", cmd.templatePath)
}
accessResp, err := zrok.Share.Access(req, auth)
@@ -288,11 +293,11 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
}
if cmd.headless {
logrus.Infof("access the zrok share at the following endpoint: %v", endpointUrl.String())
dl.Infof("access the zrok share at the following endpoint: %v", endpointUrl.String())
for {
select {
case req := <-requests:
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
dl.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
}
}
} else if cmd.subordinate {
@@ -314,6 +319,10 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
} else {
mdl := newAccessModel(shrToken, endpointUrl.String())
logrus.SetOutput(mdl)
dlOpts := dl.DefaultOptions().SetTrimPrefix(trimPrefix).SetLevel(slog.LevelInfo)
dlOpts.CustomHandler = dl.NewPrettyHandler(slog.LevelInfo, dl.DefaultOptions().SetOutput(mdl))
dl.Init(dlOpts)
prg := tea.NewProgram(mdl, tea.WithAltScreen())
mdl.prg = prg
@@ -348,15 +357,15 @@ func (cmd *accessPrivateCommand) error(err error) {
}
func (cmd *accessPrivateCommand) shutdown(frontendToken, envZId, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
logrus.Infof("shutting down '%v'", shrToken)
dl.Infof("shutting down '%v'", shrToken)
req := share.NewUnaccessParams()
req.Body.FrontendToken = frontendToken
req.Body.ShareToken = shrToken
req.Body.EnvZID = envZId
if _, err := zrok.Share.Unaccess(req, auth); err == nil {
logrus.Debugf("shutdown complete")
dl.Debugf("shutdown complete")
} else {
logrus.Errorf("error shutting down: %v", err)
dl.Errorf("error shutting down: %v", err)
}
}
+2 -2
View File
@@ -4,9 +4,9 @@ import (
"fmt"
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/endpoints/publicProxy"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -42,7 +42,7 @@ func (cmd *accessPublicCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
}
logrus.Info(dd.MustInspect(cfg))
dl.Info(dd.MustInspect(cfg))
frontend, err := publicProxy.NewHTTP(cfg)
if err != nil {
if !panicInstead {
+2 -2
View File
@@ -4,9 +4,9 @@ import (
"fmt"
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/endpoints/publicProxy"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -34,5 +34,5 @@ func (cmd *accessPublicValidateCommand) run(_ *cobra.Command, args []string) {
if err := cfg.Load(args[0]); err != nil {
tui.Error(fmt.Sprintf("unable to load configuration '%v'", args[0]), err)
}
logrus.Info(dd.MustInspect(cfg))
dl.Info(dd.MustInspect(cfg))
}
+3 -3
View File
@@ -2,9 +2,9 @@ package main
import (
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller"
"github.com/openziti/zrok/controller/config"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -35,9 +35,9 @@ func (cmd *adminBootstrap) run(_ *cobra.Command, args []string) {
if err != nil {
panic(err)
}
logrus.Info(dd.MustInspect(inCfg))
dl.Info(dd.MustInspect(inCfg))
if err := controller.Bootstrap(cmd.skipFrontend, inCfg); err != nil {
panic(err)
}
logrus.Info("bootstrap complete!")
dl.Info("bootstrap complete!")
}
+2 -2
View File
@@ -1,11 +1,11 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -65,5 +65,5 @@ func (cmd *adminCreateFrontendCommand) run(_ *cobra.Command, args []string) {
}
}
logrus.Infof("created global public frontend '%v'", resp.Payload.FrontendToken)
dl.Infof("created global public frontend '%v'", resp.Payload.FrontendToken)
}
+3 -3
View File
@@ -3,9 +3,9 @@ package main
import (
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -48,9 +48,9 @@ func (cmd *adminCreateFrontendGrantCommand) run(_ *cobra.Command, args []string)
req.Body.Email = accountEmail
if _, err = zrok.Admin.AddFrontendGrant(req, mustGetAdminAuth()); err != nil {
logrus.Errorf("error addming frontend grant: %v", err)
dl.Errorf("error addming frontend grant: %v", err)
os.Exit(1)
}
logrus.Infof("added frontend ('%v') grant for '%v'", frontendToken, accountEmail)
dl.Infof("added frontend ('%v') grant for '%v'", frontendToken, accountEmail)
}
+4 -3
View File
@@ -2,11 +2,12 @@ package main
import (
"fmt"
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
)
func init() {
@@ -41,7 +42,7 @@ func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) {
panic(err)
}
if _, err := os.Stat(zif); err == nil {
logrus.Errorf("identity '%v' already exists at '%v'", name, zif)
dl.Errorf("identity '%v' already exists at '%v'", name, zif)
os.Exit(1)
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -58,5 +58,5 @@ func (cmd *adminCreateNamespaceCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("created namespace '%v' with token '%v'", args[0], resp.Payload.NamespaceToken)
dl.Infof("created namespace '%v' with token '%v'", args[0], resp.Payload.NamespaceToken)
}
+4 -4
View File
@@ -3,9 +3,9 @@ package main
import (
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -51,9 +51,9 @@ func (cmd *adminCreateNamespaceFrontendCommand) run(_ *cobra.Command, args []str
req.Body.IsDefault = cmd.isDefault
if _, err = zrok.Admin.AddNamespaceFrontendMapping(req, mustGetAdminAuth()); err != nil {
logrus.Errorf("error creating namespace-frontend mapping: %v", err)
dl.Errorf("error creating namespace-frontend mapping: %v", err)
os.Exit(1)
}
logrus.Infof("created namespace-frontend mapping: namespace '%v' -> frontend '%v'", namespaceToken, frontendToken)
}
dl.Infof("created namespace-frontend mapping: namespace '%v' -> frontend '%v'", namespaceToken, frontendToken)
}
+4 -4
View File
@@ -3,9 +3,9 @@ package main
import (
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -48,9 +48,9 @@ func (cmd *adminCreateNamespaceGrantCommand) run(_ *cobra.Command, args []string
req.Body.Email = accountEmail
if _, err = zrok.Admin.AddNamespaceGrant(req, mustGetAdminAuth()); err != nil {
logrus.Errorf("error adding namespace grant: %v", err)
dl.Errorf("error adding namespace grant: %v", err)
os.Exit(1)
}
logrus.Infof("added namespace ('%v') grant for '%v'", namespaceToken, accountEmail)
}
dl.Infof("added namespace ('%v') grant for '%v'", namespaceToken, accountEmail)
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -50,5 +50,5 @@ func (cmd *adminCreateOrgMemberCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("added '%v' to organization '%v", args[0], args[1])
dl.Infof("added '%v' to organization '%v", args[0], args[1])
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -48,5 +48,5 @@ func (cmd *adminCreateOrganizationCommand) run(_ *cobra.Command, _ []string) {
panic(err)
}
logrus.Infof("created new organization with organization token '%v'", resp.Payload.OrganizationToken)
dl.Infof("created new organization with organization token '%v'", resp.Payload.OrganizationToken)
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -46,5 +46,5 @@ func (cmd *adminDeleteAccountCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("deleted account '%v'", email)
dl.Infof("deleted account '%v'", email)
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -46,5 +46,5 @@ func (cmd *adminDeleteFrontendCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("deleted global frontend '%v'", feToken)
dl.Infof("deleted global frontend '%v'", feToken)
}
+3 -3
View File
@@ -3,9 +3,9 @@ package main
import (
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -48,9 +48,9 @@ func (cmd *adminDeleteFrontendGrantCommand) run(_ *cobra.Command, args []string)
req.Body.Email = accountEmail
if _, err := zrok.Admin.DeleteFrontendGrant(req, mustGetAdminAuth()); err != nil {
logrus.Errorf("error deleting frontend grant: %v", err)
dl.Errorf("error deleting frontend grant: %v", err)
os.Exit(1)
}
logrus.Infof("deleted frontend ('%v') grant for '%v'", frontendToken, accountEmail)
dl.Infof("deleted frontend ('%v') grant for '%v'", frontendToken, accountEmail)
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -46,5 +46,5 @@ func (cmd *adminDeleteIdentityCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("deleted identity '%v'; please remove any related identity json files", zId)
dl.Infof("deleted identity '%v'; please remove any related identity json files", zId)
}
+3 -3
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -47,5 +47,5 @@ func (cmd *adminDeleteNamespaceCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("deleted namespace '%v'", args[0])
}
dl.Infof("deleted namespace '%v'", args[0])
}
+4 -4
View File
@@ -3,9 +3,9 @@ package main
import (
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -48,9 +48,9 @@ func (cmd *adminDeleteNamespaceFrontendCommand) run(_ *cobra.Command, args []str
req.Body.NamespaceToken = namespaceToken
if _, err := zrok.Admin.RemoveNamespaceFrontendMapping(req, mustGetAdminAuth()); err != nil {
logrus.Errorf("error deleting namespace-frontend mapping: %v", err)
dl.Errorf("error deleting namespace-frontend mapping: %v", err)
os.Exit(1)
}
logrus.Infof("deleted namespace-frontend mapping: namespace '%v' -> frontend '%v'", namespaceToken, frontendToken)
}
dl.Infof("deleted namespace-frontend mapping: namespace '%v' -> frontend '%v'", namespaceToken, frontendToken)
}
+4 -4
View File
@@ -3,9 +3,9 @@ package main
import (
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -48,9 +48,9 @@ func (cmd *adminDeleteNamespaceGrantCommand) run(_ *cobra.Command, args []string
req.Body.Email = accountEmail
if _, err := zrok.Admin.RemoveNamespaceGrant(req, mustGetAdminAuth()); err != nil {
logrus.Errorf("error removing namespace grant: %v", err)
dl.Errorf("error removing namespace grant: %v", err)
os.Exit(1)
}
logrus.Infof("removed namespace ('%v') grant for '%v'", namespaceToken, accountEmail)
}
dl.Infof("removed namespace ('%v') grant for '%v'", namespaceToken, accountEmail)
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -47,5 +47,5 @@ func (cmd *adminDeleteOrgMemberCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("removed '%v' from organization '%v", args[0], args[1])
dl.Infof("removed '%v' from organization '%v", args[0], args[1])
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -46,5 +46,5 @@ func (cmd *adminDeleteOrganizationCommand) run(_ *cobra.Command, args []string)
panic(err)
}
logrus.Infof("deleted organization with token '%v'", args[0])
dl.Infof("deleted organization with token '%v'", args[0])
}
+2 -2
View File
@@ -2,9 +2,9 @@ package main
import (
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller"
"github.com/openziti/zrok/controller/config"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -32,7 +32,7 @@ func (gc *adminGcCommand) run(_ *cobra.Command, args []string) {
if err != nil {
panic(err)
}
logrus.Info(dd.MustInspect(cfg))
dl.Info(dd.MustInspect(cfg))
if err := controller.GC(cfg); err != nil {
panic(err)
}
+6 -5
View File
@@ -2,10 +2,11 @@ package main
import (
"fmt"
"github.com/jaevor/go-nanoid"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -36,19 +37,19 @@ func (cmd *adminGenerateCommand) run(_ *cobra.Command, args []string) {
for i := 0; i < int(cmd.amount); i++ {
tokens[i], err = createToken()
if err != nil {
logrus.Error("error creating token", err)
dl.Errorf("error creating token: %v", err)
}
}
env, err := environment.LoadRoot()
if err != nil {
logrus.Error("error loading environment", err)
dl.Errorf("error loading environment: %v", err)
}
zrok, err := env.Client()
if err != nil {
if !panicInstead {
logrus.Error("error creating zrok api client", err)
dl.Errorf("error creating zrok api client: %v", err)
}
panic(err)
}
@@ -58,7 +59,7 @@ func (cmd *adminGenerateCommand) run(_ *cobra.Command, args []string) {
_, err = zrok.Admin.InviteTokenGenerate(req, mustGetAdminAuth())
if err != nil {
if !panicInstead {
logrus.Error("error creating invite tokens", err)
dl.Errorf("error creating invite tokens: %v", err)
}
panic(err)
}
+3 -3
View File
@@ -6,9 +6,9 @@ import (
"time"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -49,7 +49,7 @@ func (cmd *adminListFrontendNamespaceCommand) run(_ *cobra.Command, args []strin
namespacesReq := admin.NewListNamespacesParams()
namespacesResp, err := zrok.Admin.ListNamespaces(namespacesReq, mustGetAdminAuth())
if err != nil {
logrus.Errorf("error listing namespaces: %v", err)
dl.Errorf("error listing namespaces: %v", err)
os.Exit(1)
}
@@ -65,7 +65,7 @@ func (cmd *adminListFrontendNamespaceCommand) run(_ *cobra.Command, args []strin
resp, err := zrok.Admin.ListFrontendNamespaceMappings(req, mustGetAdminAuth())
if err != nil {
logrus.Errorf("error listing frontend-namespace mappings: %v", err)
dl.Errorf("error listing frontend-namespace mappings: %v", err)
os.Exit(1)
}
+3 -3
View File
@@ -6,9 +6,9 @@ import (
"time"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -49,7 +49,7 @@ func (cmd *adminListNamespaceFrontendCommand) run(_ *cobra.Command, args []strin
frontendsReq := admin.NewListFrontendsParams()
frontendsResp, err := zrok.Admin.ListFrontends(frontendsReq, mustGetAdminAuth())
if err != nil {
logrus.Errorf("error listing frontends: %v", err)
dl.Errorf("error listing frontends: %v", err)
os.Exit(1)
}
@@ -65,7 +65,7 @@ func (cmd *adminListNamespaceFrontendCommand) run(_ *cobra.Command, args []strin
resp, err := zrok.Admin.ListNamespaceFrontendMappings(req, mustGetAdminAuth())
if err != nil {
logrus.Errorf("error listing namespace-frontend mappings: %v", err)
dl.Errorf("error listing namespace-frontend mappings: %v", err)
os.Exit(1)
}
+4 -4
View File
@@ -2,9 +2,9 @@ package main
import (
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/config"
"github.com/openziti/zrok/controller/store"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -36,7 +36,7 @@ func (cmd *adminMigrate) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Info(dd.MustInspect(inCfg))
dl.Info(dd.MustInspect(inCfg))
// disable auto-migration, we'll control it manually
inCfg.Store.DisableAutoMigration = true
@@ -51,13 +51,13 @@ func (cmd *adminMigrate) run(_ *cobra.Command, args []string) {
if err := str.MigrateDown(inCfg.Store, cmd.steps); err != nil {
panic(err)
}
logrus.Infof("migrated down %d steps", cmd.steps)
dl.Infof("migrated down %d steps", cmd.steps)
} else {
// default behavior - migrate up
inCfg.Store.DisableAutoMigration = false
if _, err := store.Open(inCfg.Store); err != nil {
panic(err)
}
logrus.Info("migration complete")
dl.Info("migration complete")
}
}
+3 -3
View File
@@ -2,9 +2,9 @@ package main
import (
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller"
"github.com/openziti/zrok/controller/config"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -32,9 +32,9 @@ func (cmd *adminUnbootstrap) run(_ *cobra.Command, args []string) {
if err != nil {
panic(err)
}
logrus.Info(dd.MustInspect(cfg))
dl.Info(dd.MustInspect(cfg))
if err := controller.Unbootstrap(cfg); err != nil {
panic(err)
}
logrus.Info("unbootstrap complete!")
dl.Info("unbootstrap complete!")
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -57,5 +57,5 @@ func (cmd *adminUpdateFrontendCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("updated global frontend '%v'", feToken)
dl.Infof("updated global frontend '%v'", feToken)
}
+3 -3
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -51,7 +51,7 @@ func (cmd *adminUpdateNamespaceCommand) run(_ *cobra.Command, args []string) {
Name: cmd.name,
Description: cmd.description,
}
if cmd.cmd.Flags().Changed("open") {
req.Body.Open = true
req.Body.OpenSet = true
@@ -65,5 +65,5 @@ func (cmd *adminUpdateNamespaceCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("updated namespace '%v'", args[0])
dl.Infof("updated namespace '%v'", args[0])
}
+2 -2
View File
@@ -2,9 +2,9 @@ package main
import (
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller"
"github.com/openziti/zrok/controller/config"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -42,7 +42,7 @@ func (cmd *controllerCommand) run(_ *cobra.Command, args []string) {
if err != nil {
panic(err)
}
logrus.Info(dd.MustInspect(cfg))
dl.Info(dd.MustInspect(cfg))
if err := controller.Run(cfg); err != nil {
panic(err)
}
+2 -2
View File
@@ -7,9 +7,9 @@ import (
"time"
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/config"
"github.com/openziti/zrok/controller/metrics"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -37,7 +37,7 @@ func (cmd *bridgeCommand) run(_ *cobra.Command, args []string) {
if err != nil {
panic(err)
}
logrus.Info(dd.MustInspect(cfg))
dl.Info(dd.MustInspect(cfg))
bridge, err := metrics.NewBridge(cfg.Bridge)
if err != nil {
+2 -2
View File
@@ -2,9 +2,9 @@ package main
import (
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/config"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -32,5 +32,5 @@ func (cmd *controllerValidateCommand) run(_ *cobra.Command, args []string) {
if err != nil {
tui.Error("controller config validation failed", err)
}
logrus.Info(dd.MustInspect(cfg))
dl.Info(dd.MustInspect(cfg))
}
+2 -2
View File
@@ -1,10 +1,10 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/share"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -52,5 +52,5 @@ func (cmd *createNameCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to create name", err)
}
logrus.Infof("created name '%v' in namespace", args[0])
dl.Infof("created name '%v' in namespace", args[0])
}
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/share"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -51,5 +51,5 @@ func (cmd *deleteNameCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
logrus.Infof("deleted name '%v' from namespace", args[0])
dl.Infof("deleted name '%v' from namespace", args[0])
}
+3 -2
View File
@@ -2,11 +2,12 @@ package main
import (
"fmt"
httpTransport "github.com/go-openapi/runtime/client"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
restEnvironment "github.com/openziti/zrok/rest_client_zrok/environment"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -55,7 +56,7 @@ func (cmd *disableCommand) run(_ *cobra.Command, _ []string) {
_, err = zrok.Environment.Disable(req, auth)
if err != nil {
logrus.Warnf("share cleanup failed (%v); will clean up local environment", err)
dl.Warnf("share cleanup failed (%v); will clean up local environment", err)
}
if err := env.DeleteEnvironment(); err != nil {
if !panicInstead {
+6 -6
View File
@@ -8,12 +8,12 @@ import (
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
httptransport "github.com/go-openapi/runtime/client"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/environment/env_core"
restEnvironment "github.com/openziti/zrok/rest_client_zrok/environment"
"github.com/openziti/zrok/tui"
"github.com/openziti/zrok/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -84,7 +84,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
}
}()
} else {
logrus.Infof("contacting the zrok service...")
dl.Infof("contacting the zrok service...")
}
resp, err := zrok.Environment.Enable(req, auth)
@@ -95,7 +95,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
prg.Send(fmt.Sprintf("the zrok service returned an error: %v\n", err))
prg.Quit()
} else {
logrus.Errorf("the zrok service returned an error: %v", err)
dl.Errorf("the zrok service returned an error: %v", err)
}
select {
case <-done:
@@ -113,7 +113,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
prg.Send(fmt.Sprintf("there was an error saving the new environment: %v", err))
prg.Quit()
} else {
logrus.Errorf("there was an error saving the new environment: %v", err)
dl.Errorf("there was an error saving the new environment: %v", err)
}
select {
case <-done:
@@ -126,7 +126,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
prg.Send(fmt.Sprintf("there was an error writing the environment: %v", err))
prg.Quit()
} else {
logrus.Errorf("there was an error writing the environment: %v", err)
dl.Errorf("there was an error writing the environment: %v", err)
}
select {
case <-done:
@@ -139,7 +139,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
prg.Send(fmt.Sprintf("the zrok environment was successfully enabled..."))
prg.Quit()
} else {
logrus.Infof("the zrok environment was successfully enabled...")
dl.Infof("the zrok environment was successfully enabled...")
}
select {
case <-done:
+6 -5
View File
@@ -2,17 +2,18 @@ package main
import (
"fmt"
"net/url"
"os"
"sort"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/drives/sync"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/openziti/zrok/tui"
"github.com/openziti/zrok/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"net/url"
"os"
"sort"
)
func init() {
@@ -62,7 +63,7 @@ func (cmd *lsCommand) run(_ *cobra.Command, args []string) {
}
defer func() {
if err := sdk.DeleteAccess(root, access); err != nil {
logrus.Warningf("error freeing access: %v", err)
dl.Warnf("error freeing access: %v", err)
}
}()
}
+3 -2
View File
@@ -18,9 +18,9 @@ import (
"github.com/spf13/cobra"
)
func init() {
trimPrefix := "github.com/openziti/"
const trimPrefix = "github.com/openziti/"
func init() {
// dd/dl Logging
dl.Init(dl.DefaultOptions().SetTrimPrefix(trimPrefix).SetLevel(slog.LevelInfo))
dl.ConfigureChannel("mappings", dl.DefaultOptions().SetTrimPrefix(trimPrefix).SetLevel(slog.LevelInfo))
@@ -60,6 +60,7 @@ var rootCmd = &cobra.Command{
Short: "zrok",
PersistentPreRun: func(_ *cobra.Command, _ []string) {
if verbose {
dl.Init(dl.DefaultOptions().SetTrimPrefix(trimPrefix).SetLevel(slog.LevelInfo))
logrus.SetLevel(logrus.DebugLevel)
}
},
+5 -4
View File
@@ -2,14 +2,15 @@ package main
import (
"fmt"
"net/url"
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/drives/sync"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"net/url"
"os"
)
func init() {
@@ -59,7 +60,7 @@ func (cmd *mdCommand) run(_ *cobra.Command, args []string) {
}
defer func() {
if err := sdk.DeleteAccess(root, access); err != nil {
logrus.Warningf("error freeing access: %v", err)
dl.Warnf("error freeing access: %v", err)
}
}()
}
+5 -4
View File
@@ -2,14 +2,15 @@ package main
import (
"fmt"
"net/url"
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/drives/sync"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"net/url"
"os"
)
func init() {
@@ -59,7 +60,7 @@ func (cmd *mvCommand) run(_ *cobra.Command, args []string) {
}
defer func() {
if err := sdk.DeleteAccess(root, access); err != nil {
logrus.Warningf("error freeing access: %v", err)
dl.Warnf("error freeing access: %v", err)
}
}()
}
+5 -4
View File
@@ -2,14 +2,15 @@ package main
import (
"fmt"
"net/url"
"os"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/drives/sync"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"net/url"
"os"
)
func init() {
@@ -59,7 +60,7 @@ func (cmd *rmCommand) run(_ *cobra.Command, args []string) {
}
defer func() {
if err := sdk.DeleteAccess(root, access); err != nil {
logrus.Warningf("error freeing access: %v", err)
dl.Warnf("error freeing access: %v", err)
}
}()
}
+23 -13
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log/slog"
"net"
"os"
"os/signal"
@@ -12,6 +13,7 @@ import (
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentClient"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/cmd/zrok/subordinate"
@@ -77,6 +79,9 @@ func newSharePrivateCommand() *sharePrivateCommand {
func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
if cmd.subordinate {
logrus.SetFormatter(&logrus.JSONFormatter{TimestampFormat: time.RFC3339Nano})
dlOpts := dl.DefaultOptions().SetTrimPrefix(trimPrefix).SetLevel(slog.LevelInfo)
dlOpts.UseJSON = true
dl.Init(dlOpts)
}
root, err := environment.LoadRoot()
@@ -124,6 +129,7 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
if cmd.open {
req.PermissionMode = sdk.OpenPermissionMode
}
shr, err := sdk.CreateShare(root, req)
if err != nil {
cmd.error("unable to create share", err)
@@ -163,7 +169,7 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running http proxy backend: %v", err)
dl.Errorf("error running http proxy backend: %v", err)
}
}()
@@ -182,7 +188,7 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running http web backend: %v", err)
dl.Errorf("error running http web backend: %v", err)
}
}()
@@ -202,7 +208,7 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running tcpTunnel backend: %v", err)
dl.Errorf("error running tcpTunnel backend: %v", err)
}
}()
@@ -222,7 +228,7 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running udpTunnel backend: %v", err)
dl.Errorf("error running udpTunnel backend: %v", err)
}
}()
@@ -241,7 +247,7 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running caddy backend: %v", err)
dl.Errorf("error running caddy backend: %v", err)
}
}()
@@ -261,7 +267,7 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running drive backend: %v", err)
dl.Errorf("error running drive backend: %v", err)
}
}()
@@ -280,7 +286,7 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running socks backend: %v", err)
dl.Errorf("error running socks backend: %v", err)
}
}()
@@ -300,7 +306,7 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running VPN backend: %v", err)
dl.Errorf("error running VPN backend: %v", err)
}
}()
@@ -321,11 +327,11 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
}
if cmd.headless && !cmd.subordinate {
logrus.Infof("allow other to access your share with the following command:\nzrok access private %v", shr.Token)
dl.Infof("allow other to access your share with the following command:\nzrok access private %v", shr.Token)
for {
select {
case req := <-requests:
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
dl.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
}
}
@@ -348,6 +354,10 @@ func (cmd *sharePrivateCommand) shareLocal(args []string, root env_core.Root) {
} else {
logrus.SetOutput(mdl)
dlOpts := dl.DefaultOptions().SetTrimPrefix(trimPrefix).SetLevel(slog.LevelInfo)
dlOpts.CustomHandler = dl.NewPrettyHandler(slog.LevelInfo, dl.DefaultOptions().SetOutput(mdl))
dl.Init(dlOpts)
prg := tea.NewProgram(mdl, tea.WithAltScreen())
mdl.prg = prg
@@ -380,11 +390,11 @@ func (cmd *sharePrivateCommand) error(msg string, err error) {
}
func (cmd *sharePrivateCommand) shutdown(root env_core.Root, shr *sdk.Share) {
logrus.Debugf("shutting down '%v'", shr.Token)
dl.Debugf("shutting down '%v'", shr.Token)
if err := sdk.DeleteShare(root, shr); err != nil {
logrus.Errorf("error shutting down '%v': %v", shr.Token, err)
dl.Errorf("error shutting down '%v': %v", shr.Token, err)
}
logrus.Debugf("shutdown complete")
dl.Debugf("shutdown complete")
}
func (cmd *sharePrivateCommand) shareAgent(args []string, root env_core.Root) {
+18 -9
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log/slog"
"os"
"os/signal"
"path/filepath"
@@ -13,6 +14,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/gobwas/glob"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentClient"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/cmd/zrok/subordinate"
@@ -89,6 +91,9 @@ func newSharePublicCommand() *sharePublicCommand {
func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
if cmd.subordinate {
logrus.SetFormatter(&logrus.JSONFormatter{TimestampFormat: time.RFC3339Nano})
dlOpts := dl.DefaultOptions().SetTrimPrefix(trimPrefix).SetLevel(slog.LevelInfo)
dlOpts.UseJSON = true
dl.Init(dlOpts)
}
root, err := environment.LoadRoot()
@@ -194,7 +199,7 @@ func (cmd *sharePublicCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running http proxy backend: %v", err)
dl.Errorf("error running http proxy backend: %v", err)
}
}()
@@ -213,7 +218,7 @@ func (cmd *sharePublicCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running http web backend: %v", err)
dl.Errorf("error running http web backend: %v", err)
}
}()
@@ -232,7 +237,7 @@ func (cmd *sharePublicCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running caddy backend: %v", err)
dl.Errorf("error running caddy backend: %v", err)
}
}()
@@ -252,7 +257,7 @@ func (cmd *sharePublicCommand) shareLocal(args []string, root env_core.Root) {
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running drive backend: %v", err)
dl.Errorf("error running drive backend: %v", err)
}
}()
@@ -273,11 +278,11 @@ func (cmd *sharePublicCommand) shareLocal(args []string, root env_core.Root) {
}
if cmd.headless && !cmd.subordinate {
logrus.Infof("access your zrok share at the following endpoints:\n %v", strings.Join(shr.FrontendEndpoints, "\n"))
dl.Infof("access your zrok share at the following endpoints:\n %v", strings.Join(shr.FrontendEndpoints, "\n"))
for {
select {
case req := <-requests:
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
dl.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
}
}
@@ -300,6 +305,10 @@ func (cmd *sharePublicCommand) shareLocal(args []string, root env_core.Root) {
} else {
logrus.SetOutput(mdl)
dlOpts := dl.DefaultOptions().SetTrimPrefix(trimPrefix).SetLevel(slog.LevelInfo)
dlOpts.CustomHandler = dl.NewPrettyHandler(slog.LevelInfo, dl.DefaultOptions().SetOutput(mdl))
dl.Init(dlOpts)
prg := tea.NewProgram(mdl, tea.WithAltScreen())
mdl.prg = prg
@@ -332,11 +341,11 @@ func (cmd *sharePublicCommand) error(msg string, err error) {
}
func (cmd *sharePublicCommand) shutdown(root env_core.Root, shr *sdk.Share) {
logrus.Debugf("shutting down '%v'", shr.Token)
dl.Debugf("shutting down '%v'", shr.Token)
if err := sdk.DeleteShare(root, shr); err != nil {
logrus.Errorf("error shutting down '%v': %v", shr.Token, err)
dl.Errorf("error shutting down '%v': %v", shr.Token, err)
}
logrus.Debugf("shutdown complete")
dl.Debugf("shutdown complete")
}
func (cmd *sharePublicCommand) shareAgent(args []string, root env_core.Root) {
+12 -11
View File
@@ -2,10 +2,11 @@ package main
import (
"fmt"
"github.com/openziti/zrok/sdk/golang/sdk"
"strings"
"time"
"github.com/openziti/zrok/sdk/golang/sdk"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/reflow/wordwrap"
@@ -218,7 +219,7 @@ func (m *shareModel) Write(p []byte) (n int, err error) {
return len(p), nil
}
func (shareModel) Close() error {
func (*shareModel) Close() error {
return nil
}
@@ -230,24 +231,24 @@ func wrap(lines []string, width int) []string {
continue
}
for i := 0; i <= len(line); {
max := i + width
if max > len(line) {
max = len(line)
maxWidth := i + width
if maxWidth > len(line) {
maxWidth = len(line)
}
if line[i:max] == "" {
if line[i:maxWidth] == "" {
continue
}
nextI := i + width
if max < len(line)-1 {
if !wordwrapBreakpoints[rune(line[max])] || !wordwrapBreakpoints[rune(line[max+1])] {
lastSpace := strings.LastIndexAny(line[:max], wordwrapCharacters)
if maxWidth < len(line)-1 {
if !wordwrapBreakpoints[rune(line[maxWidth])] || !wordwrapBreakpoints[rune(line[maxWidth+1])] {
lastSpace := strings.LastIndexAny(line[:maxWidth], wordwrapCharacters)
if lastSpace > -1 {
max = lastSpace
maxWidth = lastSpace
nextI = lastSpace
}
}
}
ret = append(ret, strings.TrimSpace(line[i:max]))
ret = append(ret, strings.TrimSpace(line[i:maxWidth]))
i = nextI
}
}
+5 -4
View File
@@ -3,8 +3,9 @@ package subordinate
import (
"bytes"
"encoding/json"
"github.com/sirupsen/logrus"
"strings"
"github.com/michaelquigley/df/dl"
)
const (
@@ -34,14 +35,14 @@ func NewMessageHandler() *MessageHandler {
func (h *MessageHandler) Tail(data []byte) {
defer func() {
if r := recover(); r != nil {
logrus.Errorf("recovered: %v", r)
dl.Errorf("recovered: %v", r)
}
}()
h.readBuffer.Write(data)
if line, err := h.readBuffer.ReadString('\n'); err == nil {
line = strings.Trim(line, "\n \t")
logrus.Debugf("line: '%v'", line)
dl.Debugf("line: '%v'", line)
msg := make(map[string]interface{})
if !h.booted {
if line[0] == '{' {
@@ -74,7 +75,7 @@ func (h *MessageHandler) Tail(data []byte) {
} else {
if line[0] == '{' {
if err := json.Unmarshal([]byte(line), &msg); err != nil {
logrus.Error(line)
dl.Error(line)
}
} else {
msg[MessageKey] = RawMessage
+9 -8
View File
@@ -2,12 +2,13 @@ package main
import (
"context"
"github.com/openziti/zrok/canary"
"github.com/openziti/zrok/environment"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"math/rand"
"time"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/canary"
"github.com/openziti/zrok/environment"
"github.com/spf13/cobra"
)
func init() {
@@ -54,7 +55,7 @@ func newTestCanaryEnabler() *testCanaryEnabler {
func (cmd *testCanaryEnabler) run(_ *cobra.Command, _ []string) {
if err := canary.AcknowledgeDangerousCanary(); err != nil {
logrus.Fatal(err)
dl.Fatal(err)
}
root, err := environment.LoadRoot()
@@ -124,7 +125,7 @@ func (cmd *testCanaryEnabler) run(_ *cobra.Command, _ []string) {
go disabler.Run()
}
for _, disabler := range disablers {
logrus.Infof("waiting for disabler #%d", disabler.Id)
dl.Infof("waiting for disabler #%d", disabler.Id)
<-disabler.Done
}
@@ -137,7 +138,7 @@ func (cmd *testCanaryEnabler) run(_ *cobra.Command, _ []string) {
if !ok {
break enablerLoop
}
logrus.Infof("enabler #%d: %v", enabler.Id, env.ZitiIdentity)
dl.Infof("enabler #%d: %v", enabler.Id, env.ZitiIdentity)
}
}
}
@@ -152,5 +153,5 @@ func (cmd *testCanaryEnabler) run(_ *cobra.Command, _ []string) {
<-sns.Closed
}
logrus.Info("complete")
dl.Info("complete")
}
+7 -6
View File
@@ -2,15 +2,16 @@ package main
import (
"context"
"github.com/openziti/zrok/canary"
"github.com/openziti/zrok/environment"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"math/rand"
"os"
"os/signal"
"syscall"
"time"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/canary"
"github.com/openziti/zrok/environment"
"github.com/spf13/cobra"
)
func init() {
@@ -80,7 +81,7 @@ func newTestCanaryPrivateProxy() *testCanaryPrivateProxy {
func (cmd *testCanaryPrivateProxy) run(_ *cobra.Command, _ []string) {
if err := canary.AcknowledgeDangerousCanary(); err != nil {
logrus.Fatal(err)
dl.Fatal(err)
}
root, err := environment.LoadRoot()
@@ -89,7 +90,7 @@ func (cmd *testCanaryPrivateProxy) run(_ *cobra.Command, _ []string) {
}
if !root.IsEnabled() {
logrus.Fatal("unable to load environment; did you 'zrok enable'?")
dl.Fatal("unable to load environment; did you 'zrok enable'?")
}
var sns *canary.SnapshotStreamer
+7 -6
View File
@@ -2,15 +2,16 @@ package main
import (
"context"
"github.com/openziti/zrok/canary"
"github.com/openziti/zrok/environment"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"math/rand"
"os"
"os/signal"
"syscall"
"time"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/canary"
"github.com/openziti/zrok/environment"
"github.com/spf13/cobra"
)
func init() {
@@ -80,7 +81,7 @@ func newTestCanaryPublicProxy() *testCanaryPublicProxy {
func (cmd *testCanaryPublicProxy) run(_ *cobra.Command, _ []string) {
if err := canary.AcknowledgeDangerousCanary(); err != nil {
logrus.Fatal(err)
dl.Fatal(err)
}
root, err := environment.LoadRoot()
@@ -89,7 +90,7 @@ func (cmd *testCanaryPublicProxy) run(_ *cobra.Command, _ []string) {
}
if !root.IsEnabled() {
logrus.Fatal("unable to load environment; did you 'zrok enable'?")
dl.Fatal("unable to load environment; did you 'zrok enable'?")
}
var sns *canary.SnapshotStreamer
+6 -6
View File
@@ -12,12 +12,12 @@ import (
"os"
"time"
"github.com/michaelquigley/df/dl"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/zrok/cmd/zrok/endpointUi"
"github.com/openziti/zrok/tui"
"github.com/openziti/zrok/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/time/rate"
"nhooyr.io/websocket"
@@ -120,16 +120,16 @@ func (cmd *testEndpointCommand) run(_ *cobra.Command, _ []string) {
}
func (cmd *testEndpointCommand) serveIndex(w http.ResponseWriter, r *http.Request) {
logrus.Infof("%v {%v} | %v -> /index.gohtml", r.RemoteAddr, r.Host, r.RequestURI)
dl.Infof("%v {%v} | %v -> /index.gohtml", r.RemoteAddr, r.Host, r.RequestURI)
if err := cmd.t.Execute(w, newEndpointData(r)); err != nil {
logrus.Error(err)
dl.Error(err)
}
}
func (cmd *testEndpointCommand) websocketEcho(w http.ResponseWriter, r *http.Request) {
c, err := websocket.Accept(w, r, nil)
if err != nil {
logrus.Error(err)
dl.Error(err)
return
}
defer func() { _ = c.Close(websocket.StatusInternalError, "connection terminated") }()
@@ -141,7 +141,7 @@ func (cmd *testEndpointCommand) websocketEcho(w http.ResponseWriter, r *http.Req
return
}
if err != nil {
logrus.Errorf("failed to echo for '%v': %v", r.RemoteAddr, err)
dl.Errorf("failed to echo for '%v': %v", r.RemoteAddr, err)
return
}
}
@@ -203,7 +203,7 @@ func newEndpointData(r *http.Request) *endpointData {
func (ed *endpointData) getHostInfo() {
host, hostDetail, _, err := util.GetHostDetails()
if err != nil {
logrus.Errorf("error getting host detail: %v", err)
dl.Errorf("error getting host detail: %v", err)
}
ed.Host = host
ed.HostDetail = hostDetail
+18 -18
View File
@@ -3,13 +3,13 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/jmoiron/sqlx"
"github.com/michaelquigley/df/dl"
"github.com/openziti/edge-api/rest_model"
"github.com/openziti/zrok/controller/automation"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/share"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type accessHandler struct{}
@@ -21,7 +21,7 @@ func newAccessHandler() *accessHandler {
func (h *accessHandler) Handle(params share.AccessParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
return share.NewAccessInternalServerError()
}
defer func() { _ = trx.Rollback() }()
@@ -32,53 +32,53 @@ func (h *accessHandler) Handle(params share.AccessParams, principal *rest_model_
found := false
for _, env := range envs {
if env.ZId == envZId {
logrus.Debugf("found identity '%v' for user '%v'", envZId, principal.Email)
dl.Debugf("found identity '%v' for user '%v'", envZId, principal.Email)
envId = env.Id
found = true
break
}
}
if !found {
logrus.Errorf("environment '%v' not found for user '%v'", envZId, principal.Email)
dl.Errorf("environment '%v' not found for user '%v'", envZId, principal.Email)
return share.NewAccessUnauthorized()
}
} else {
logrus.Errorf("error finding environments for account '%v'", principal.Email)
dl.Errorf("error finding environments for account '%v'", principal.Email)
return share.NewAccessNotFound()
}
shrToken := params.Body.ShareToken
shr, err := str.FindShareWithToken(shrToken, trx)
if err != nil {
logrus.Errorf("error finding share with token '%v': %v", shrToken, err)
dl.Errorf("error finding share with token '%v': %v", shrToken, err)
return share.NewAccessNotFound()
}
if shr == nil {
logrus.Errorf("unable to find share '%v' for user '%v'", shrToken, principal.Email)
dl.Errorf("unable to find share '%v' for user '%v'", shrToken, principal.Email)
return share.NewAccessNotFound()
}
if shr.PermissionMode == store.ClosedPermissionMode {
shrEnv, err := str.GetEnvironment(shr.EnvironmentId, trx)
if err != nil {
logrus.Errorf("error getting environment for share '%v': %v", shrToken, err)
dl.Errorf("error getting environment for share '%v': %v", shrToken, err)
return share.NewAccessInternalServerError()
}
if err := h.checkAccessGrants(shr, *shrEnv.AccountId, principal, trx); err != nil {
logrus.Errorf("closed permission mode for '%v' fails for '%v': %v", shr.Token, principal.Email, err)
dl.Errorf("closed permission mode for '%v' fails for '%v': %v", shr.Token, principal.Email, err)
return share.NewAccessUnauthorized()
}
}
if err := h.checkLimits(shr, trx); err != nil {
logrus.Errorf("cannot access limited share for '%v': %v", principal.Email, err)
dl.Errorf("cannot access limited share for '%v': %v", principal.Email, err)
return share.NewAccessNotFound()
}
feToken, err := CreateToken()
if err != nil {
logrus.Error(err)
dl.Error(err)
return share.NewAccessInternalServerError()
}
@@ -87,13 +87,13 @@ func (h *accessHandler) Handle(params share.AccessParams, principal *rest_model_
fe.BindAddress = &params.Body.BindAddress
}
if _, err := str.CreateFrontend(envId, fe, trx); err != nil {
logrus.Errorf("error creating frontend record for user '%v': %v", principal.Email, err)
dl.Errorf("error creating frontend record for user '%v': %v", principal.Email, err)
return share.NewAccessInternalServerError()
}
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
logrus.Error(err)
dl.Error(err)
return share.NewAccessInternalServerError()
}
@@ -114,12 +114,12 @@ func (h *accessHandler) Handle(params share.AccessParams, principal *rest_model_
}
if _, err := ziti.ServicePolicies.CreateDial(opts); err != nil {
logrus.Errorf("unable to create dial policy for user '%v': %v", principal.Email, err)
dl.Errorf("unable to create dial policy for user '%v': %v", principal.Email, err)
return share.NewAccessInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing frontend record: %v", err)
dl.Errorf("error committing frontend record: %v", err)
return share.NewAccessInternalServerError()
}
@@ -144,16 +144,16 @@ func (h *accessHandler) checkLimits(shr *store.Share, trx *sqlx.Tx) error {
func (h *accessHandler) checkAccessGrants(shr *store.Share, ownerAccountId int, principal *rest_model_zrok.Principal, trx *sqlx.Tx) error {
if int(principal.ID) == ownerAccountId {
logrus.Infof("accessing own share '%v' for '%v'", shr.Token, principal.Email)
dl.Infof("accessing own share '%v' for '%v'", shr.Token, principal.Email)
return nil
}
count, err := str.IsAccessGrantedToAccountForShare(shr.Id, int(principal.ID), trx)
if err != nil {
logrus.Infof("error checking access grants for '%v': %v", shr.Token, err)
dl.Infof("error checking access grants for '%v': %v", shr.Token, err)
return err
}
if count > 0 {
logrus.Infof("found '%d' grants for '%v'", count, principal.Email)
dl.Infof("found '%d' grants for '%v'", count, principal.Email)
return nil
}
return errors.Errorf("access denied for '%v' accessing '%v'", principal.Email, shr.Token)
+5 -5
View File
@@ -2,9 +2,9 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/metadata"
"github.com/sirupsen/logrus"
)
type accountDetailHandler struct{}
@@ -16,13 +16,13 @@ func newAccountDetailHandler() *accountDetailHandler {
func (h *accountDetailHandler) Handle(params metadata.GetAccountDetailParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return metadata.NewGetAccountDetailInternalServerError()
}
defer func() { _ = trx.Rollback() }()
envs, err := str.FindEnvironmentsForAccount(int(principal.ID), trx)
if err != nil {
logrus.Errorf("error retrieving environments for '%v': %v", principal.Email, err)
dl.Errorf("error retrieving environments for '%v': %v", principal.Email, err)
return metadata.NewGetAccountDetailInternalServerError()
}
sparkRx := make(map[int][]int64)
@@ -30,10 +30,10 @@ func (h *accountDetailHandler) Handle(params metadata.GetAccountDetailParams, pr
if cfg.Metrics != nil && cfg.Metrics.Influx != nil {
sparkRx, sparkTx, err = sparkDataForEnvironments(envs)
if err != nil {
logrus.Errorf("error querying spark data for environments for '%v': %v", principal.Email, err)
dl.Errorf("error querying spark data for environments for '%v': %v", principal.Email, err)
}
} else {
logrus.Debug("skipping spark data for environments; no influx configuration")
dl.Debug("skipping spark data for environments; no influx configuration")
}
var payload []*rest_model_zrok.Environment
for _, env := range envs {
+10 -10
View File
@@ -4,9 +4,9 @@ import (
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type addFrontendGrantHandler struct{}
@@ -17,47 +17,47 @@ func newAddFrontendGrantHandler() *addFrontendGrantHandler {
func (h *addFrontendGrantHandler) Handle(params admin.AddFrontendGrantParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Error("invalid admin principal")
dl.Error("invalid admin principal")
return admin.NewAddFrontendGrantUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewAddFrontendGrantInternalServerError()
}
defer trx.Rollback()
fe, err := str.FindFrontendWithToken(params.Body.FrontendToken, trx)
if err != nil {
logrus.Errorf("error finding frontend with token '%v': %v", params.Body.FrontendToken, err)
dl.Errorf("error finding frontend with token '%v': %v", params.Body.FrontendToken, err)
return admin.NewAddFrontendGrantNotFound().WithPayload(rest_model_zrok.ErrorMessage(fmt.Sprintf("frontend token '%v' not found", params.Body.FrontendToken)))
}
acct, err := str.FindAccountWithEmail(params.Body.Email, trx)
if err != nil {
logrus.Errorf("error finding account with email '%v': %v", params.Body.Email, err)
dl.Errorf("error finding account with email '%v': %v", params.Body.Email, err)
return admin.NewAddFrontendGrantNotFound().WithPayload(rest_model_zrok.ErrorMessage(fmt.Sprintf("account '%v' not found", params.Body.Email)))
}
if granted, err := str.IsFrontendGrantedToAccount(fe.Id, acct.Id, trx); err != nil {
logrus.Errorf("error checking frontend grant for account '%v' and frontend '%v': %v", acct.Email, fe.Token, err)
dl.Errorf("error checking frontend grant for account '%v' and frontend '%v': %v", acct.Email, fe.Token, err)
return admin.NewAddFrontendGrantInternalServerError()
} else if !granted {
if _, err := str.CreateFrontendGrant(fe.Id, acct.Id, trx); err != nil {
logrus.Errorf("error creating frontend ('%v') grant for '%v': %v", fe.Token, acct.Email, err)
dl.Errorf("error creating frontend ('%v') grant for '%v': %v", fe.Token, acct.Email, err)
return admin.NewAddFrontendGrantInternalServerError()
}
logrus.Infof("granted '%v' access to frontend '%v'", acct.Email, fe.Token)
dl.Infof("granted '%v' access to frontend '%v'", acct.Email, fe.Token)
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return admin.NewAddFrontendGrantInternalServerError()
}
} else {
logrus.Infof("account '%v' already granted access to frontend '%v'", acct.Email, fe.Token)
dl.Infof("account '%v' already granted access to frontend '%v'", acct.Email, fe.Token)
}
return admin.NewAddFrontendGrantOK()
+8 -8
View File
@@ -2,9 +2,9 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type addNamespaceFrontendMappingHandler struct{}
@@ -15,13 +15,13 @@ func newAddNamespaceFrontendMappingHandler() *addNamespaceFrontendMappingHandler
func (handler *addNamespaceFrontendMappingHandler) Handle(params admin.AddNamespaceFrontendMappingParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Errorf("invalid admin principal")
dl.Errorf("invalid admin principal")
return admin.NewAddNamespaceFrontendMappingUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewAddNamespaceFrontendMappingInternalServerError()
}
defer func() { _ = trx.Rollback() }()
@@ -32,27 +32,27 @@ func (handler *addNamespaceFrontendMappingHandler) Handle(params admin.AddNamesp
ns, err := str.FindNamespaceWithToken(nsToken, trx)
if err != nil {
logrus.Errorf("error finding namespace by token '%s': %v", nsToken, err)
dl.Errorf("error finding namespace by token '%s': %v", nsToken, err)
return admin.NewAddNamespaceFrontendMappingNotFound()
}
fe, err := str.FindFrontendWithToken(feToken, trx)
if err != nil {
logrus.Errorf("error finding frontend by token '%s': %v", feToken, err)
dl.Errorf("error finding frontend by token '%s': %v", feToken, err)
return admin.NewAddNamespaceFrontendMappingNotFound()
}
_, err = str.CreateNamespaceFrontendMapping(ns.Id, fe.Id, isDefault, trx)
if err != nil {
logrus.Errorf("error creating namespace frontend mapping: %v", err)
dl.Errorf("error creating namespace frontend mapping: %v", err)
return admin.NewAddNamespaceFrontendMappingInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return admin.NewAddNamespaceFrontendMappingInternalServerError()
}
logrus.Infof("added namespace frontend mapping for namespace '%s' and frontend '%s'", nsToken, feToken)
dl.Infof("added namespace frontend mapping for namespace '%s' and frontend '%s'", nsToken, feToken)
return admin.NewAddNamespaceFrontendMappingOK()
}
+10 -10
View File
@@ -2,10 +2,10 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type addNamespaceGrantHandler struct{}
@@ -16,31 +16,31 @@ func newAddNamespaceGrantHandler() *addNamespaceGrantHandler {
func (h *addNamespaceGrantHandler) Handle(params admin.AddNamespaceGrantParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Error("invalid admin principal")
dl.Error("invalid admin principal")
return admin.NewAddNamespaceGrantUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewAddNamespaceGrantInternalServerError()
}
defer trx.Rollback()
ns, err := str.FindNamespaceWithToken(params.Body.NamespaceToken, trx)
if err != nil {
logrus.Errorf("error finding namespace with token '%v': %v", params.Body.NamespaceToken, err)
dl.Errorf("error finding namespace with token '%v': %v", params.Body.NamespaceToken, err)
return admin.NewAddNamespaceGrantNotFound()
}
acct, err := str.FindAccountWithEmail(params.Body.Email, trx)
if err != nil {
logrus.Errorf("error finding account with email '%v': %v", params.Body.Email, err)
dl.Errorf("error finding account with email '%v': %v", params.Body.Email, err)
return admin.NewAddNamespaceGrantNotFound()
}
if granted, err := str.CheckNamespaceGrant(ns.Id, acct.Id, trx); err != nil {
logrus.Errorf("error checking namespace grant for account '%v' and namespace '%v': %v", acct.Email, ns.Token, err)
dl.Errorf("error checking namespace grant for account '%v' and namespace '%v': %v", acct.Email, ns.Token, err)
return admin.NewAddNamespaceGrantInternalServerError()
} else if !granted {
@@ -49,18 +49,18 @@ func (h *addNamespaceGrantHandler) Handle(params admin.AddNamespaceGrantParams,
AccountId: acct.Id,
}
if _, err := str.CreateNamespaceGrant(ng, trx); err != nil {
logrus.Errorf("error creating namespace ('%v') grant for '%v': %v", ns.Token, acct.Email, err)
dl.Errorf("error creating namespace ('%v') grant for '%v': %v", ns.Token, acct.Email, err)
return admin.NewAddNamespaceGrantInternalServerError()
}
logrus.Infof("granted '%v' access to namespace '%v'", acct.Email, ns.Token)
dl.Infof("granted '%v' access to namespace '%v'", acct.Email, ns.Token)
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return admin.NewAddNamespaceGrantInternalServerError()
}
} else {
logrus.Infof("account '%v' already granted access to namespace '%v'", acct.Email, ns.Token)
dl.Infof("account '%v' already granted access to namespace '%v'", acct.Email, ns.Token)
}
return admin.NewAddNamespaceGrantOK()
+7 -7
View File
@@ -2,9 +2,9 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type addOrganizationMemberHandler struct{}
@@ -15,36 +15,36 @@ func newAddOrganizationMemberHandler() *addOrganizationMemberHandler {
func (h *addOrganizationMemberHandler) Handle(params admin.AddOrganizationMemberParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Error("invalid admin principal")
dl.Error("invalid admin principal")
return admin.NewAddOrganizationMemberUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewAddOrganizationMemberInternalServerError()
}
defer func() { _ = trx.Rollback() }()
acct, err := str.FindAccountWithEmail(params.Body.Email, trx)
if err != nil {
logrus.Errorf("error finding account with email address '%v': %v", params.Body.Email, err)
dl.Errorf("error finding account with email address '%v': %v", params.Body.Email, err)
return admin.NewAddOrganizationMemberNotFound()
}
org, err := str.FindOrganizationByToken(params.Body.OrganizationToken, trx)
if err != nil {
logrus.Errorf("error finding organization '%v': %v", params.Body.OrganizationToken, err)
dl.Errorf("error finding organization '%v': %v", params.Body.OrganizationToken, err)
return admin.NewAddOrganizationMemberNotFound()
}
if err := str.AddAccountToOrganization(acct.Id, org.Id, params.Body.Admin, trx); err != nil {
logrus.Errorf("error adding account '%v' to organization '%v': %v", acct.Email, org.Token, err)
dl.Errorf("error adding account '%v' to organization '%v': %v", acct.Email, org.Token, err)
return admin.NewAddOrganizationMemberInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return admin.NewAddOrganizationMemberInternalServerError()
}
+14 -13
View File
@@ -2,12 +2,13 @@ package controller
import (
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/edge-api/rest_model"
"github.com/openziti/zrok/controller/automation"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentEnrollHandler struct{}
@@ -20,32 +21,32 @@ func (h *agentEnrollHandler) Handle(params agent.EnrollParams, principal *rest_m
// start transaction early, if it fails, don't bother creating ziti resources
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return agent.NewEnrollInternalServerError()
}
defer trx.Rollback()
env, err := str.FindEnvironmentForAccount(params.Body.EnvZID, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
return agent.NewEnrollUnauthorized()
}
if _, err := str.FindAgentEnrollmentForEnvironment(env.Id, trx); err == nil {
logrus.Errorf("environment '%v' (%v) is already enrolled!", params.Body.EnvZID, principal.Email)
dl.Errorf("environment '%v' (%v) is already enrolled!", params.Body.EnvZID, principal.Email)
return agent.NewEnrollBadRequest()
}
token, err := CreateToken()
if err != nil {
logrus.Errorf("error creating agent enrollment token for '%v': %v", principal.Email, err)
dl.Errorf("error creating agent enrollment token for '%v': %v", principal.Email, err)
return agent.NewEnrollInternalServerError()
}
logrus.Infof("enrollment token: %v", token)
dl.Infof("enrollment token: %v", token)
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
logrus.Errorf("error getting automation client for '%v': %v", principal.Email, err)
dl.Errorf("error getting automation client for '%v': %v", principal.Email, err)
return agent.NewEnrollInternalServerError()
}
@@ -60,7 +61,7 @@ func (h *agentEnrollHandler) Handle(params agent.EnrollParams, principal *rest_m
}
zId, err := ziti.Services.Create(serviceOpts)
if err != nil {
logrus.Errorf("error creating agent remoting service for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error creating agent remoting service for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewEnrollInternalServerError()
}
@@ -77,7 +78,7 @@ func (h *agentEnrollHandler) Handle(params agent.EnrollParams, principal *rest_m
Semantic: rest_model.SemanticAllOf,
}
if _, err := ziti.ServicePolicies.CreateBind(bindOpts); err != nil {
logrus.Errorf("error creating agent remoting bind policy for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error creating agent remoting bind policy for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewEnrollInternalServerError()
}
@@ -94,7 +95,7 @@ func (h *agentEnrollHandler) Handle(params agent.EnrollParams, principal *rest_m
Semantic: rest_model.SemanticAllOf,
}
if _, err := ziti.ServicePolicies.CreateDial(dialOpts); err != nil {
logrus.Errorf("error creating agent remoting dial policy for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error creating agent remoting dial policy for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewEnrollInternalServerError()
}
@@ -109,17 +110,17 @@ func (h *agentEnrollHandler) Handle(params agent.EnrollParams, principal *rest_m
Semantic: rest_model.SemanticAllOf,
}
if _, err := ziti.ServiceEdgeRouterPolicies.Create(serpOpts); err != nil {
logrus.Errorf("error creating agent remoting serp for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error creating agent remoting serp for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewEnrollInternalServerError()
}
if _, err := str.CreateAgentEnrollment(env.Id, token, trx); err != nil {
logrus.Errorf("error storing agent enrollment for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error storing agent enrollment for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewEnrollInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing agent enrollment record for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error committing agent enrollment record for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewEnrollInternalServerError()
}
+6 -6
View File
@@ -4,10 +4,10 @@ import (
"context"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentPingHandler struct{}
@@ -19,33 +19,33 @@ func newAgentPingHandler() *agentPingHandler {
func (h *agentPingHandler) Handle(params agent.PingParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return agent.NewPingInternalServerError()
}
defer trx.Rollback()
env, err := str.FindEnvironmentForAccount(params.Body.EnvZID, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
return agent.NewPingUnauthorized()
}
ae, err := str.FindAgentEnrollmentForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding agent enrollment for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding agent enrollment for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewPingBadGateway()
}
agentClient, agentConn, err := agentCtrl.NewClient(ae.Token)
if err != nil {
logrus.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewPingInternalServerError()
}
defer agentConn.Close()
resp, err := agentClient.Version(context.Background(), &agentGrpc.VersionRequest{})
if err != nil {
logrus.Errorf("error retrieving agent version for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error retrieving agent version for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewPingBadGateway()
}
+6 -6
View File
@@ -4,10 +4,10 @@ import (
"context"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentRemoteAccessHandler struct{}
@@ -19,27 +19,27 @@ func newAgentRemoteAccessHandler() *agentRemoteAccessHandler {
func (h *agentRemoteAccessHandler) Handle(params agent.RemoteAccessParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return agent.NewRemoteAccessInternalServerError()
}
defer trx.Rollback()
env, err := str.FindEnvironmentForAccount(params.Body.EnvZID, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environment for '%v' (%v): %v", params.Body.EnvZID, principal.ID, err)
dl.Errorf("error finding environment for '%v' (%v): %v", params.Body.EnvZID, principal.ID, err)
return agent.NewRemoteAccessUnauthorized()
}
ae, err := str.FindAgentEnrollmentForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteAccessBadGateway()
}
_ = trx.Rollback() // ...or will block the access trx on sqlite
agentClient, agentConn, err := agentCtrl.NewClient(ae.Token)
if err != nil {
logrus.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteAccessInternalServerError()
}
defer agentConn.Close()
@@ -55,7 +55,7 @@ func (h *agentRemoteAccessHandler) Handle(params agent.RemoteAccessParams, princ
}
resp, err := agentClient.AccessPrivate(context.Background(), req)
if err != nil {
logrus.Errorf("error creating remote agent private access for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating remote agent private access for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteAccessBadGateway()
}
+8 -8
View File
@@ -4,10 +4,10 @@ import (
"context"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentRemoteShareHandler struct{}
@@ -19,27 +19,27 @@ func newAgentRemoteShareHandler() *agentRemoteShareHandler {
func (h *agentRemoteShareHandler) Handle(params agent.RemoteShareParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return agent.NewRemoteShareInternalServerError()
}
defer trx.Rollback()
env, err := str.FindEnvironmentForAccount(params.Body.EnvZID, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteShareUnauthorized()
}
ae, err := str.FindAgentEnrollmentForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteShareBadGateway()
}
_ = trx.Rollback() // ...or will block share trx on sqlite
agentClient, agentConn, err := agentCtrl.NewClient(ae.Token)
if err != nil {
logrus.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteShareInternalServerError()
}
defer agentConn.Close()
@@ -49,7 +49,7 @@ func (h *agentRemoteShareHandler) Handle(params agent.RemoteShareParams, princip
case "public":
token, frontendEndpoints, err := h.publicShare(params, agentClient)
if err != nil {
logrus.Errorf("error creating public remote agent share for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating public remote agent share for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteShareBadGateway()
}
out.Token = token
@@ -58,7 +58,7 @@ func (h *agentRemoteShareHandler) Handle(params agent.RemoteShareParams, princip
case "private":
token, err := h.privateShare(params, agentClient)
if err != nil {
logrus.Errorf("error creating private remote agent share for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating private remote agent share for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteShareBadGateway()
}
out.Token = token
@@ -89,7 +89,7 @@ func (h *agentRemoteShareHandler) publicShare(params agent.RemoteShareParams, cl
if err != nil {
return "", nil, err
}
logrus.Infof("got token '%v'", resp.Token)
dl.Infof("got token '%v'", resp.Token)
return resp.Token, resp.FrontendEndpoints, nil
}
+6 -6
View File
@@ -5,10 +5,10 @@ import (
"time"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentRemoteStatusHandler struct{}
@@ -20,33 +20,33 @@ func newAgentRemoteStatusHandler() *agentRemoteStatusHandler {
func (h *agentRemoteStatusHandler) Handle(params agent.RemoteStatusParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return agent.NewRemoteStatusInternalServerError()
}
defer trx.Rollback()
env, err := str.FindEnvironmentForAccount(params.Body.EnvZID, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environment '%v' for '%v' (%v)", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding environment '%v' for '%v' (%v)", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteStatusUnauthorized()
}
ae, err := str.FindAgentEnrollmentForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteStatusBadGateway()
}
agentClient, agentConn, err := agentCtrl.NewClient(ae.Token)
if err != nil {
logrus.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteStatusInternalServerError()
}
defer agentConn.Close()
resp, err := agentClient.Status(context.Background(), &agentGrpc.StatusRequest{})
if err != nil {
logrus.Errorf("error retrieving remote agent status for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error retrieving remote agent status for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteStatusBadGateway()
}
+6 -6
View File
@@ -4,10 +4,10 @@ import (
"context"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentRemoteUnaccessHandler struct{}
@@ -19,27 +19,27 @@ func newAgentRemoteUnaccessHandler() *agentRemoteUnaccessHandler {
func (h *agentRemoteUnaccessHandler) Handle(params agent.RemoteUnaccessParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return agent.NewRemoteUnshareInternalServerError()
}
defer trx.Rollback()
env, err := str.FindEnvironmentForAccount(params.Body.EnvZID, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteUnshareUnauthorized()
}
ae, err := str.FindAgentEnrollmentForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteUnshareBadGateway()
}
_ = trx.Rollback() // ...or will block unshare trx on sqlite
agentClient, agentConn, err := agentCtrl.NewClient(ae.Token)
if err != nil {
logrus.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteUnshareInternalServerError()
}
defer agentConn.Close()
@@ -47,7 +47,7 @@ func (h *agentRemoteUnaccessHandler) Handle(params agent.RemoteUnaccessParams, p
req := &agentGrpc.ReleaseAccessRequest{FrontendToken: params.Body.FrontendToken}
_, err = agentClient.ReleaseAccess(context.Background(), req)
if err != nil {
logrus.Errorf("error releasing access '%v' for '%v' (%v): %v", params.Body.FrontendToken, params.Body.EnvZID, principal.Email, err)
dl.Errorf("error releasing access '%v' for '%v' (%v): %v", params.Body.FrontendToken, params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteUnaccessBadGateway()
}
+6 -6
View File
@@ -4,10 +4,10 @@ import (
"context"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentRemoteUnshareHandler struct{}
@@ -19,27 +19,27 @@ func newAgentRemoteUnshareHandler() *agentRemoteUnshareHandler {
func (h *agentRemoteUnshareHandler) Handle(params agent.RemoteUnshareParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return agent.NewRemoteUnshareInternalServerError()
}
defer trx.Rollback()
env, err := str.FindEnvironmentForAccount(params.Body.EnvZID, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteUnshareUnauthorized()
}
ae, err := str.FindAgentEnrollmentForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteUnshareBadGateway()
}
_ = trx.Rollback() // ...or will block unshare trx on sqlite
agentClient, agentConn, err := agentCtrl.NewClient(ae.Token)
if err != nil {
logrus.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteUnshareInternalServerError()
}
defer agentConn.Close()
@@ -47,7 +47,7 @@ func (h *agentRemoteUnshareHandler) Handle(params agent.RemoteUnshareParams, pri
req := &agentGrpc.ReleaseShareRequest{Token: params.Body.Token}
_, err = agentClient.ReleaseShare(context.Background(), req)
if err != nil {
logrus.Errorf("error releasing share '%v' for '%v' (%v): %v", params.Body.Token, params.Body.EnvZID, principal.Email, err)
dl.Errorf("error releasing share '%v' for '%v' (%v): %v", params.Body.Token, params.Body.EnvZID, principal.Email, err)
return agent.NewRemoteUnshareBadGateway()
}
+6 -6
View File
@@ -4,10 +4,10 @@ import (
"context"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentShareHttpHealthcheckHandler struct{}
@@ -19,27 +19,27 @@ func newAgentShareHttpHealthcheckHandler() *agentShareHttpHealthcheckHandler {
func (h *agentShareHttpHealthcheckHandler) Handle(params agent.ShareHTTPHealthcheckParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return agent.NewShareHTTPHealthcheckInternalServerError()
}
defer trx.Rollback()
env, err := str.FindEnvironmentForAccount(params.Body.EnvZID, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
return agent.NewShareHTTPHealthcheckUnauthorized()
}
ae, err := str.FindAgentEnrollmentForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding agent enrollment for environment '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewShareHTTPHealthcheckBadGateway()
}
_ = trx.Rollback() // ...or will block share trx on sqlite
agentClient, agentConn, err := agentCtrl.NewClient(ae.Token)
if err != nil {
logrus.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewShareHTTPHealthcheckInternalServerError()
}
defer agentConn.Close()
@@ -53,7 +53,7 @@ func (h *agentShareHttpHealthcheckHandler) Handle(params agent.ShareHTTPHealthch
}
resp, err := agentClient.ShareHttpHealthcheck(context.Background(), req)
if err != nil {
logrus.Infof("error invoking remoted share '%v' http healthcheck for '%v': %v", params.Body.ShareToken, params.Body.EnvZID, err)
dl.Infof("error invoking remoted share '%v' http healthcheck for '%v': %v", params.Body.ShareToken, params.Body.EnvZID, err)
return agent.NewShareHTTPHealthcheckBadGateway()
}
+12 -11
View File
@@ -2,11 +2,12 @@ package controller
import (
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/automation"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentUnenrollHandler struct{}
@@ -19,64 +20,64 @@ func (h *agentUnenrollHandler) Handle(params agent.UnenrollParams, principal *re
// start transaction early, if it fails, don't bother creating ziti resources
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return agent.NewUnenrollInternalServerError()
}
defer trx.Rollback()
env, err := str.FindEnvironmentForAccount(params.Body.EnvZID, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding environment '%v' for '%v': %v", params.Body.EnvZID, principal.Email, err)
return agent.NewUnenrollUnauthorized()
}
ae, err := str.FindAgentEnrollmentForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding agent enrollment for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
dl.Errorf("error finding agent enrollment for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewUnenrollBadRequest()
}
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
logrus.Errorf("error getting automation client for '%v': %v", principal.Email, err)
dl.Errorf("error getting automation client for '%v': %v", principal.Email, err)
return agent.NewUnenrollInternalServerError()
}
// delete service edge router policies for agent remote
serpFilter := fmt.Sprintf("tags.zrokAgentRemote=\"%v\"", ae.Token)
if err := ziti.ServiceEdgeRouterPolicies.DeleteWithFilter(serpFilter); err != nil {
logrus.Errorf("error removing agent remote serp for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error removing agent remote serp for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewUnenrollInternalServerError()
}
// delete dial service policies for agent remote
dialFilter := fmt.Sprintf("tags.zrokAgentRemote=\"%v\" and type=1", ae.Token)
if err := ziti.ServicePolicies.DeleteWithFilter(dialFilter); err != nil {
logrus.Errorf("error removing agent remote dial service policy for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error removing agent remote dial service policy for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewUnenrollInternalServerError()
}
// delete bind service policies for agent remote
bindFilter := fmt.Sprintf("tags.zrokAgentRemote=\"%v\" and type=2", ae.Token)
if err := ziti.ServicePolicies.DeleteWithFilter(bindFilter); err != nil {
logrus.Errorf("error removing agent remote bind service policy for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error removing agent remote bind service policy for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewUnenrollInternalServerError()
}
// find and delete the agent remote service
serviceFilter := fmt.Sprintf("name=\"%v\"", ae.Token)
if err := ziti.Services.DeleteWithFilter(serviceFilter); err != nil {
logrus.Errorf("error removing agent remote service for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error removing agent remote service for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewUnenrollInternalServerError()
}
if err := str.DeleteAgentEnrollment(ae.Id, trx); err != nil {
logrus.Errorf("error deleting agent enrollment for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error deleting agent enrollment for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewUnenrollInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing agent unenrollment for '%v' (%v): %v", env.ZId, principal.Email, err)
dl.Errorf("error committing agent unenrollment for '%v' (%v): %v", env.ZId, principal.Email, err)
return agent.NewUnenrollInternalServerError()
}
+4 -4
View File
@@ -1,10 +1,10 @@
package automation
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/edge-api/rest_management_api_client/config"
"github.com/openziti/edge-api/rest_model"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type ConfigManager struct {
@@ -42,7 +42,7 @@ func (cm *ConfigManager) Create(opts *ConfigOptions) (string, error) {
return "", errors.Wrapf(err, "error creating config '%s'", opts.Name)
}
logrus.Infof("created config '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
dl.Infof("created config '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
return resp.Payload.Data.ID, nil
}
@@ -63,7 +63,7 @@ func (cm *ConfigManager) Update(id string, opts *ConfigOptions) error {
return errors.Wrapf(err, "error updating config '%s'", id)
}
logrus.Infof("updated config '%s'", id)
dl.Infof("updated config '%s'", id)
return nil
}
@@ -79,7 +79,7 @@ func (cm *ConfigManager) Delete(id string) error {
return errors.Wrapf(err, "error deleting config '%s'", id)
}
logrus.Infof("deleted config '%s'", id)
dl.Infof("deleted config '%s'", id)
return nil
}
+4 -4
View File
@@ -1,10 +1,10 @@
package automation
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/edge-api/rest_management_api_client/config"
"github.com/openziti/edge-api/rest_model"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type ConfigTypeManager struct {
@@ -40,7 +40,7 @@ func (ctm *ConfigTypeManager) Create(opts *ConfigTypeOptions) (string, error) {
return "", errors.Wrapf(err, "error creating config type '%s'", opts.Name)
}
logrus.Infof("created config type '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
dl.Infof("created config type '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
return resp.Payload.Data.ID, nil
}
@@ -56,7 +56,7 @@ func (ctm *ConfigTypeManager) Delete(id string) error {
return errors.Wrapf(err, "error deleting config type '%s'", id)
}
logrus.Infof("deleted config type '%s'", id)
dl.Infof("deleted config type '%s'", id)
return nil
}
@@ -96,7 +96,7 @@ func (ctm *ConfigTypeManager) EnsureExists(name string) (string, error) {
}
if existing != nil {
logrus.Infof("found existing config type '%s' with id '%s'", name, *existing.ID)
dl.Infof("found existing config type '%s' with id '%s'", name, *existing.ID)
return *existing.ID, nil
}
+3 -3
View File
@@ -1,10 +1,10 @@
package automation
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/edge-api/rest_management_api_client/edge_router_policy"
"github.com/openziti/edge-api/rest_model"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type EdgeRouterPolicyManager struct {
@@ -44,7 +44,7 @@ func (erpm *EdgeRouterPolicyManager) Create(opts *EdgeRouterPolicyOptions) (stri
return "", errors.Wrapf(err, "error creating edge router policy '%s'", opts.Name)
}
logrus.Infof("created edge router policy '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
dl.Infof("created edge router policy '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
return resp.Payload.Data.ID, nil
}
@@ -60,7 +60,7 @@ func (erpm *EdgeRouterPolicyManager) Delete(id string) error {
return errors.Wrapf(err, "error deleting edge router policy '%s'", id)
}
logrus.Infof("deleted edge router policy '%s'", id)
dl.Infof("deleted edge router policy '%s'", id)
return nil
}
+4 -4
View File
@@ -1,12 +1,12 @@
package automation
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/edge-api/rest_management_api_client/identity"
"github.com/openziti/edge-api/rest_model"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/enroll"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type IdentityManager struct {
@@ -45,7 +45,7 @@ func (im *IdentityManager) Create(opts *IdentityOptions) (string, error) {
return "", errors.Wrapf(err, "error creating identity '%s'", opts.Name)
}
logrus.Infof("created identity '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
dl.Infof("created identity '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
return resp.Payload.Data.ID, nil
}
@@ -61,7 +61,7 @@ func (im *IdentityManager) Delete(id string) error {
return errors.Wrapf(err, "error deleting identity '%s'", id)
}
logrus.Infof("deleted identity '%s'", id)
dl.Infof("deleted identity '%s'", id)
return nil
}
@@ -121,7 +121,7 @@ func (im *IdentityManager) Enroll(id string) (*ziti.Config, error) {
return nil, errors.Wrap(err, "error enrolling identity")
}
logrus.Infof("enrolled identity '%s'", id)
dl.Infof("enrolled identity '%s'", id)
return conf, nil
}
+3 -3
View File
@@ -1,10 +1,10 @@
package automation
import (
"github.com/michaelquigley/df/dl"
edgeservice "github.com/openziti/edge-api/rest_management_api_client/service"
"github.com/openziti/edge-api/rest_model"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type ServiceManager struct {
@@ -63,7 +63,7 @@ func (sm *ServiceManager) Create(opts *ServiceOptions) (string, error) {
return "", errors.Wrapf(err, "error creating service '%s'", opts.Name)
}
logrus.Infof("created service '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
dl.Infof("created service '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
return resp.Payload.Data.ID, nil
}
@@ -79,7 +79,7 @@ func (sm *ServiceManager) Delete(id string) error {
return errors.Wrapf(err, "error deleting service '%s'", id)
}
logrus.Infof("deleted service '%s'", id)
dl.Infof("deleted service '%s'", id)
return nil
}
@@ -1,10 +1,10 @@
package automation
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/edge-api/rest_management_api_client/service_edge_router_policy"
"github.com/openziti/edge-api/rest_model"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type ServiceEdgeRouterPolicyManager struct {
@@ -44,7 +44,7 @@ func (serpm *ServiceEdgeRouterPolicyManager) Create(opts *ServiceEdgeRouterPolic
return "", errors.Wrapf(err, "error creating service edge router policy '%s'", opts.Name)
}
logrus.Infof("created service edge router policy '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
dl.Infof("created service edge router policy '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
return resp.Payload.Data.ID, nil
}
@@ -60,7 +60,7 @@ func (serpm *ServiceEdgeRouterPolicyManager) Delete(id string) error {
return errors.Wrapf(err, "error deleting service edge router policy '%s'", id)
}
logrus.Infof("deleted service edge router policy '%s'", id)
dl.Infof("deleted service edge router policy '%s'", id)
return nil
}
+3 -3
View File
@@ -1,10 +1,10 @@
package automation
import (
"github.com/michaelquigley/df/dl"
"github.com/openziti/edge-api/rest_management_api_client/service_policy"
"github.com/openziti/edge-api/rest_model"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type ServicePolicyManager struct {
@@ -47,7 +47,7 @@ func (spm *ServicePolicyManager) Create(opts *ServicePolicyOptions) (string, err
return "", errors.Wrapf(err, "error creating service policy '%s'", opts.Name)
}
logrus.Infof("created service policy '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
dl.Infof("created service policy '%s' with id '%s'", opts.Name, resp.Payload.Data.ID)
return resp.Payload.Data.ID, nil
}
@@ -63,7 +63,7 @@ func (spm *ServicePolicyManager) Delete(id string) error {
return errors.Wrapf(err, "error deleting service policy '%s'", id)
}
logrus.Infof("deleted service policy '%s'", id)
dl.Infof("deleted service policy '%s'", id)
return nil
}
+10 -10
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"github.com/michaelquigley/df/dl"
restModelEdge "github.com/openziti/edge-api/rest_model"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/zrok/controller/automation"
@@ -13,7 +14,6 @@ import (
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
@@ -25,7 +25,7 @@ func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
return errors.Wrap(err, "error opening store")
}
logrus.Info("connecting to the ziti edge management api")
dl.Info("connecting to the ziti edge management api")
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
return errors.Wrap(err, "error connecting to the ziti edge management api")
@@ -38,10 +38,10 @@ func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
var frontendZId string
if !skipFrontend {
logrus.Info("creating identity for public frontend access")
dl.Info("creating identity for public frontend access")
if frontendZId, err = getIdentityId(env.PublicIdentityName()); err == nil {
logrus.Infof("frontend identity: %v", frontendZId)
dl.Infof("frontend identity: %v", frontendZId)
} else {
frontendZId, err = bootstrapIdentity(env.PublicIdentityName(), ziti)
if err != nil {
@@ -62,12 +62,12 @@ func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
defer func() { _ = trx.Rollback() }()
publicFe, err := str.FindFrontendWithZId(frontendZId, trx)
if err != nil {
logrus.Warnf("missing public frontend for ziti id '%v'; please use 'zrok admin create frontend %v public https://{token}.your.dns.name' to create a frontend instance", frontendZId, frontendZId)
dl.Warnf("missing public frontend for ziti id '%v'; please use 'zrok admin create frontend %v public https://{token}.your.dns.name' to create a frontend instance", frontendZId, frontendZId)
} else {
if publicFe.PublicName != nil && publicFe.UrlTemplate != nil {
logrus.Infof("found public frontend entry '%v' (%v) for ziti identity '%v'", *publicFe.PublicName, publicFe.Token, frontendZId)
dl.Infof("found public frontend entry '%v' (%v) for ziti identity '%v'", *publicFe.PublicName, publicFe.Token, frontendZId)
} else {
logrus.Warnf("found frontend entry for ziti identity '%v'; missing either public name or url template", frontendZId)
dl.Warnf("found frontend entry for ziti identity '%v'; missing either public name or url template", frontendZId)
}
}
}
@@ -119,7 +119,7 @@ func assertIdentity(zId string, auto *automation.ZitiAutomation) error {
if err != nil {
return errors.Wrapf(err, "error asserting identity '%v'", zId)
}
logrus.Infof("asserted identity '%v'", zId)
dl.Infof("asserted identity '%v'", zId)
return nil
}
@@ -170,7 +170,7 @@ func assertErpForIdentity(name, zId string, auto *automation.ZitiAutomation) err
}
if len(erps) != 1 {
logrus.Infof("creating erp for '%v' (%v)", name, zId)
dl.Infof("creating erp for '%v' (%v)", name, zId)
erpOpts := &automation.EdgeRouterPolicyOptions{
BaseOptions: automation.BaseOptions{
@@ -187,6 +187,6 @@ func assertErpForIdentity(name, zId string, auto *automation.ZitiAutomation) err
return errors.Wrapf(err, "error creating erp for '%v' (%v)", name, zId)
}
}
logrus.Infof("asserted erps for '%v' (%v)", name, zId)
dl.Infof("asserted erps for '%v' (%v)", name, zId)
return nil
}
+12 -12
View File
@@ -2,10 +2,10 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/config"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/account"
"github.com/sirupsen/logrus"
)
type changePasswordHandler struct {
@@ -20,56 +20,56 @@ func newChangePasswordHandler(cfg *config.Config) *changePasswordHandler {
func (handler *changePasswordHandler) Handle(params account.ChangePasswordParams, principal *rest_model_zrok.Principal) middleware.Responder {
if params.Body.Email == "" || params.Body.OldPassword == "" || params.Body.NewPassword == "" {
logrus.Error("missing email, old, or new password")
dl.Error("missing email, old, or new password")
return account.NewChangePasswordUnauthorized()
}
logrus.Infof("received change password request for email '%v'", params.Body.Email)
dl.Infof("received change password request for email '%v'", params.Body.Email)
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return account.NewChangePasswordUnauthorized()
}
defer func() { _ = trx.Rollback() }()
a, err := str.FindAccountWithEmail(params.Body.Email, trx)
if err != nil {
logrus.Errorf("error finding account '%v': %v", params.Body.Email, err)
dl.Errorf("error finding account '%v': %v", params.Body.Email, err)
return account.NewChangePasswordUnauthorized()
}
ohpwd, err := rehashPassword(params.Body.OldPassword, a.Salt)
if err != nil {
logrus.Errorf("error hashing password for '%v': %v", params.Body.Email, err)
dl.Errorf("error hashing password for '%v': %v", params.Body.Email, err)
return account.NewChangePasswordUnauthorized()
}
if a.Password != ohpwd.Password {
logrus.Errorf("password mismatch for account '%v'", params.Body.Email)
dl.Errorf("password mismatch for account '%v'", params.Body.Email)
return account.NewChangePasswordUnauthorized()
}
if err := validatePassword(handler.cfg, params.Body.NewPassword); err != nil {
logrus.Errorf("password not valid for request '%v': %v", a.Email, err)
dl.Errorf("password not valid for request '%v': %v", a.Email, err)
return account.NewChangePasswordUnprocessableEntity().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
}
nhpwd, err := HashPassword(params.Body.NewPassword)
if err != nil {
logrus.Errorf("error hashing password for '%v': %v", a.Email, err)
dl.Errorf("error hashing password for '%v': %v", a.Email, err)
return account.NewChangePasswordInternalServerError()
}
a.Salt = nhpwd.Salt
a.Password = nhpwd.Password
if _, err := str.UpdateAccount(a, trx); err != nil {
logrus.Errorf("error updating for '%v': %v", a.Email, err)
dl.Errorf("error updating for '%v': %v", a.Email, err)
return account.NewChangePasswordInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing '%v': %v", a.Email, err)
dl.Errorf("error committing '%v': %v", a.Email, err)
return account.NewChangePasswordInternalServerError()
}
logrus.Infof("change password for '%v'", a.Email)
dl.Infof("change password for '%v'", a.Email)
return account.NewChangePasswordOK()
}
+4 -4
View File
@@ -9,6 +9,7 @@ import (
"github.com/go-openapi/loads"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/jessevdk/go-flags"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/agentController"
"github.com/openziti/zrok/controller/config"
"github.com/openziti/zrok/controller/dynamicProxyController"
@@ -20,7 +21,6 @@ import (
"github.com/openziti/zrok/rest_server_zrok/operations/account"
"github.com/openziti/zrok/rest_server_zrok/operations/metadata"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
var (
@@ -87,7 +87,7 @@ func Run(inCfg *config.Config) error {
if cfg.AgentController != nil {
if i, err := agentController.NewAgentController(cfg.AgentController); err == nil {
agentCtrl = i
logrus.Infof("created new agent controller")
dl.Infof("created new agent controller")
} else {
return errors.Wrap(err, "error creating agent controller")
}
@@ -149,13 +149,13 @@ func Run(inCfg *config.Config) error {
if err != nil {
return err
}
logrus.Infof("started dynamic proxy controller")
dl.Infof("started dynamic proxy controller")
}
if cfg.Metrics != nil && cfg.Metrics.Influx != nil {
idb = influxdb2.NewClient(cfg.Metrics.Influx.Url, cfg.Metrics.Influx.Token)
} else {
logrus.Warn("skipping influx client; no configuration")
dl.Warn("skipping influx client; no configuration")
}
if cfg.Metrics != nil && cfg.Metrics.Agent != nil && cfg.Metrics.Influx != nil {
+9 -9
View File
@@ -2,10 +2,10 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type createAccountHandler struct{}
@@ -16,28 +16,28 @@ func newCreateAccountHandler() *createAccountHandler {
func (h *createAccountHandler) Handle(params admin.CreateAccountParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Error("invalid admin principal")
dl.Error("invalid admin principal")
return admin.NewCreateAccountUnauthorized()
}
token, err := CreateToken()
if err != nil {
logrus.Errorf("error creating token: %v", err)
dl.Errorf("error creating token: %v", err)
return admin.NewCreateAccountInternalServerError()
}
hpwd, err := HashPassword(params.Body.Password)
if err != nil {
logrus.Errorf("error hashing password: %v", err)
dl.Errorf("error hashing password: %v", err)
return admin.NewCreateAccountInternalServerError()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewCreateAccountInternalServerError()
}
defer trx.Rollback()
a := &store.Account{
Email: params.Body.Email,
Salt: hpwd.Salt,
@@ -45,14 +45,14 @@ func (h *createAccountHandler) Handle(params admin.CreateAccountParams, principa
Token: token,
}
if _, err := str.CreateAccount(a, trx); err != nil {
logrus.Errorf("error creating account: %v", err)
dl.Errorf("error creating account: %v", err)
return admin.NewCreateAccountInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
}
logrus.Infof("administratively created account '%v'", params.Body.Email)
dl.Infof("administratively created account '%v'", params.Body.Email)
return admin.NewCreateAccountCreated().WithPayload(&admin.CreateAccountCreatedBody{AccountToken: token})
}
+10 -10
View File
@@ -6,11 +6,11 @@ import (
"github.com/go-openapi/runtime/middleware"
"github.com/lib/pq"
"github.com/mattn/go-sqlite3"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/automation"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type createFrontendHandler struct{}
@@ -21,37 +21,37 @@ func newCreateFrontendHandler() *createFrontendHandler {
func (h *createFrontendHandler) Handle(params admin.CreateFrontendParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Errorf("invalid admin principal")
dl.Errorf("invalid admin principal")
return admin.NewCreateFrontendUnauthorized()
}
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
logrus.Errorf("error getting automation client: %v", err)
dl.Errorf("error getting automation client: %v", err)
return admin.NewCreateFrontendInternalServerError()
}
zId := params.Body.ZID
identity, err := ziti.Identities.GetByID(zId)
if err != nil {
logrus.Errorf("error getting identity details for '%v': %v", zId, err)
dl.Errorf("error getting identity details for '%v': %v", zId, err)
if ziti.IsNotFound(err) {
return admin.NewCreateFrontendNotFound()
}
return admin.NewCreateFrontendInternalServerError()
}
logrus.Infof("found frontend identity '%v'", *identity.Name)
dl.Infof("found frontend identity '%v'", *identity.Name)
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewCreateFrontendInternalServerError()
}
defer func() { _ = trx.Rollback() }()
feToken, err := CreateToken()
if err != nil {
logrus.Errorf("error creating frontend token: %v", err)
dl.Errorf("error creating frontend token: %v", err)
return admin.NewCreateFrontendInternalServerError()
}
@@ -77,16 +77,16 @@ func (h *createFrontendHandler) Handle(params admin.CreateFrontendParams, princi
}
}
logrus.Errorf("error creating frontend record: %v", err)
dl.Errorf("error creating frontend record: %v", err)
return admin.NewCreateFrontendInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing frontend record: %v", err)
dl.Errorf("error committing frontend record: %v", err)
return admin.NewCreateFrontendInternalServerError()
}
logrus.Infof("created global frontend '%v' with public name '%v'", fe.Token, *fe.PublicName)
dl.Infof("created global frontend '%v' with public name '%v'", fe.Token, *fe.PublicName)
return admin.NewCreateFrontendCreated().WithPayload(&admin.CreateFrontendCreatedBody{FrontendToken: feToken})
}
+7 -7
View File
@@ -6,11 +6,11 @@ import (
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
rest_model_edge "github.com/openziti/edge-api/rest_model"
"github.com/openziti/zrok/controller/automation"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type createIdentityHandler struct{}
@@ -23,13 +23,13 @@ func (h *createIdentityHandler) Handle(params admin.CreateIdentityParams, princi
name := params.Body.Name
if !principal.Admin {
logrus.Errorf("invalid admin principal")
dl.Errorf("invalid admin principal")
return admin.NewCreateIdentityUnauthorized()
}
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
logrus.Errorf("error getting automation client: %v", err)
dl.Errorf("error getting automation client: %v", err)
return admin.NewCreateIdentityInternalServerError()
}
@@ -44,14 +44,14 @@ func (h *createIdentityHandler) Handle(params admin.CreateIdentityParams, princi
}
zId, err := ziti.Identities.Create(identityOpts)
if err != nil {
logrus.Errorf("error creating identity: %v", err)
dl.Errorf("error creating identity: %v", err)
return admin.NewCreateIdentityInternalServerError()
}
// enroll identity
idCfg, err := ziti.Identities.Enroll(zId)
if err != nil {
logrus.Errorf("error enrolling identity: %v", err)
dl.Errorf("error enrolling identity: %v", err)
return admin.NewCreateIdentityInternalServerError()
}
@@ -66,7 +66,7 @@ func (h *createIdentityHandler) Handle(params admin.CreateIdentityParams, princi
Semantic: rest_model_edge.SemanticAllOf,
}
if _, err := ziti.EdgeRouterPolicies.Create(erpOpts); err != nil {
logrus.Errorf("error creating edge router policy for identity: %v", err)
dl.Errorf("error creating edge router policy for identity: %v", err)
return admin.NewCreateIdentityInternalServerError()
}
@@ -75,7 +75,7 @@ func (h *createIdentityHandler) Handle(params admin.CreateIdentityParams, princi
enc.SetEscapeHTML(false)
err = enc.Encode(&idCfg)
if err != nil {
logrus.Errorf("error encoding identity config: %v", err)
dl.Errorf("error encoding identity config: %v", err)
return admin.NewCreateIdentityInternalServerError()
}
+8 -8
View File
@@ -2,10 +2,10 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type createNamespaceHandler struct{}
@@ -16,13 +16,13 @@ func newCreateNamespaceHandler() *createNamespaceHandler {
func (h *createNamespaceHandler) Handle(params admin.CreateNamespaceParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Errorf("invalid admin principal")
dl.Errorf("invalid admin principal")
return admin.NewCreateNamespaceUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewCreateNamespaceInternalServerError()
}
defer func() { _ = trx.Rollback() }()
@@ -30,7 +30,7 @@ func (h *createNamespaceHandler) Handle(params admin.CreateNamespaceParams, prin
// check if namespace already exists
if params.Body.Name != "" {
if _, err := str.FindNamespaceWithName(params.Body.Name, trx); err == nil {
logrus.Errorf("namespace '%v' already exists", params.Body.Name)
dl.Errorf("namespace '%v' already exists", params.Body.Name)
return admin.NewCreateNamespaceConflict()
}
}
@@ -41,7 +41,7 @@ func (h *createNamespaceHandler) Handle(params admin.CreateNamespaceParams, prin
} else {
namespaceToken, err = CreateToken()
if err != nil {
logrus.Errorf("error creating namespace token: %v", err)
dl.Errorf("error creating namespace token: %v", err)
return admin.NewCreateNamespaceInternalServerError()
}
}
@@ -53,16 +53,16 @@ func (h *createNamespaceHandler) Handle(params admin.CreateNamespaceParams, prin
Open: params.Body.Open,
}
if _, err := str.CreateNamespace(ns, trx); err != nil {
logrus.Errorf("error creating namespace: %v", err)
dl.Errorf("error creating namespace: %v", err)
return admin.NewCreateNamespaceInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing namespace: %v", err)
dl.Errorf("error committing namespace: %v", err)
return admin.NewCreateNamespaceInternalServerError()
}
logrus.Infof("added namespace '%v' with name '%v'", ns.Token, ns.Name)
dl.Infof("added namespace '%v' with name '%v'", ns.Token, ns.Name)
return admin.NewCreateNamespaceCreated().WithPayload(&admin.CreateNamespaceCreatedBody{NamespaceToken: ns.Token})
}
+7 -7
View File
@@ -2,10 +2,10 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type createOrganizationHandler struct{}
@@ -16,20 +16,20 @@ func newCreateOrganizationHandler() *createOrganizationHandler {
func (h *createOrganizationHandler) Handle(params admin.CreateOrganizationParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Errorf("invalid admin principal")
dl.Errorf("invalid admin principal")
return admin.NewCreateOrganizationUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewCreateOrganizationInternalServerError()
}
defer func() { _ = trx.Rollback() }()
orgToken, err := CreateToken()
if err != nil {
logrus.Errorf("error creating organization token: %v", err)
dl.Errorf("error creating organization token: %v", err)
return admin.NewCreateOrganizationInternalServerError()
}
@@ -38,16 +38,16 @@ func (h *createOrganizationHandler) Handle(params admin.CreateOrganizationParams
Description: params.Body.Description,
}
if _, err := str.CreateOrganization(org, trx); err != nil {
logrus.Errorf("error creating organization: %v", err)
dl.Errorf("error creating organization: %v", err)
return admin.NewCreateOrganizationInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing organization: %v", err)
dl.Errorf("error committing organization: %v", err)
return admin.NewCreateOrganizationInternalServerError()
}
logrus.Infof("added organzation '%v' with description '%v'", org.Token, org.Description)
dl.Infof("added organzation '%v' with description '%v'", org.Token, org.Description)
return admin.NewCreateOrganizationCreated().WithPayload(&admin.CreateOrganizationCreatedBody{OrganizationToken: org.Token})
}
+10 -11
View File
@@ -11,7 +11,6 @@ import (
"github.com/openziti/zrok/rest_server_zrok/operations/share"
"github.com/openziti/zrok/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type createShareNameHandler struct{}
@@ -23,7 +22,7 @@ func newCreateShareNameHandler() *createShareNameHandler {
func (h *createShareNameHandler) Handle(params share.CreateShareNameParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return share.NewCreateShareNameInternalServerError()
}
defer func() { _ = trx.Rollback() }()
@@ -31,7 +30,7 @@ func (h *createShareNameHandler) Handle(params share.CreateShareNameParams, prin
// find namespace
ns, err := str.FindNamespaceWithToken(params.Body.NamespaceToken, trx)
if err != nil {
logrus.Errorf("error finding namespace with token '%v': %v", params.Body.NamespaceToken, err)
dl.Errorf("error finding namespace with token '%v': %v", params.Body.NamespaceToken, err)
return share.NewCreateShareNameNotFound()
}
@@ -39,29 +38,29 @@ func (h *createShareNameHandler) Handle(params share.CreateShareNameParams, prin
if !ns.Open {
granted, err := str.CheckNamespaceGrant(ns.Id, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error checking namespace grant for account '%v' and namespace '%v': %v", principal.Email, ns.Token, err)
dl.Errorf("error checking namespace grant for account '%v' and namespace '%v': %v", principal.Email, ns.Token, err)
return share.NewCreateShareNameInternalServerError()
}
if !granted {
logrus.Errorf("account '%v' is not granted access to namespace '%v'", principal.Email, ns.Token)
dl.Errorf("account '%v' is not granted access to namespace '%v'", principal.Email, ns.Token)
return share.NewCreateShareNameUnauthorized()
}
}
// check limits
if err := h.checkLimits(principal, trx); err != nil {
logrus.Errorf("limits error: %v", err)
dl.Errorf("limits error: %v", err)
return share.NewCreateShareNameConflict().WithPayload("names limit reached; cannot reserve additional names")
}
// check name availability
available, err := str.CheckNameAvailability(ns.Id, params.Body.Name, trx)
if err != nil {
logrus.Errorf("error checking name availability for '%v' in namespace '%v': %v", params.Body.Name, ns.Token, err)
dl.Errorf("error checking name availability for '%v' in namespace '%v': %v", params.Body.Name, ns.Token, err)
return share.NewCreateShareNameInternalServerError()
}
if !available {
logrus.Errorf("name '%v' already exists in namespace '%v'", params.Body.Name, ns.Token)
dl.Errorf("name '%v' already exists in namespace '%v'", params.Body.Name, ns.Token)
return share.NewCreateShareNameConflict()
}
@@ -80,16 +79,16 @@ func (h *createShareNameHandler) Handle(params share.CreateShareNameParams, prin
}
_, err = str.CreateName(an, trx)
if err != nil {
logrus.Errorf("error creating allocated name '%v' in namespace '%v' for account '%v': %v", params.Body.Name, ns.Token, principal.Email, err)
dl.Errorf("error creating allocated name '%v' in namespace '%v' for account '%v': %v", params.Body.Name, ns.Token, principal.Email, err)
return share.NewCreateShareNameInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return share.NewCreateShareNameInternalServerError()
}
logrus.Infof("created allocated name '%v' in namespace '%v' for account '%v'", params.Body.Name, ns.Token, principal.Email)
dl.Infof("created allocated name '%v' in namespace '%v' for account '%v'", params.Body.Name, ns.Token, principal.Email)
return share.NewCreateShareNameCreated()
}
+14 -14
View File
@@ -2,10 +2,10 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/automation"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type deleteAccountHandler struct{}
@@ -16,57 +16,57 @@ func newDeleteAccountHandler() *deleteAccountHandler {
func (h *deleteAccountHandler) Handle(params admin.DeleteAccountParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Error("invalid admin principal")
dl.Error("invalid admin principal")
return admin.NewDeleteAccountUnauthorized()
}
logrus.Infof("starting deletion of account with email '%s'", params.Body.Email)
dl.Infof("starting deletion of account with email '%s'", params.Body.Email)
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewDeleteAccountInternalServerError()
}
defer trx.Rollback()
account, err := str.FindAccountWithEmail(params.Body.Email, trx)
if err != nil {
logrus.Errorf("error finding account with email '%s': %v", params.Body.Email, err)
dl.Errorf("error finding account with email '%s': %v", params.Body.Email, err)
return admin.NewDeleteAccountNotFound()
}
envs, err := str.FindEnvironmentsForAccount(account.Id, trx)
if err != nil {
logrus.Errorf("error finding environments for account '%s': %v", params.Body.Email, err)
dl.Errorf("error finding environments for account '%s': %v", params.Body.Email, err)
return admin.NewDeleteAccountInternalServerError()
}
logrus.Infof("found %d environments to clean up for account '%s'", len(envs), params.Body.Email)
dl.Infof("found %d environments to clean up for account '%s'", len(envs), params.Body.Email)
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
logrus.Errorf("error getting automation client: %v", err)
dl.Errorf("error getting automation client: %v", err)
return admin.NewDeleteAccountInternalServerError()
}
for _, env := range envs {
logrus.Infof("disabling environment '%d' (envZId: '%s') for account '%s'", env.Id, env.ZId, params.Body.Email)
dl.Infof("disabling environment '%d' (envZId: '%s') for account '%s'", env.Id, env.ZId, params.Body.Email)
if err := disableEnvironment(env, trx, ziti); err != nil {
logrus.Errorf("error disabling environment '%d' for account '%s': %v", env.Id, params.Body.Email, err)
dl.Errorf("error disabling environment '%d' for account '%s': %v", env.Id, params.Body.Email, err)
return admin.NewDeleteAccountInternalServerError()
}
logrus.Infof("successfully disabled environment '%d' for account '%s'", env.Id, params.Body.Email)
dl.Infof("successfully disabled environment '%d' for account '%s'", env.Id, params.Body.Email)
}
if err := str.DeleteAccount(account.Id, trx); err != nil {
logrus.Errorf("error deleting account '%s': %v", params.Body.Email, err)
dl.Errorf("error deleting account '%s': %v", params.Body.Email, err)
return admin.NewDeleteAccountInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return admin.NewDeleteAccountInternalServerError()
}
logrus.Infof("successfully deleted account '%s'", params.Body.Email)
dl.Infof("successfully deleted account '%s'", params.Body.Email)
return admin.NewDeleteAccountOK()
}
+6 -6
View File
@@ -2,9 +2,9 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type deleteFrontendHandler struct{}
@@ -17,30 +17,30 @@ func (h *deleteFrontendHandler) Handle(params admin.DeleteFrontendParams, princi
feToken := params.Body.FrontendToken
if !principal.Admin {
logrus.Errorf("invalid admin principal")
dl.Errorf("invalid admin principal")
return admin.NewDeleteFrontendUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewDeleteFrontendInternalServerError()
}
defer func() { _ = trx.Rollback() }()
fe, err := str.FindFrontendWithToken(feToken, trx)
if err != nil {
logrus.Errorf("error finding frontend with token '%v': %v", feToken, err)
dl.Errorf("error finding frontend with token '%v': %v", feToken, err)
return admin.NewDeleteFrontendNotFound()
}
if err := str.DeleteFrontend(fe.Id, trx); err != nil {
logrus.Errorf("error deleting frontend '%v': %v", feToken, err)
dl.Errorf("error deleting frontend '%v': %v", feToken, err)
return admin.NewDeleteFrontendInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing frontend '%v' deletion: %v", feToken, err)
dl.Errorf("error committing frontend '%v' deletion: %v", feToken, err)
return admin.NewDeleteFrontendInternalServerError()
}
+10 -10
View File
@@ -4,9 +4,9 @@ import (
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type deleteFrontendGrantHandler struct{}
@@ -17,47 +17,47 @@ func newDeleteFrontendGrantHandler() *deleteFrontendGrantHandler {
func (h *deleteFrontendGrantHandler) Handle(params admin.DeleteFrontendGrantParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Error("invalid admin principal")
dl.Error("invalid admin principal")
return admin.NewDeleteFrontendGrantUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewDeleteFrontendGrantInternalServerError()
}
defer trx.Rollback()
fe, err := str.FindFrontendWithToken(params.Body.FrontendToken, trx)
if err != nil {
logrus.Errorf("error finding frontend with token '%v': %v", params.Body.FrontendToken, err)
dl.Errorf("error finding frontend with token '%v': %v", params.Body.FrontendToken, err)
return admin.NewDeleteFrontendGrantNotFound().WithPayload(rest_model_zrok.ErrorMessage(fmt.Sprintf("frontend token '%v' not found", params.Body.FrontendToken)))
}
acct, err := str.FindAccountWithEmail(params.Body.Email, trx)
if err != nil {
logrus.Errorf("error finding account with email '%v': %v", params.Body.Email, err)
dl.Errorf("error finding account with email '%v': %v", params.Body.Email, err)
return admin.NewDeleteFrontendGrantNotFound().WithPayload(rest_model_zrok.ErrorMessage(fmt.Sprintf("account '%v' not found", params.Body.Email)))
}
if granted, err := str.IsFrontendGrantedToAccount(fe.Id, acct.Id, trx); err != nil {
logrus.Errorf("error checking frontend grant for account '%v' and frontend '%v': %v", acct.Email, fe.Token, err)
dl.Errorf("error checking frontend grant for account '%v' and frontend '%v': %v", acct.Email, fe.Token, err)
return admin.NewDeleteFrontendGrantInternalServerError()
} else if granted {
if err := str.DeleteFrontendGrant(fe.Id, acct.Id, trx); err != nil {
logrus.Errorf("error deleting frontend ('%v') grant for '%v': %v", fe.Token, acct.Email, err)
dl.Errorf("error deleting frontend ('%v') grant for '%v': %v", fe.Token, acct.Email, err)
return admin.NewDeleteFrontendGrantInternalServerError()
}
logrus.Infof("deleted '%v' access to frontend '%v'", acct.Email, fe.Token)
dl.Infof("deleted '%v' access to frontend '%v'", acct.Email, fe.Token)
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return admin.NewAddFrontendGrantInternalServerError()
}
} else {
logrus.Infof("account '%v' not granted access to frontend '%v'", acct.Email, fe.Token)
dl.Infof("account '%v' not granted access to frontend '%v'", acct.Email, fe.Token)
}
return admin.NewDeleteFrontendGrantOK()
+5 -5
View File
@@ -4,10 +4,10 @@ import (
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/automation"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type deleteIdentityHandler struct{}
@@ -20,26 +20,26 @@ func (h *deleteIdentityHandler) Handle(params admin.DeleteIdentityParams, princi
identityZId := params.Body.ZID
if !principal.Admin {
logrus.Errorf("invalid admin principal")
dl.Errorf("invalid admin principal")
return admin.NewDeleteIdentityUnauthorized()
}
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
logrus.Errorf("error getting automation client: %v", err)
dl.Errorf("error getting automation client: %v", err)
return admin.NewDeleteIdentityInternalServerError()
}
// delete edge router policy for the identity
erpFilter := fmt.Sprintf("name=\"%v\"", identityZId)
if err := ziti.EdgeRouterPolicies.DeleteWithFilter(erpFilter); err != nil {
logrus.Errorf("error deleting edge router policy: %v", err)
dl.Errorf("error deleting edge router policy: %v", err)
return admin.NewDeleteIdentityInternalServerError()
}
// delete the identity
if err := ziti.Identities.Delete(identityZId); err != nil {
logrus.Errorf("error deleting identity '%v': %v", identityZId, err)
dl.Errorf("error deleting identity '%v': %v", identityZId, err)
return admin.NewDeleteIdentityInternalServerError()
}
+7 -7
View File
@@ -2,9 +2,9 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type deleteNamespaceHandler struct{}
@@ -15,35 +15,35 @@ func newDeleteNamespaceHandler() *deleteNamespaceHandler {
func (h *deleteNamespaceHandler) Handle(params admin.DeleteNamespaceParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Errorf("invalid admin principal")
dl.Errorf("invalid admin principal")
return admin.NewDeleteNamespaceUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewDeleteNamespaceInternalServerError()
}
defer func() { _ = trx.Rollback() }()
ns, err := str.FindNamespaceWithToken(params.Body.NamespaceToken, trx)
if err != nil {
logrus.Errorf("error finding namespace by token: %v", err)
dl.Errorf("error finding namespace by token: %v", err)
return admin.NewDeleteNamespaceNotFound()
}
err = str.DeleteNamespace(ns.Id, trx)
if err != nil {
logrus.Errorf("error deleting namespace: %v", err)
dl.Errorf("error deleting namespace: %v", err)
return admin.NewDeleteNamespaceInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return admin.NewDeleteNamespaceInternalServerError()
}
logrus.Infof("deleted namespace '%v'", ns.Token)
dl.Infof("deleted namespace '%v'", ns.Token)
return admin.NewDeleteNamespaceOK()
}
+6 -6
View File
@@ -2,9 +2,9 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/admin"
"github.com/sirupsen/logrus"
)
type deleteOrganizationHandler struct{}
@@ -15,31 +15,31 @@ func newDeleteOrganizationHandler() *deleteOrganizationHandler {
func (h *deleteOrganizationHandler) Handle(params admin.DeleteOrganizationParams, principal *rest_model_zrok.Principal) middleware.Responder {
if !principal.Admin {
logrus.Errorf("invalid admin principal")
dl.Errorf("invalid admin principal")
return admin.NewDeleteOrganizationUnauthorized()
}
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return admin.NewDeleteOrganizationInternalServerError()
}
defer func() { _ = trx.Rollback() }()
org, err := str.FindOrganizationByToken(params.Body.OrganizationToken, trx)
if err != nil {
logrus.Errorf("error finding organization by token: %v", err)
dl.Errorf("error finding organization by token: %v", err)
return admin.NewDeleteOrganizationNotFound()
}
err = str.DeleteOrganization(org.Id, trx)
if err != nil {
logrus.Errorf("error deleting organization: %v", err)
dl.Errorf("error deleting organization: %v", err)
return admin.NewDeleteOrganizationInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return admin.NewDeleteOrganizationInternalServerError()
}
+10 -10
View File
@@ -2,9 +2,9 @@ package controller
import (
"github.com/go-openapi/runtime/middleware"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/share"
"github.com/sirupsen/logrus"
)
type deleteShareNameHandler struct{}
@@ -16,7 +16,7 @@ func newDeleteShareNameHandler() *deleteShareNameHandler {
func (h *deleteShareNameHandler) Handle(params share.DeleteShareNameParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
dl.Errorf("error starting transaction: %v", err)
return share.NewDeleteShareNameInternalServerError()
}
defer func() { _ = trx.Rollback() }()
@@ -24,7 +24,7 @@ func (h *deleteShareNameHandler) Handle(params share.DeleteShareNameParams, prin
// find namespace
ns, err := str.FindNamespaceWithToken(params.Body.NamespaceToken, trx)
if err != nil {
logrus.Errorf("error finding namespace with token '%v': %v", params.Body.NamespaceToken, err)
dl.Errorf("error finding namespace with token '%v': %v", params.Body.NamespaceToken, err)
return share.NewDeleteShareNameNotFound()
}
@@ -32,11 +32,11 @@ func (h *deleteShareNameHandler) Handle(params share.DeleteShareNameParams, prin
// check namespace grant
granted, err := str.CheckNamespaceGrant(ns.Id, int(principal.ID), trx)
if err != nil {
logrus.Errorf("error checking namespace grant for account '%v' and namespace '%v': %v", principal.Email, ns.Token, err)
dl.Errorf("error checking namespace grant for account '%v' and namespace '%v': %v", principal.Email, ns.Token, err)
return share.NewDeleteShareNameInternalServerError()
}
if !granted {
logrus.Errorf("account '%v' is not granted access to namespace '%v'", principal.Email, ns.Token)
dl.Errorf("account '%v' is not granted access to namespace '%v'", principal.Email, ns.Token)
return share.NewDeleteShareNameUnauthorized()
}
}
@@ -44,27 +44,27 @@ func (h *deleteShareNameHandler) Handle(params share.DeleteShareNameParams, prin
// find allocated name
an, err := str.FindNameByNamespaceAndName(ns.Id, params.Body.Name, trx)
if err != nil {
logrus.Errorf("error finding allocated name '%v' in namespace '%v': %v", params.Body.Name, ns.Token, err)
dl.Errorf("error finding allocated name '%v' in namespace '%v': %v", params.Body.Name, ns.Token, err)
return share.NewDeleteShareNameNotFound()
}
// verify ownership
if an.AccountId != int(principal.ID) {
logrus.Errorf("account '%v' does not own name '%v' in namespace '%v'", principal.Email, params.Body.Name, ns.Token)
dl.Errorf("account '%v' does not own name '%v' in namespace '%v'", principal.Email, params.Body.Name, ns.Token)
return share.NewDeleteShareNameUnauthorized()
}
// delete allocated name
if err := str.DeleteName(an.Id, trx); err != nil {
logrus.Errorf("error deleting allocated name '%v' in namespace '%v' for account '%v': %v", params.Body.Name, ns.Token, principal.Email, err)
dl.Errorf("error deleting allocated name '%v' in namespace '%v' for account '%v': %v", params.Body.Name, ns.Token, principal.Email, err)
return share.NewDeleteShareNameInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction: %v", err)
dl.Errorf("error committing transaction: %v", err)
return share.NewDeleteShareNameInternalServerError()
}
logrus.Infof("deleted allocated name '%v' in namespace '%v' for account '%v'", params.Body.Name, ns.Token, principal.Email)
dl.Infof("deleted allocated name '%v' in namespace '%v' for account '%v'", params.Body.Name, ns.Token, principal.Email)
return share.NewDeleteShareNameOK()
}
+14 -14
View File
@@ -5,12 +5,12 @@ import (
"github.com/go-openapi/runtime/middleware"
"github.com/jmoiron/sqlx"
"github.com/michaelquigley/df/dl"
"github.com/openziti/zrok/controller/automation"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/environment"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type disableHandler struct{}
@@ -22,30 +22,30 @@ func newDisableHandler() *disableHandler {
func (h *disableHandler) Handle(params environment.DisableParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
defer func() { _ = trx.Rollback() }()
env, err := str.FindEnvironmentForAccount(params.Body.Identity, int(principal.ID), trx)
if err != nil {
logrus.Errorf("identity check failed for user '%v': %v", principal.Email, err)
dl.Errorf("identity check failed for user '%v': %v", principal.Email, err)
return environment.NewDisableUnauthorized()
}
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
logrus.Errorf("error getting automation client for user '%v': %v", principal.Email, err)
dl.Errorf("error getting automation client for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
if err := disableEnvironment(env, trx, ziti); err != nil {
logrus.Errorf("error disabling environment for user '%v': %v", principal.Email, err)
dl.Errorf("error disabling environment for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing for user '%v': %v", principal.Email, err)
dl.Errorf("error committing for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
@@ -87,38 +87,38 @@ func removeSharesForEnvironment(env *store.Environment, trx *sqlx.Tx, ziti *auto
}
for _, shr := range shrs {
shrToken := shr.Token
logrus.Infof("garbage collecting share '%v' for environment '%v'", shrToken, env.ZId)
dl.Infof("garbage collecting share '%v' for environment '%v'", shrToken, env.ZId)
// delete service edge router policies for share
serpFilter := fmt.Sprintf("tags.zrokShareToken=\"%v\"", shrToken)
if err := ziti.ServiceEdgeRouterPolicies.DeleteWithFilter(serpFilter); err != nil {
logrus.Error(err)
dl.Error(err)
}
// delete dial service policies for share
dialFilter := fmt.Sprintf("tags.zrokShareToken=\"%v\" and type=1", shrToken)
if err := ziti.ServicePolicies.DeleteWithFilter(dialFilter); err != nil {
logrus.Error(err)
dl.Error(err)
}
// delete bind service policies for share
bindFilter := fmt.Sprintf("tags.zrokShareToken=\"%v\" and type=2", shrToken)
if err := ziti.ServicePolicies.DeleteWithFilter(bindFilter); err != nil {
logrus.Error(err)
dl.Error(err)
}
// delete configs for share
configFilter := fmt.Sprintf("tags.zrokShareToken=\"%v\"", shrToken)
if err := ziti.Configs.DeleteWithFilter(configFilter); err != nil {
logrus.Error(err)
dl.Error(err)
}
// delete service
if err := ziti.Services.Delete(shr.ZId); err != nil {
logrus.Error(err)
dl.Error(err)
}
logrus.Infof("removed share '%v' for environment '%v'", shr.Token, env.ZId)
dl.Infof("removed share '%v' for environment '%v'", shr.Token, env.ZId)
}
return nil
}
@@ -131,7 +131,7 @@ func removeFrontendsForEnvironment(env *store.Environment, trx *sqlx.Tx, ziti *a
for _, fe := range fes {
filter := fmt.Sprintf("tags.zrokFrontendToken=\"%v\" and type=1", fe.Token)
if err := ziti.ServicePolicies.DeleteWithFilter(filter); err != nil {
logrus.Errorf("error removing frontend access for '%v': %v", fe.Token, err)
dl.Errorf("error removing frontend access for '%v': %v", fe.Token, err)
}
}
return nil
@@ -6,9 +6,9 @@ import (
"time"
"github.com/michaelquigley/df/dd"
"github.com/michaelquigley/df/dl"
"github.com/pkg/errors"
amqp "github.com/rabbitmq/amqp091-go"
"github.com/sirupsen/logrus"
)
type AmqpPublisherConfig struct {
@@ -63,7 +63,7 @@ func (p *AmqpPublisher) connect() error {
p.ch = ch
p.connected = true
logrus.Infof("amqp publisher connected to '%s', exchange: '%s'", p.cfg.Url, p.cfg.ExchangeName)
dl.Infof("amqp publisher connected to '%s', exchange: '%s'", p.cfg.Url, p.cfg.ExchangeName)
return nil
}
@@ -106,7 +106,7 @@ func (p *AmqpPublisher) Publish(ctx context.Context, frontendToken string, m Map
return errors.Wrapf(err, "failed to publish mapping update for frontend '%s'", frontendToken)
}
logrus.Debugf("published mapping update for frontend '%s': %+v", frontendToken, m)
dl.Debugf("published mapping update for frontend '%s': %+v", frontendToken, m)
return nil
}
@@ -4,9 +4,9 @@ import (
"context"
"github.com/jmoiron/sqlx"
"github.com/michaelquigley/df/dl"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/zrok/controller/store"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
@@ -46,11 +46,11 @@ func NewController(cfg *Config, str *store.Store) (*Controller, error) {
}
go func() {
if err := srv.Serve(l); err != nil {
logrus.Errorf("error serving dynamic proxy controller: %v", err)
dl.Errorf("error serving dynamic proxy controller: %v", err)
return
}
}()
logrus.Infof("started dynamic proxy controller server")
dl.Infof("started dynamic proxy controller server")
return ctrl, nil
}
@@ -124,6 +124,6 @@ func (c *Controller) sendMappingUpdate(frontendToken string, m Mapping) error {
if err := c.publisher.Publish(context.Background(), frontendToken, m); err != nil {
return err
}
logrus.Infof("sent mapping update '%+v' -> '%s'", m, frontendToken)
dl.Infof("sent mapping update '%+v' -> '%s'", m, frontendToken)
return nil
}
+11 -11
View File
@@ -7,13 +7,13 @@ import (
"github.com/go-openapi/runtime/middleware"
"github.com/jmoiron/sqlx"
"github.com/michaelquigley/df/dl"
rest_model_edge "github.com/openziti/edge-api/rest_model"
"github.com/openziti/zrok/controller/automation"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/environment"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type enableHandler struct{}
@@ -25,25 +25,25 @@ func newEnableHandler() *enableHandler {
func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_model_zrok.Principal) middleware.Responder {
trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
dl.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
defer func() { _ = trx.Rollback() }()
if err := h.checkLimits(principal, trx); err != nil {
logrus.Errorf("limits error for user '%v': %v", principal.Email, err)
dl.Errorf("limits error for user '%v': %v", principal.Email, err)
return environment.NewEnableUnauthorized()
}
uniqueToken, err := createShareToken()
if err != nil {
logrus.Errorf("error creating unique identity token for user '%v': %v", principal.Email, err)
dl.Errorf("error creating unique identity token for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
ziti, err := automation.NewZitiAutomation(cfg.Ziti)
if err != nil {
logrus.Errorf("error getting automation client for user '%v': %v", principal.Email, err)
dl.Errorf("error getting automation client for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
@@ -60,14 +60,14 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_
}
envZId, err := ziti.Identities.Create(identityOpts)
if err != nil {
logrus.Errorf("error creating environment identity for user '%v': %v", principal.Email, err)
dl.Errorf("error creating environment identity for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
// enroll identity
zitiCfg, err := ziti.Identities.Enroll(envZId)
if err != nil {
logrus.Errorf("error enrolling environment identity for user '%v': %v", principal.Email, err)
dl.Errorf("error enrolling environment identity for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
@@ -82,7 +82,7 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_
Semantic: rest_model_edge.SemanticAllOf,
}
if _, err := ziti.EdgeRouterPolicies.Create(erpOpts); err != nil {
logrus.Errorf("error creating edge router policy for user '%v': %v", principal.Email, err)
dl.Errorf("error creating edge router policy for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
@@ -93,16 +93,16 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_
ZId: envZId,
}, trx)
if err != nil {
logrus.Errorf("error storing created identity for user '%v': %v", principal.Email, err)
dl.Errorf("error storing created identity for user '%v': %v", principal.Email, err)
_ = trx.Rollback()
return environment.NewEnableInternalServerError()
}
if err := trx.Commit(); err != nil {
logrus.Errorf("error committing for user '%v': %v", principal.Email, err)
dl.Errorf("error committing for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
logrus.Infof("created environment for '%v', with ziti identity '%v', and database id '%v'", principal.Email, envZId, envId)
dl.Infof("created environment for '%v', with ziti identity '%v', and database id '%v'", principal.Email, envZId, envId)
resp := environment.NewEnableCreated().WithPayload(&environment.EnableCreatedBody{Identity: envZId})

Some files were not shown because too many files have changed in this diff Show More