2023-04-19 11:46:02 +03: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 14:21:08 +02:00
|
|
|
func NewAddUniqueConstraints(deviceCode, userCode string) []*eventstore.UniqueConstraint {
|
2023-10-19 12:19:10 +02:00
|
|
|
return []*eventstore.UniqueConstraint{
|
2023-04-19 11:46:02 +03:00
|
|
|
eventstore.NewAddEventUniqueConstraint(
|
|
|
|
UniqueDeviceCode,
|
2023-12-20 14:21:08 +02:00
|
|
|
deviceCode,
|
2023-04-19 11:46:02 +03:00
|
|
|
DuplicateDeviceCode,
|
|
|
|
),
|
|
|
|
eventstore.NewAddEventUniqueConstraint(
|
|
|
|
UniqueUserCode,
|
|
|
|
userCode,
|
|
|
|
DuplicateUserCode,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-20 14:21:08 +02:00
|
|
|
func NewRemoveUniqueConstraints(deviceCode, userCode string) []*eventstore.UniqueConstraint {
|
2023-10-19 12:19:10 +02:00
|
|
|
return []*eventstore.UniqueConstraint{
|
|
|
|
eventstore.NewRemoveUniqueConstraint(
|
2023-04-19 11:46:02 +03:00
|
|
|
UniqueDeviceCode,
|
2023-12-20 14:21:08 +02:00
|
|
|
deviceCode,
|
2023-04-19 11:46:02 +03:00
|
|
|
),
|
2023-10-19 12:19:10 +02:00
|
|
|
eventstore.NewRemoveUniqueConstraint(
|
2023-04-19 11:46:02 +03:00
|
|
|
UniqueUserCode,
|
|
|
|
userCode,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|