operational improvements in log messages (#186)

This commit is contained in:
Michael Quigley 2023-01-30 11:38:55 -05:00
parent 18bd8a798e
commit d9258a2915
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
9 changed files with 57 additions and 60 deletions

View File

@ -18,7 +18,7 @@ func newAccessHandler() *accessHandler {
func (h *accessHandler) Handle(params share.AccessParams, principal *rest_model_zrok.Principal) middleware.Responder {
tx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
logrus.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
return share.NewAccessInternalServerError()
}
defer func() { _ = tx.Rollback() }()
@ -62,7 +62,7 @@ func (h *accessHandler) Handle(params share.AccessParams, principal *rest_model_
}
if _, err := str.CreateFrontend(envId, &store.Frontend{Token: feToken, ZId: envZId}, tx); err != nil {
logrus.Errorf("error creating frontend record: %v", err)
logrus.Errorf("error creating frontend record for user '%v': %v", principal.Email, err)
return share.NewAccessInternalServerError()
}
@ -77,7 +77,7 @@ func (h *accessHandler) Handle(params share.AccessParams, principal *rest_model_
"zrokShareToken": shrToken,
}
if err := zrokEdgeSdk.CreateServicePolicyDial(envZId+"-"+sshr.ZId+"-dial", sshr.ZId, []string{envZId}, addlTags, edge); err != nil {
logrus.Errorf("unable to create dial policy: %v", err)
logrus.Errorf("unable to create dial policy for user '%v': %v", principal.Email, err)
return share.NewAccessInternalServerError()
}

View File

@ -22,47 +22,47 @@ func newDisableHandler() *disableHandler {
func (h *disableHandler) Handle(params environment.DisableParams, principal *rest_model_zrok.Principal) middleware.Responder {
tx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
logrus.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
defer func() { _ = tx.Rollback() }()
envId, err := h.checkZitiIdentity(params.Body.Identity, principal, tx)
if err != nil {
logrus.Errorf("identity check failed: %v", err)
logrus.Errorf("identity check failed for user '%v': %v", principal.Email, err)
return environment.NewDisableUnauthorized()
}
env, err := str.GetEnvironment(envId, tx)
if err != nil {
logrus.Errorf("error getting environment: %v", err)
logrus.Errorf("error getting environment for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
edge, err := edgeClient()
if err != nil {
logrus.Errorf("error getting edge client: %v", err)
logrus.Errorf("error getting edge client for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
if err := h.removeSharesForEnvironment(envId, tx, edge); err != nil {
logrus.Errorf("error removing shares for environment: %v", err)
logrus.Errorf("error removing shares for environment for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
if err := h.removeFrontendsForEnvironment(envId, tx, edge); err != nil {
logrus.Errorf("error removing frontends for environment: %v", err)
logrus.Errorf("error removing frontends for environment for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
if err := h.removeEnvironment(envId, tx); err != nil {
logrus.Errorf("error removing environment: %v", err)
logrus.Errorf("error removing environment for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
if err := zrokEdgeSdk.DeleteEdgeRouterPolicy(env.ZId, edge); err != nil {
logrus.Errorf("error deleting edge router policy: %v", err)
logrus.Errorf("error deleting edge router policy for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
if err := zrokEdgeSdk.DeleteIdentity(params.Body.Identity, edge); err != nil {
logrus.Errorf("error deleting identity: %v", err)
logrus.Errorf("error deleting identity for user '%v': %v", principal.Email, err)
return environment.NewDisableInternalServerError()
}
if err := tx.Commit(); err != nil {
logrus.Errorf("error committing: %v", err)
logrus.Errorf("error committing for user '%v': %v", principal.Email, err)
}
return environment.NewDisableOK()
}

View File

@ -25,43 +25,43 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_
// start transaction early; if it fails, don't bother creating ziti resources
tx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
logrus.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
defer func() { _ = tx.Rollback() }()
if err := h.checkLimits(principal, tx); err != nil {
logrus.Errorf("limits error: %v", err)
logrus.Errorf("limits error for user '%v': %v", principal.Email, err)
return environment.NewEnableUnauthorized()
}
client, err := edgeClient()
if err != nil {
logrus.Errorf("error getting edge client: %v", err)
logrus.Errorf("error getting edge client for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
uniqueToken, err := createShareToken()
if err != nil {
logrus.Errorf("error creating unique identity token: %v", err)
logrus.Errorf("error creating unique identity token for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
ident, err := zrokEdgeSdk.CreateEnvironmentIdentity(uniqueToken, principal.Email, params.Body.Description, client)
if err != nil {
logrus.Error(err)
logrus.Errorf("error creating environment identity for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
envZId := ident.Payload.Data.ID
cfg, err := zrokEdgeSdk.EnrollIdentity(envZId, client)
if err != nil {
logrus.Error(err)
logrus.Errorf("error enrolling environment identity for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
if err := zrokEdgeSdk.CreateEdgeRouterPolicy(envZId, envZId, client); err != nil {
logrus.Error(err)
logrus.Errorf("error creating edge router policy for user '%v': %v", principal.Email, err)
return environment.NewEnableInternalServerError()
}
@ -72,13 +72,13 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_
ZId: envZId,
}, tx)
if err != nil {
logrus.Errorf("error storing created identity: %v", err)
logrus.Errorf("error storing created identity for user '%v': %v", principal.Email, err)
_ = tx.Rollback()
return environment.NewEnableInternalServerError()
}
if err := tx.Commit(); err != nil {
logrus.Errorf("error committing: %v", err)
logrus.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, ident.Payload.Data.ID, envId)

View File

@ -16,7 +16,7 @@ func newEnvironmentDetailHandler() *environmentDetailHandler {
func (h *environmentDetailHandler) Handle(params metadata.GetEnvironmentDetailParams, principal *rest_model_zrok.Principal) middleware.Responder {
tx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
logrus.Errorf("error starting transaction for user '%v': %v", principal.Email, err)
return metadata.NewGetEnvironmentDetailInternalServerError()
}
defer func() { _ = tx.Rollback() }()
@ -37,14 +37,14 @@ func (h *environmentDetailHandler) Handle(params metadata.GetEnvironmentDetailPa
}
shrs, err := str.FindSharesForEnvironment(senv.Id, tx)
if err != nil {
logrus.Errorf("error finding shares for environment '%v': %v", senv.ZId, err)
logrus.Errorf("error finding shares for environment '%v' for user '%v': %v", senv.ZId, principal.Email, err)
return metadata.NewGetEnvironmentDetailInternalServerError()
}
var sparkData map[string][]int64
if cfg.Influx != nil {
sparkData, err = sparkDataForShares(shrs)
if err != nil {
logrus.Errorf("error querying spark data for shares: %v", err)
logrus.Errorf("error querying spark data for shares for user '%v': %v", principal.Email, err)
}
}
for _, shr := range shrs {

View File

@ -13,7 +13,7 @@ type registerHandler struct{}
func newRegisterHandler() *registerHandler {
return &registerHandler{}
}
func (self *registerHandler) Handle(params account.RegisterParams) middleware.Responder {
func (h *registerHandler) Handle(params account.RegisterParams) middleware.Responder {
if params.Body == nil || params.Body.Token == "" || params.Body.Password == "" {
logrus.Error("missing token or password")
return account.NewRegisterNotFound()
@ -22,25 +22,25 @@ func (self *registerHandler) Handle(params account.RegisterParams) middleware.Re
tx, err := str.Begin()
if err != nil {
logrus.Error(err)
logrus.Errorf("error starting transaction for token '%v': %v", params.Body.Token, err)
return account.NewRegisterInternalServerError()
}
defer func() { _ = tx.Rollback() }()
ar, err := str.FindAccountRequestWithToken(params.Body.Token, tx)
if err != nil {
logrus.Error(err)
logrus.Errorf("error finding account request with token '%v': %v", params.Body.Token, err)
return account.NewRegisterNotFound()
}
token, err := createToken()
if err != nil {
logrus.Error(err)
logrus.Errorf("error creating token for request '%v' (%v): %v", params.Body.Token, ar.Email, err)
return account.NewRegisterInternalServerError()
}
hpwd, err := hashPassword(params.Body.Password)
if err != nil {
logrus.Error(err)
logrus.Errorf("error hashing password for request '%v' (%v): %v", params.Body.Token, ar.Email, err)
return account.NewRegisterInternalServerError()
}
a := &store.Account{
@ -50,17 +50,17 @@ func (self *registerHandler) Handle(params account.RegisterParams) middleware.Re
Token: token,
}
if _, err := str.CreateAccount(a, tx); err != nil {
logrus.Error(err)
logrus.Errorf("error creating account for request '%v' (%v): %v", params.Body.Token, ar.Email, err)
return account.NewRegisterInternalServerError()
}
if err := str.DeleteAccountRequest(ar.Id, tx); err != nil {
logrus.Error(err)
logrus.Errorf("error deleteing account request '%v' (%v): %v", params.Body.Token, ar.Email, err)
return account.NewRegisterInternalServerError()
}
if err := tx.Commit(); err != nil {
logrus.Error(err)
logrus.Errorf("error committing '%v' (%v): %v", params.Body.Token, ar.Email, err)
return account.NewRegisterInternalServerError()
}

View File

@ -21,42 +21,42 @@ func (handler *resetPasswordHandler) Handle(params account.ResetPasswordParams)
tx, err := str.Begin()
if err != nil {
logrus.Error(err)
logrus.Errorf("error starting transaction for '%v': %v", params.Body.Token, err)
return account.NewResetPasswordInternalServerError()
}
defer func() { _ = tx.Rollback() }()
prr, err := str.FindPasswordResetRequestWithToken(params.Body.Token, tx)
if err != nil {
logrus.Error(err)
logrus.Errorf("error finding reset request for '%v': %v", params.Body.Token, err)
return account.NewResetPasswordNotFound()
}
a, err := str.GetAccount(prr.AccountId, tx)
if err != nil {
logrus.Error(err)
logrus.Errorf("error finding account for '%v': %v", params.Body.Token, err)
return account.NewResetPasswordNotFound()
}
hpwd, err := hashPassword(params.Body.Password)
if err != nil {
logrus.Error(err)
logrus.Errorf("error hashing password for '%v' (%v): %v", params.Body.Token, a.Email, err)
return account.NewResetPasswordRequestInternalServerError()
}
a.Salt = hpwd.Salt
a.Password = hpwd.Password
if _, err := str.UpdateAccount(a, tx); err != nil {
logrus.Error(err)
logrus.Errorf("error updating for '%v' (%v): %v", params.Body.Token, a.Email, err)
return account.NewResetPasswordInternalServerError()
}
if err := str.DeletePasswordResetRequest(prr.Id, tx); err != nil {
logrus.Error(err)
logrus.Errorf("error deleting reset request '%v' (%v): %v", params.Body.Token, a.Email, err)
return account.NewResetPasswordInternalServerError()
}
if err := tx.Commit(); err != nil {
logrus.Error(err)
logrus.Errorf("error committing '%v' (%v): %v", params.Body.Token, a.Email, err)
return account.NewResetPasswordInternalServerError()
}

View File

@ -24,22 +24,23 @@ func (handler *resetPasswordRequestHandler) Handle(params account.ResetPasswordR
return account.NewResetPasswordRequestBadRequest()
}
logrus.Infof("received reset password request for email '%v'", params.Body.EmailAddress)
var token string
tx, err := str.Begin()
if err != nil {
logrus.Error(err)
logrus.Errorf("error starting transaction for request '%v': %v", params.Body.EmailAddress, err)
return account.NewResetPasswordRequestInternalServerError()
}
defer func() { _ = tx.Rollback() }()
token, err = createToken()
if err != nil {
logrus.Error(err)
logrus.Errorf("error creating token for '%v': %v", params.Body.EmailAddress, err)
return account.NewResetPasswordRequestInternalServerError()
}
acct, err := str.FindAccountWithEmail(params.Body.EmailAddress, tx)
a, err := str.FindAccountWithEmail(params.Body.EmailAddress, tx)
if err != nil {
logrus.Infof("no account found for '%v': %v", params.Body.EmailAddress, err)
return account.NewResetPasswordRequestInternalServerError()
@ -47,29 +48,29 @@ func (handler *resetPasswordRequestHandler) Handle(params account.ResetPasswordR
prr := &store.PasswordResetRequest{
Token: token,
AccountId: acct.Id,
AccountId: a.Id,
}
if _, err := str.CreatePasswordResetRequest(prr, tx); err != nil {
logrus.Errorf("error creating reset password request for '%v': %v", params.Body.EmailAddress, err)
logrus.Errorf("error creating reset password request for '%v': %v", a.Email, err)
return account.NewResetPasswordRequestInternalServerError()
}
if err := tx.Commit(); err != nil {
logrus.Errorf("error committing reset password request for '%v': %v", params.Body.EmailAddress, err)
logrus.Errorf("error committing reset password request for '%v': %v", a.Email, err)
return account.NewResetPasswordRequestInternalServerError()
}
if cfg.Email != nil && cfg.Registration != nil && cfg.ResetPassword != nil {
if err := sendResetPasswordEmail(acct.Email, token); err != nil {
logrus.Errorf("error sending reset password email for '%v': %v", acct.Email, err)
if err := sendResetPasswordEmail(a.Email, token); err != nil {
logrus.Errorf("error sending reset password email for '%v': %v", a.Email, err)
return account.NewResetPasswordRequestInternalServerError()
}
} else {
logrus.Errorf("'email', 'registration', and 'reset_password' configuration missing; skipping reset password email")
}
logrus.Infof("reset password request for '%v' has token '%v'", params.Body.EmailAddress, prr.Token)
logrus.Infof("reset password request for '%v' has token '%v'", a.Email, prr.Token)
return account.NewResetPasswordRequestCreated()
}

View File

@ -7,7 +7,6 @@ import (
"github.com/openziti/zrok/controller/zrokEdgeSdk"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/share"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@ -45,8 +44,7 @@ func (h *unaccessHandler) Handle(params share.UnaccessParams, principal *rest_mo
}
}
if senv == nil {
err := errors.Errorf("environment with id '%v' not found for '%v", envZId, principal.Email)
logrus.Error(err)
logrus.Errorf("environment with id '%v' not found for '%v", envZId, principal.Email)
return share.NewUnaccessUnauthorized()
}
} else {
@ -56,7 +54,7 @@ func (h *unaccessHandler) Handle(params share.UnaccessParams, principal *rest_mo
sfe, err := str.FindFrontendWithToken(feToken, tx)
if err != nil {
logrus.Error(err)
logrus.Errorf("error finding frontend for '%v': %v", principal.Email, err)
return share.NewUnaccessInternalServerError()
}

View File

@ -24,20 +24,20 @@ func newUnshareHandler() *unshareHandler {
func (h *unshareHandler) Handle(params share.UnshareParams, principal *rest_model_zrok.Principal) middleware.Responder {
tx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
logrus.Errorf("error starting transaction for '%v': %v", principal.Email, err)
return share.NewUnshareInternalServerError()
}
defer func() { _ = tx.Rollback() }()
edge, err := edgeClient()
if err != nil {
logrus.Error(err)
logrus.Errorf("error getting edge client for '%v': %v", principal.Email, err)
return share.NewUnshareInternalServerError()
}
shrToken := params.Body.ShrToken
shrZId, err := h.findShareZId(shrToken, edge)
if err != nil {
logrus.Error(err)
logrus.Errorf("error finding share identity for '%v' (%v): %v", shrToken, principal.Email, err)
return share.NewUnshareNotFound()
}
var senv *store.Environment
@ -49,8 +49,7 @@ func (h *unshareHandler) Handle(params share.UnshareParams, principal *rest_mode
}
}
if senv == nil {
err := errors.Errorf("environment with id '%v' not found for '%v", params.Body.EnvZID, principal.Email)
logrus.Error(err)
logrus.Errorf("environment with id '%v' not found for '%v", params.Body.EnvZID, principal.Email)
return share.NewUnshareNotFound()
}
} else {
@ -67,8 +66,7 @@ func (h *unshareHandler) Handle(params share.UnshareParams, principal *rest_mode
}
}
if sshr == nil {
err := errors.Errorf("share with id '%v' not found for '%v'", shrZId, principal.Email)
logrus.Error(err)
logrus.Errorf("share with id '%v' not found for '%v'", shrZId, principal.Email)
return share.NewUnshareNotFound()
}
} else {