2022-08-29 07:16:12 +00:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
2021-01-01 20:34:47 +00:00
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-03-07 09:15:01 +00:00
|
|
|
"errors"
|
2021-01-01 20:34:47 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2021-03-24 06:37:51 +00:00
|
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
|
|
"entgo.io/ent/schema/field"
|
2021-01-01 20:34:47 +00:00
|
|
|
"github.com/dexidp/dex/storage"
|
|
|
|
"github.com/dexidp/dex/storage/ent/db/keys"
|
|
|
|
"github.com/dexidp/dex/storage/ent/db/predicate"
|
2022-08-29 07:16:12 +00:00
|
|
|
jose "gopkg.in/square/go-jose.v2"
|
2021-01-01 20:34:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// KeysUpdate is the builder for updating Keys entities.
|
|
|
|
type KeysUpdate struct {
|
|
|
|
config
|
|
|
|
hooks []Hook
|
|
|
|
mutation *KeysMutation
|
|
|
|
}
|
|
|
|
|
2021-09-13 13:48:02 +00:00
|
|
|
// Where appends a list predicates to the KeysUpdate builder.
|
2021-01-01 20:34:47 +00:00
|
|
|
func (ku *KeysUpdate) Where(ps ...predicate.Keys) *KeysUpdate {
|
2021-09-13 13:48:02 +00:00
|
|
|
ku.mutation.Where(ps...)
|
2021-01-01 20:34:47 +00:00
|
|
|
return ku
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetVerificationKeys sets the "verification_keys" field.
|
|
|
|
func (ku *KeysUpdate) SetVerificationKeys(sk []storage.VerificationKey) *KeysUpdate {
|
|
|
|
ku.mutation.SetVerificationKeys(sk)
|
|
|
|
return ku
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSigningKey sets the "signing_key" field.
|
|
|
|
func (ku *KeysUpdate) SetSigningKey(jwk jose.JSONWebKey) *KeysUpdate {
|
|
|
|
ku.mutation.SetSigningKey(jwk)
|
|
|
|
return ku
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSigningKeyPub sets the "signing_key_pub" field.
|
|
|
|
func (ku *KeysUpdate) SetSigningKeyPub(jwk jose.JSONWebKey) *KeysUpdate {
|
|
|
|
ku.mutation.SetSigningKeyPub(jwk)
|
|
|
|
return ku
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNextRotation sets the "next_rotation" field.
|
|
|
|
func (ku *KeysUpdate) SetNextRotation(t time.Time) *KeysUpdate {
|
|
|
|
ku.mutation.SetNextRotation(t)
|
|
|
|
return ku
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns the KeysMutation object of the builder.
|
|
|
|
func (ku *KeysUpdate) Mutation() *KeysMutation {
|
|
|
|
return ku.mutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
|
|
func (ku *KeysUpdate) Save(ctx context.Context) (int, error) {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
affected int
|
|
|
|
)
|
|
|
|
if len(ku.hooks) == 0 {
|
|
|
|
affected, err = ku.sqlSave(ctx)
|
|
|
|
} else {
|
|
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
|
|
mutation, ok := m.(*KeysMutation)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
|
|
}
|
|
|
|
ku.mutation = mutation
|
|
|
|
affected, err = ku.sqlSave(ctx)
|
|
|
|
mutation.done = true
|
|
|
|
return affected, err
|
|
|
|
})
|
|
|
|
for i := len(ku.hooks) - 1; i >= 0; i-- {
|
2021-09-13 13:48:02 +00:00
|
|
|
if ku.hooks[i] == nil {
|
|
|
|
return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)")
|
|
|
|
}
|
2021-01-01 20:34:47 +00:00
|
|
|
mut = ku.hooks[i](mut)
|
|
|
|
}
|
|
|
|
if _, err := mut.Mutate(ctx, ku.mutation); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return affected, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
|
|
func (ku *KeysUpdate) SaveX(ctx context.Context) int {
|
|
|
|
affected, err := ku.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return affected
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exec executes the query.
|
|
|
|
func (ku *KeysUpdate) Exec(ctx context.Context) error {
|
|
|
|
_, err := ku.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (ku *KeysUpdate) ExecX(ctx context.Context) {
|
|
|
|
if err := ku.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ku *KeysUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
|
|
Node: &sqlgraph.NodeSpec{
|
|
|
|
Table: keys.Table,
|
|
|
|
Columns: keys.Columns,
|
|
|
|
ID: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Column: keys.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if ps := ku.mutation.predicates; len(ps) > 0 {
|
|
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
|
|
for i := range ps {
|
|
|
|
ps[i](selector)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if value, ok := ku.mutation.VerificationKeys(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeJSON,
|
|
|
|
Value: value,
|
|
|
|
Column: keys.FieldVerificationKeys,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := ku.mutation.SigningKey(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeJSON,
|
|
|
|
Value: value,
|
|
|
|
Column: keys.FieldSigningKey,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := ku.mutation.SigningKeyPub(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeJSON,
|
|
|
|
Value: value,
|
|
|
|
Column: keys.FieldSigningKeyPub,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := ku.mutation.NextRotation(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeTime,
|
|
|
|
Value: value,
|
|
|
|
Column: keys.FieldNextRotation,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if n, err = sqlgraph.UpdateNodes(ctx, ku.driver, _spec); err != nil {
|
|
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
|
|
err = &NotFoundError{keys.Label}
|
2021-09-13 13:48:02 +00:00
|
|
|
} else if sqlgraph.IsConstraintError(err) {
|
2022-08-29 07:16:12 +00:00
|
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
2021-01-01 20:34:47 +00:00
|
|
|
}
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// KeysUpdateOne is the builder for updating a single Keys entity.
|
|
|
|
type KeysUpdateOne struct {
|
|
|
|
config
|
2021-04-30 14:31:49 +00:00
|
|
|
fields []string
|
2021-01-01 20:34:47 +00:00
|
|
|
hooks []Hook
|
|
|
|
mutation *KeysMutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetVerificationKeys sets the "verification_keys" field.
|
|
|
|
func (kuo *KeysUpdateOne) SetVerificationKeys(sk []storage.VerificationKey) *KeysUpdateOne {
|
|
|
|
kuo.mutation.SetVerificationKeys(sk)
|
|
|
|
return kuo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSigningKey sets the "signing_key" field.
|
|
|
|
func (kuo *KeysUpdateOne) SetSigningKey(jwk jose.JSONWebKey) *KeysUpdateOne {
|
|
|
|
kuo.mutation.SetSigningKey(jwk)
|
|
|
|
return kuo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSigningKeyPub sets the "signing_key_pub" field.
|
|
|
|
func (kuo *KeysUpdateOne) SetSigningKeyPub(jwk jose.JSONWebKey) *KeysUpdateOne {
|
|
|
|
kuo.mutation.SetSigningKeyPub(jwk)
|
|
|
|
return kuo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNextRotation sets the "next_rotation" field.
|
|
|
|
func (kuo *KeysUpdateOne) SetNextRotation(t time.Time) *KeysUpdateOne {
|
|
|
|
kuo.mutation.SetNextRotation(t)
|
|
|
|
return kuo
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns the KeysMutation object of the builder.
|
|
|
|
func (kuo *KeysUpdateOne) Mutation() *KeysMutation {
|
|
|
|
return kuo.mutation
|
|
|
|
}
|
|
|
|
|
2021-04-30 14:31:49 +00:00
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
|
|
// The default is selecting all fields defined in the entity schema.
|
|
|
|
func (kuo *KeysUpdateOne) Select(field string, fields ...string) *KeysUpdateOne {
|
|
|
|
kuo.fields = append([]string{field}, fields...)
|
|
|
|
return kuo
|
|
|
|
}
|
|
|
|
|
2021-01-01 20:34:47 +00:00
|
|
|
// Save executes the query and returns the updated Keys entity.
|
|
|
|
func (kuo *KeysUpdateOne) Save(ctx context.Context) (*Keys, error) {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
node *Keys
|
|
|
|
)
|
|
|
|
if len(kuo.hooks) == 0 {
|
|
|
|
node, err = kuo.sqlSave(ctx)
|
|
|
|
} else {
|
|
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
|
|
mutation, ok := m.(*KeysMutation)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
|
|
}
|
|
|
|
kuo.mutation = mutation
|
|
|
|
node, err = kuo.sqlSave(ctx)
|
|
|
|
mutation.done = true
|
|
|
|
return node, err
|
|
|
|
})
|
|
|
|
for i := len(kuo.hooks) - 1; i >= 0; i-- {
|
2021-09-13 13:48:02 +00:00
|
|
|
if kuo.hooks[i] == nil {
|
|
|
|
return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)")
|
|
|
|
}
|
2021-01-01 20:34:47 +00:00
|
|
|
mut = kuo.hooks[i](mut)
|
|
|
|
}
|
2022-08-29 07:16:12 +00:00
|
|
|
v, err := mut.Mutate(ctx, kuo.mutation)
|
|
|
|
if err != nil {
|
2021-01-01 20:34:47 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-29 07:16:12 +00:00
|
|
|
nv, ok := v.(*Keys)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected node type %T returned from KeysMutation", v)
|
|
|
|
}
|
|
|
|
node = nv
|
2021-01-01 20:34:47 +00:00
|
|
|
}
|
|
|
|
return node, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
|
|
func (kuo *KeysUpdateOne) SaveX(ctx context.Context) *Keys {
|
|
|
|
node, err := kuo.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exec executes the query on the entity.
|
|
|
|
func (kuo *KeysUpdateOne) Exec(ctx context.Context) error {
|
|
|
|
_, err := kuo.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (kuo *KeysUpdateOne) ExecX(ctx context.Context) {
|
|
|
|
if err := kuo.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (kuo *KeysUpdateOne) sqlSave(ctx context.Context) (_node *Keys, err error) {
|
|
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
|
|
Node: &sqlgraph.NodeSpec{
|
|
|
|
Table: keys.Table,
|
|
|
|
Columns: keys.Columns,
|
|
|
|
ID: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Column: keys.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
id, ok := kuo.mutation.ID()
|
|
|
|
if !ok {
|
2022-03-07 09:15:01 +00:00
|
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Keys.id" for update`)}
|
2021-01-01 20:34:47 +00:00
|
|
|
}
|
|
|
|
_spec.Node.ID.Value = id
|
2021-04-30 14:31:49 +00:00
|
|
|
if fields := kuo.fields; len(fields) > 0 {
|
|
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
|
|
_spec.Node.Columns = append(_spec.Node.Columns, keys.FieldID)
|
|
|
|
for _, f := range fields {
|
|
|
|
if !keys.ValidColumn(f) {
|
|
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
|
|
}
|
|
|
|
if f != keys.FieldID {
|
|
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-24 06:37:51 +00:00
|
|
|
if ps := kuo.mutation.predicates; len(ps) > 0 {
|
|
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
|
|
for i := range ps {
|
|
|
|
ps[i](selector)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-01 20:34:47 +00:00
|
|
|
if value, ok := kuo.mutation.VerificationKeys(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeJSON,
|
|
|
|
Value: value,
|
|
|
|
Column: keys.FieldVerificationKeys,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := kuo.mutation.SigningKey(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeJSON,
|
|
|
|
Value: value,
|
|
|
|
Column: keys.FieldSigningKey,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := kuo.mutation.SigningKeyPub(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeJSON,
|
|
|
|
Value: value,
|
|
|
|
Column: keys.FieldSigningKeyPub,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := kuo.mutation.NextRotation(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeTime,
|
|
|
|
Value: value,
|
|
|
|
Column: keys.FieldNextRotation,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
_node = &Keys{config: kuo.config}
|
|
|
|
_spec.Assign = _node.assignValues
|
|
|
|
_spec.ScanValues = _node.scanValues
|
|
|
|
if err = sqlgraph.UpdateNode(ctx, kuo.driver, _spec); err != nil {
|
|
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
|
|
err = &NotFoundError{keys.Label}
|
2021-09-13 13:48:02 +00:00
|
|
|
} else if sqlgraph.IsConstraintError(err) {
|
2022-08-29 07:16:12 +00:00
|
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
2021-01-01 20:34:47 +00:00
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return _node, nil
|
|
|
|
}
|