2023-04-19 08:46:02 +00:00
|
|
|
package deviceauth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
UniqueUserCode = "user_code"
|
|
|
|
UniqueDeviceCode = "device_code"
|
|
|
|
DuplicateUserCode = "Errors.DeviceUserCode.AlreadyExists"
|
|
|
|
DuplicateDeviceCode = "Errors.DeviceCode.AlreadyExists"
|
|
|
|
)
|
|
|
|
|
2023-12-20 12:21:08 +00:00
|
|
|
func NewAddUniqueConstraints(deviceCode, userCode string) []*eventstore.UniqueConstraint {
|
2023-10-19 10:19:10 +00:00
|
|
|
return []*eventstore.UniqueConstraint{
|
2023-04-19 08:46:02 +00:00
|
|
|
eventstore.NewAddEventUniqueConstraint(
|
|
|
|
UniqueDeviceCode,
|
2023-12-20 12:21:08 +00:00
|
|
|
deviceCode,
|
2023-04-19 08:46:02 +00:00
|
|
|
DuplicateDeviceCode,
|
|
|
|
),
|
|
|
|
eventstore.NewAddEventUniqueConstraint(
|
|
|
|
UniqueUserCode,
|
|
|
|
userCode,
|
|
|
|
DuplicateUserCode,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-20 12:21:08 +00:00
|
|
|
func NewRemoveUniqueConstraints(deviceCode, userCode string) []*eventstore.UniqueConstraint {
|
2023-10-19 10:19:10 +00:00
|
|
|
return []*eventstore.UniqueConstraint{
|
|
|
|
eventstore.NewRemoveUniqueConstraint(
|
2023-04-19 08:46:02 +00:00
|
|
|
UniqueDeviceCode,
|
2023-12-20 12:21:08 +00:00
|
|
|
deviceCode,
|
2023-04-19 08:46:02 +00:00
|
|
|
),
|
2023-10-19 10:19:10 +00:00
|
|
|
eventstore.NewRemoveUniqueConstraint(
|
2023-04-19 08:46:02 +00:00
|
|
|
UniqueUserCode,
|
|
|
|
userCode,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|