mirror of
https://github.com/openziti/zrok.git
synced 2025-02-16 18:20:51 +01:00
fix for reserved unique name collision checking
This commit is contained in:
parent
73340f0f6f
commit
28d3002207
@ -72,6 +72,15 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
||||
logrus.Errorf("invalid unique name '%v' for account '%v'", uniqueName, principal.Email)
|
||||
return share.NewShareUnprocessableEntity()
|
||||
}
|
||||
shareExists, err := str.ShareWithTokenExists(uniqueName, trx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error checking share for token collision: %v", err)
|
||||
return share.NewUpdateShareInternalServerError()
|
||||
}
|
||||
if shareExists {
|
||||
logrus.Errorf("token '%v' already exists; cannot create share", uniqueName)
|
||||
return share.NewShareConflict()
|
||||
}
|
||||
shrToken = uniqueName
|
||||
}
|
||||
|
||||
@ -135,16 +144,6 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
||||
sshr.FrontendEndpoint = &sshr.ShareMode
|
||||
}
|
||||
|
||||
sh, err := str.FindShareWithToken(sshr.Token, trx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error checking share for token collision: %v", err)
|
||||
return share.NewShareInternalServerError()
|
||||
}
|
||||
if sh != nil {
|
||||
logrus.Errorf("token '%v' already exists; cannot create share", sshr.Token)
|
||||
return share.NewShareConflict()
|
||||
}
|
||||
|
||||
sid, err := str.CreateShare(envId, sshr, trx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error creating share record: %v", err)
|
||||
|
@ -63,6 +63,14 @@ func (str *Store) FindShareWithToken(shrToken string, tx *sqlx.Tx) (*Share, erro
|
||||
return shr, nil
|
||||
}
|
||||
|
||||
func (str *Store) ShareWithTokenExists(shrToken string, tx *sqlx.Tx) (bool, error) {
|
||||
count := 0
|
||||
if err := tx.QueryRowx("select count(0) from shares where token = $1 and not deleted", shrToken).Scan(&count); err != nil {
|
||||
return true, errors.Wrap(err, "error selecting share count by token")
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (str *Store) FindShareWithZIdAndDeleted(zId string, tx *sqlx.Tx) (*Share, error) {
|
||||
shr := &Share{}
|
||||
if err := tx.QueryRowx("select * from shares where z_id = $1", zId).StructScan(shr); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user