mirror of
https://github.com/netbirdio/dex.git
synced 2026-05-22 18:43:53 -07:00
Signed-off-by: maksim.nabokikh <max.nabokih@gmail.com> Signed-off-by: Maksim Nabokikh <max.nabokih@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
45 lines
919 B
Go
45 lines
919 B
Go
package client
|
|
|
|
import (
|
|
"fmt"
|
|
"hash"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/dexidp/dex/storage"
|
|
"github.com/dexidp/dex/storage/ent/db"
|
|
)
|
|
|
|
func rollback(tx *db.Tx, t string, err error) error {
|
|
rerr := tx.Rollback()
|
|
err = convertDBError(t, err)
|
|
|
|
if rerr == nil {
|
|
return err
|
|
}
|
|
return errors.Wrapf(err, "rolling back transaction: %v", rerr)
|
|
}
|
|
|
|
func convertDBError(t string, err error) error {
|
|
if db.IsNotFound(err) {
|
|
return storage.ErrNotFound
|
|
}
|
|
|
|
if db.IsConstraintError(err) {
|
|
return storage.ErrAlreadyExists
|
|
}
|
|
|
|
return fmt.Errorf(t, err)
|
|
}
|
|
|
|
// compositeKeyID composes a hashed id from two key parts to use as primary key.
|
|
// ent doesn't support multi-key primary yet
|
|
// https://github.com/facebook/ent/issues/400
|
|
func compositeKeyID(first string, second string, hasher func() hash.Hash) string {
|
|
h := hasher()
|
|
|
|
h.Write([]byte(first))
|
|
h.Write([]byte(second))
|
|
return fmt.Sprintf("%x", h.Sum(nil))
|
|
}
|