mirror of
https://github.com/openziti/zrok.git
synced 2024-12-26 00:29:15 +01:00
fix authentication transaction; record created identities (#10)
This commit is contained in:
parent
cb1a88e339
commit
1292c5d702
@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/openziti-test-kitchen/zrok/controller/store"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/identity"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
@ -34,6 +35,23 @@ func enableHandler(_ identity.EnableParams, principal *rest_model_zrok.Principal
|
||||
return identity.NewEnableInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
|
||||
tx, err := str.Begin()
|
||||
if err != nil {
|
||||
logrus.Errorf("error starting transaction: %v", err)
|
||||
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
iid, err := str.CreateIdentity(int(principal.ID), &store.Identity{ZitiId: ident.Payload.Data.ID}, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error storing created identity: %v", err)
|
||||
_ = tx.Rollback()
|
||||
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
logrus.Errorf("error committing: %v", err)
|
||||
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
logrus.Infof("recorded identity '%v' with id '%v' for '%v'", ident.Payload.Data.ID, iid, principal.Username)
|
||||
|
||||
resp := identity.NewEnableCreated().WithPayload(&rest_model_zrok.EnableResponse{
|
||||
Identity: ident.Payload.Data.ID,
|
||||
})
|
||||
|
@ -11,12 +11,12 @@ type Identity struct {
|
||||
ZitiId string
|
||||
}
|
||||
|
||||
func (self *Store) CreateIdentity(accountId int, svc *Service, tx *sqlx.Tx) (int, error) {
|
||||
func (self *Store) CreateIdentity(accountId int, i *Identity, tx *sqlx.Tx) (int, error) {
|
||||
stmt, err := tx.Prepare("insert into identities (account_id, ziti_id) values (?, ?)")
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error preparing identities insert statement")
|
||||
}
|
||||
res, err := stmt.Exec(accountId, svc.ZitiId)
|
||||
res, err := stmt.Exec(accountId, i.ZitiId)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error executing identities insert statement")
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ func ZrokAuthenticate(token string) (*rest_model_zrok.Principal, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if a, err := str.FindAccountWithToken(token, tx); err == nil {
|
||||
principal := rest_model_zrok.Principal{
|
||||
ID: int64(a.Id),
|
||||
|
Loading…
Reference in New Issue
Block a user