feat: use new logger.CapturedE() api
This commit is contained in:
parent
b0898eefc3
commit
ce9b3003fe
|
@ -8,7 +8,6 @@ import (
|
|||
"forge.cadoles.com/Cadoles/emissary/internal/auth/agent"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/jwk"
|
||||
"forge.cadoles.com/Cadoles/emissary/pkg/client"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/api"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
|
@ -45,16 +44,14 @@ func (a *Agent) Run(ctx context.Context) error {
|
|||
|
||||
if err := a.registerAgent(ctx, client, state); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not register agent", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not register agent", logger.CapturedE(err))
|
||||
}
|
||||
|
||||
logger.Debug(ctx, "state before reconciliation", logger.F("state", state))
|
||||
|
||||
if err := a.Reconcile(ctx, state); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not reconcile node with state", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not reconcile node with state", logger.CapturedE(err))
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -85,8 +82,7 @@ func (a *Agent) Reconcile(ctx context.Context, state *State) error {
|
|||
|
||||
if err := ctrl.Reconcile(ctrlCtx, state); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not reconcile", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not reconcile", logger.CapturedE(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,9 +116,8 @@ func (a *Agent) collectMetadata(ctx context.Context) (map[string]any, error) {
|
|||
err = errors.WithStack(err)
|
||||
logger.Error(
|
||||
ctx, "could not collect metadata",
|
||||
logger.E(err), logger.F("name", name),
|
||||
logger.CapturedE(err), logger.F("name", name),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"forge.cadoles.com/arcad/edge/pkg/storage/driver"
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage/share"
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/lestrrat-go/jwx/v2/jwa"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -201,9 +200,8 @@ func createResolveAppURL(specs *spec.Spec) (ResolveAppURLFunc, error) {
|
|||
err = errors.WithStack(err)
|
||||
logger.Warn(
|
||||
ctx, "could not find interface",
|
||||
logger.E(err), logger.F("iface", ifaceName),
|
||||
logger.CapturedE(err), logger.F("iface", ifaceName),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
@ -213,10 +211,9 @@ func createResolveAppURL(specs *spec.Spec) (ResolveAppURLFunc, error) {
|
|||
err = errors.WithStack(err)
|
||||
logger.Error(
|
||||
ctx, "could not list interface addresses",
|
||||
logger.E(err),
|
||||
logger.CapturedE(err),
|
||||
logger.F("iface", iface.Name),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
@ -227,10 +224,9 @@ func createResolveAppURL(specs *spec.Spec) (ResolveAppURLFunc, error) {
|
|||
err = errors.WithStack(err)
|
||||
logger.Error(
|
||||
ctx, "could not parse interface ip",
|
||||
logger.E(err),
|
||||
logger.CapturedE(err),
|
||||
logger.F("iface", iface.Name),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"forge.cadoles.com/arcad/edge/pkg/app"
|
||||
"forge.cadoles.com/arcad/edge/pkg/bundle"
|
||||
appModule "forge.cadoles.com/arcad/edge/pkg/module/app"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
@ -65,8 +64,7 @@ func (r *AppRepository) List(ctx context.Context) ([]*app.Manifest, error) {
|
|||
bundle, err := bundle.FromPath(path)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(bundleCtx, "could not load bundle", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(bundleCtx, "could not load bundle", logger.CapturedE(err))
|
||||
|
||||
continue
|
||||
}
|
||||
|
@ -74,8 +72,7 @@ func (r *AppRepository) List(ctx context.Context) ([]*app.Manifest, error) {
|
|||
manifest, err := app.LoadManifest(bundle)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(bundleCtx, "could not load manifest", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(bundleCtx, "could not load manifest", logger.CapturedE(err))
|
||||
|
||||
continue
|
||||
}
|
||||
|
@ -103,8 +100,7 @@ func (r *AppRepository) findManifest(ctx context.Context, id app.ID) (*app.Manif
|
|||
bundle, err := bundle.FromPath(path)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(bundleCtx, "could not load bundle", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(bundleCtx, "could not load bundle", logger.CapturedE(err))
|
||||
|
||||
continue
|
||||
}
|
||||
|
@ -112,8 +108,7 @@ func (r *AppRepository) findManifest(ctx context.Context, id app.ID) (*app.Manif
|
|||
manifest, err := app.LoadManifest(bundle)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(bundleCtx, "could not load manifest", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(bundleCtx, "could not load manifest", logger.CapturedE(err))
|
||||
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"forge.cadoles.com/Cadoles/emissary/internal/agent/controller/app/spec"
|
||||
"forge.cadoles.com/arcad/edge/pkg/app"
|
||||
"forge.cadoles.com/arcad/edge/pkg/bundle"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/mitchellh/hashstructure/v2"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
|
@ -71,9 +70,8 @@ func (c *Controller) stopAllApps(ctx context.Context, spec *spec.Spec) {
|
|||
logger.Error(
|
||||
ctx, "error while stopping app",
|
||||
logger.F("appID", appID),
|
||||
logger.E(err),
|
||||
logger.CapturedE(err),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
delete(c.servers, appID)
|
||||
}
|
||||
|
@ -94,9 +92,8 @@ func (c *Controller) updateApps(ctx context.Context, specs *spec.Spec) {
|
|||
logger.Error(
|
||||
ctx, "error while stopping app",
|
||||
logger.F("appKey", appKey),
|
||||
logger.E(err),
|
||||
logger.CapturedE(err),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
delete(c.servers, appKey)
|
||||
}
|
||||
|
@ -106,9 +103,8 @@ func (c *Controller) updateApps(ctx context.Context, specs *spec.Spec) {
|
|||
err = errors.WithStack(err)
|
||||
logger.Error(
|
||||
ctx, "could not update app repository",
|
||||
logger.E(err),
|
||||
logger.CapturedE(err),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -119,8 +115,7 @@ func (c *Controller) updateApps(ctx context.Context, specs *spec.Spec) {
|
|||
|
||||
if err := c.updateApp(ctx, specs, appKey); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(appCtx, "could not update app", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(appCtx, "could not update app", logger.CapturedE(err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
"gitlab.com/wpetit/goweb/logger"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/bundle"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -74,8 +73,7 @@ func (s *Server) Start(ctx context.Context, addr string) (err error) {
|
|||
if recovered := recover(); recovered != nil {
|
||||
if err, ok := recovered.(error); ok {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, err.Error(), logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, err.Error(), logger.CapturedE(err))
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"forge.cadoles.com/Cadoles/emissary/internal/agent"
|
||||
mdns "forge.cadoles.com/Cadoles/emissary/internal/agent/controller/mdns/spec"
|
||||
"github.com/brutella/dnssd"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/mitchellh/hashstructure/v2"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
|
@ -119,8 +118,7 @@ func (c *Controller) updateResponder(ctx context.Context, spec *mdns.Spec) error
|
|||
service, err := dnssd.NewService(config)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not create mdns service", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not create mdns service", logger.CapturedE(err))
|
||||
|
||||
continue
|
||||
}
|
||||
|
@ -136,8 +134,7 @@ func (c *Controller) updateResponder(ctx context.Context, spec *mdns.Spec) error
|
|||
for _, service := range services {
|
||||
if _, err := responder.Add(service); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not add mdns service", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not add mdns service", logger.CapturedE(err))
|
||||
|
||||
continue
|
||||
}
|
||||
|
@ -154,8 +151,7 @@ func (c *Controller) updateResponder(ctx context.Context, spec *mdns.Spec) error
|
|||
|
||||
if err := responder.Respond(ctx); err != nil && !errors.Is(err, context.Canceled) {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not respond to mdns queries", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not respond to mdns queries", logger.CapturedE(err))
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent/controller/openwrt/spec/sysupgrade"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
@ -68,10 +67,9 @@ func (c *SysUpgradeController) Reconcile(ctx context.Context, state *agent.State
|
|||
err = errors.WithStack(err)
|
||||
logger.Error(
|
||||
ctx, "could not remove download direction",
|
||||
logger.E(err),
|
||||
logger.CapturedE(err),
|
||||
logger.F("downloadDir", downloadDir),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"forge.cadoles.com/Cadoles/emissary/internal/agent"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/openwrt/uci"
|
||||
ucispec "forge.cadoles.com/Cadoles/emissary/internal/spec/uci"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
@ -48,8 +47,7 @@ func (c *UCIController) Reconcile(ctx context.Context, state *agent.State) error
|
|||
|
||||
if err := c.updateConfiguration(ctx, uciSpec); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not update configuration", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not update configuration", logger.CapturedE(err))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/spec"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
@ -147,8 +146,7 @@ func (c *Controller) writeState(ctx context.Context, state *agent.State) error {
|
|||
}
|
||||
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not remove temporary file", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not remove temporary file", logger.CapturedE(err))
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -159,8 +157,7 @@ func (c *Controller) writeState(ctx context.Context, state *agent.State) error {
|
|||
}
|
||||
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not close temporary file", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not close temporary file", logger.CapturedE(err))
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"forge.cadoles.com/Cadoles/emissary/internal/agent"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/proxy"
|
||||
spec "forge.cadoles.com/Cadoles/emissary/internal/spec/proxy"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/mitchellh/hashstructure/v2"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
|
@ -63,9 +62,8 @@ func (c *Controller) stopAllProxies(ctx context.Context) {
|
|||
logger.Error(
|
||||
ctx, "error while stopping proxy",
|
||||
logger.F("proxyID", proxyID),
|
||||
logger.E(err),
|
||||
logger.CapturedE(err),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
delete(c.proxies, proxyID)
|
||||
}
|
||||
|
@ -86,9 +84,8 @@ func (c *Controller) updateProxies(ctx context.Context, spec *spec.Spec) {
|
|||
logger.Error(
|
||||
ctx, "error while stopping proxy",
|
||||
logger.F("proxyID", proxyID),
|
||||
logger.E(err),
|
||||
logger.CapturedE(err),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
delete(c.proxies, proxyID)
|
||||
}
|
||||
|
@ -100,8 +97,7 @@ func (c *Controller) updateProxies(ctx context.Context, spec *spec.Spec) {
|
|||
|
||||
if err := c.updateProxy(ctx, proxyID, proxySpec); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(proxyCtx, "could not update proxy", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(proxyCtx, "could not update proxy", logger.CapturedE(err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"sync"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/proxy"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
@ -40,15 +39,13 @@ func (p *ReverseProxy) Start(ctx context.Context, addr string, funcs ...proxy.Op
|
|||
defer func() {
|
||||
if err := p.Stop(); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "error while stopping gateway", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "error while stopping gateway", logger.CapturedE(err))
|
||||
}
|
||||
}()
|
||||
|
||||
if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "error while listening", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "error while listening", logger.CapturedE(err))
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"forge.cadoles.com/Cadoles/emissary/internal/agent"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
"forge.cadoles.com/Cadoles/emissary/pkg/client"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
@ -49,8 +48,7 @@ func (c *Controller) reconcileAgent(ctx context.Context, client *client.Client,
|
|||
specs, err := client.GetAgentSpecs(ctx, agent.ID)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not retrieve agent specs", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not retrieve agent specs", logger.CapturedE(err))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -64,6 +64,10 @@ func Main(buildDate, projectVersion, gitRef, defaultConfigPath string, commands
|
|||
if err != nil {
|
||||
logger.Error(ctx.Context, "could not initialize sentry", logger.E(errors.WithStack(err)))
|
||||
}
|
||||
|
||||
logger.SetCaptureFunc(func(err error) {
|
||||
sentry.CaptureException(err)
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/command/common"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
|
@ -34,8 +33,7 @@ func PingCommand() *cli.Command {
|
|||
defer func() {
|
||||
if err := db.Close(); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx.Context, "error while closing database connection", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx.Context, "error while closing database connection", logger.CapturedE(err))
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/lestrrat-go/jwx/v2/jwk"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
|
@ -74,8 +73,7 @@ func (r *AgentRepository) GetSpecs(ctx context.Context, agentID datastore.AgentI
|
|||
defer func() {
|
||||
if err := rows.Close(); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not close rows", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not close rows", logger.CapturedE(err))
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -230,8 +228,7 @@ func (r *AgentRepository) Query(ctx context.Context, opts ...datastore.AgentQuer
|
|||
defer func() {
|
||||
if err := rows.Close(); err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not close rows", logger.E(errors.WithStack(err)))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not close rows", logger.CapturedE(err))
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -550,8 +547,7 @@ func (r *AgentRepository) withTx(ctx context.Context, fn func(*sql.Tx) error) er
|
|||
}
|
||||
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not rollback transaction", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not rollback transaction", logger.CapturedE(err))
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"forge.cadoles.com/Cadoles/emissary/internal/agent/metadata"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/jwk"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/api"
|
||||
|
@ -41,8 +40,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||
keySet, err := jwk.Parse(registerAgentReq.KeySet)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not parse key set", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not parse key set", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
return
|
||||
|
@ -55,8 +53,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||
validSignature, err := jwk.Verify(keySet, registerAgentReq.Signature, registerAgentReq.Thumbprint, registerAgentReq.Metadata)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not validate signature", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not validate signature", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
return
|
||||
|
@ -80,8 +77,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
if !errors.Is(err, datastore.ErrAlreadyExist) {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not create agent", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not create agent", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
return
|
||||
|
@ -94,8 +90,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not retrieve agents", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not retrieve agents", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
return
|
||||
|
@ -103,9 +98,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if len(agents) == 0 {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not retrieve matching agent", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
|
||||
logger.Error(ctx, "could not retrieve matching agent", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeNotFound, nil)
|
||||
|
||||
return
|
||||
|
@ -118,9 +111,8 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||
err = errors.WithStack(err)
|
||||
logger.Error(
|
||||
ctx, "could not retrieve agent",
|
||||
logger.E(err), logger.F("agentID", agentID),
|
||||
logger.CapturedE(err), logger.F("agentID", agentID),
|
||||
)
|
||||
sentry.CaptureException(err)
|
||||
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
|
@ -130,8 +122,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||
validSignature, err = jwk.Verify(agent.KeySet.Set, registerAgentReq.Signature, registerAgentReq.Thumbprint, registerAgentReq.Metadata)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not validate signature using previous keyset", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not validate signature using previous keyset", logger.CapturedE(err))
|
||||
|
||||
api.ErrorResponse(w, http.StatusConflict, ErrCodeConflict, nil)
|
||||
|
||||
|
@ -146,8 +137,7 @@ func (s *Server) registerAgent(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not update agent", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not update agent", logger.CapturedE(err))
|
||||
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
|
@ -197,9 +187,7 @@ func (s *Server) updateAgent(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not update agent", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
|
||||
logger.Error(ctx, "could not update agent", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
return
|
||||
|
@ -281,9 +269,7 @@ func (s *Server) queryAgents(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not list agents", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
|
||||
logger.Error(ctx, "could not list agents", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
return
|
||||
|
@ -318,9 +304,7 @@ func (s *Server) deleteAgent(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not delete agent", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
|
||||
logger.Error(ctx, "could not delete agent", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
return
|
||||
|
@ -353,9 +337,7 @@ func (s *Server) getAgent(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not get agent", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
|
||||
logger.Error(ctx, "could not get agent", logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
return
|
||||
|
@ -373,7 +355,7 @@ func getAgentID(w http.ResponseWriter, r *http.Request) (datastore.AgentID, bool
|
|||
|
||||
agentID, err := strconv.ParseInt(rawAgentID, 10, 64)
|
||||
if err != nil {
|
||||
logger.Error(r.Context(), "could not parse agent id", logger.E(errors.WithStack(err)))
|
||||
logger.Error(r.Context(), "could not parse agent id", logger.CapturedE(errors.WithStack(err)))
|
||||
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil)
|
||||
|
||||
return 0, false
|
||||
|
@ -388,9 +370,7 @@ func getIntQueryParam(w http.ResponseWriter, r *http.Request, param string, defa
|
|||
value, err := strconv.ParseInt(rawValue, 10, 64)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(r.Context(), "could not parse int param", logger.F("param", param), logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
|
||||
logger.Error(r.Context(), "could not parse int param", logger.F("param", param), logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil)
|
||||
|
||||
return 0, false
|
||||
|
@ -424,9 +404,7 @@ func getIntSliceValues(w http.ResponseWriter, r *http.Request, param string, def
|
|||
value, err := strconv.ParseInt(rv, 10, 64)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(r.Context(), "could not parse int slice param", logger.F("param", param), logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
|
||||
logger.Error(r.Context(), "could not parse int slice param", logger.F("param", param), logger.CapturedE(err))
|
||||
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil)
|
||||
|
||||
return nil, false
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"forge.cadoles.com/Cadoles/emissary/internal/auth"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/auth/agent"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/auth/thirdparty"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/api"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
|
@ -126,8 +125,7 @@ func assertRequestUser(w http.ResponseWriter, r *http.Request) (auth.User, bool)
|
|||
user, err := auth.CtxUser(ctx)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not retrieve user", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not retrieve user", logger.CapturedE(err))
|
||||
|
||||
forbidden(w, r)
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/spec"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/api"
|
||||
|
@ -46,8 +45,7 @@ func (s *Server) updateSpec(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not validate spec", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not validate spec", logger.CapturedE(err))
|
||||
|
||||
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeInvalidRequest, data)
|
||||
|
||||
|
@ -75,8 +73,7 @@ func (s *Server) updateSpec(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not update spec", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not update spec", logger.CapturedE(err))
|
||||
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
|
@ -107,8 +104,7 @@ func (s *Server) getAgentSpecs(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not list specs", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not list specs", logger.CapturedE(err))
|
||||
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
|
@ -152,8 +148,7 @@ func (s *Server) deleteSpec(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(ctx, "could not delete spec", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(ctx, "could not delete spec", logger.CapturedE(err))
|
||||
|
||||
api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil)
|
||||
|
||||
|
@ -173,8 +168,7 @@ func getSpecID(w http.ResponseWriter, r *http.Request) (datastore.SpecID, bool)
|
|||
specID, err := strconv.ParseInt(rawSpecID, 10, 64)
|
||||
if err != nil {
|
||||
err = errors.WithStack(err)
|
||||
logger.Error(r.Context(), "could not parse spec id", logger.E(err))
|
||||
sentry.CaptureException(err)
|
||||
logger.Error(r.Context(), "could not parse spec id", logger.CapturedE(err))
|
||||
|
||||
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeMalformedRequest, nil)
|
||||
|
||||
|
|
Loading…
Reference in New Issue