mirror of https://github.com/dexidp/dex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
916 B
44 lines
916 B
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) |
|
} |
|
|
|
// compose hashed id from user and connection id to use it as primary key |
|
// ent doesn't support multi-key primary yet |
|
// https://github.com/facebook/ent/issues/400 |
|
func offlineSessionID(userID string, connID string, hasher func() hash.Hash) string { |
|
h := hasher() |
|
|
|
h.Write([]byte(userID)) |
|
h.Write([]byte(connID)) |
|
return fmt.Sprintf("%x", h.Sum(nil)) |
|
}
|
|
|