OpenID Connect (OIDC) identity and OAuth 2.0 provider with pluggable connectors
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.
 
 
 
 
 
 

241 lines
6.6 KiB

// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/ent/db/keys"
jose "github.com/go-jose/go-jose/v4"
)
// KeysCreate is the builder for creating a Keys entity.
type KeysCreate struct {
config
mutation *KeysMutation
hooks []Hook
}
// SetVerificationKeys sets the "verification_keys" field.
func (_c *KeysCreate) SetVerificationKeys(v []storage.VerificationKey) *KeysCreate {
_c.mutation.SetVerificationKeys(v)
return _c
}
// SetSigningKey sets the "signing_key" field.
func (_c *KeysCreate) SetSigningKey(v jose.JSONWebKey) *KeysCreate {
_c.mutation.SetSigningKey(v)
return _c
}
// SetSigningKeyPub sets the "signing_key_pub" field.
func (_c *KeysCreate) SetSigningKeyPub(v jose.JSONWebKey) *KeysCreate {
_c.mutation.SetSigningKeyPub(v)
return _c
}
// SetNextRotation sets the "next_rotation" field.
func (_c *KeysCreate) SetNextRotation(v time.Time) *KeysCreate {
_c.mutation.SetNextRotation(v)
return _c
}
// SetID sets the "id" field.
func (_c *KeysCreate) SetID(v string) *KeysCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the KeysMutation object of the builder.
func (_c *KeysCreate) Mutation() *KeysMutation {
return _c.mutation
}
// Save creates the Keys in the database.
func (_c *KeysCreate) Save(ctx context.Context) (*Keys, error) {
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *KeysCreate) SaveX(ctx context.Context) *Keys {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *KeysCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *KeysCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *KeysCreate) check() error {
if _, ok := _c.mutation.VerificationKeys(); !ok {
return &ValidationError{Name: "verification_keys", err: errors.New(`db: missing required field "Keys.verification_keys"`)}
}
if _, ok := _c.mutation.SigningKey(); !ok {
return &ValidationError{Name: "signing_key", err: errors.New(`db: missing required field "Keys.signing_key"`)}
}
if _, ok := _c.mutation.SigningKeyPub(); !ok {
return &ValidationError{Name: "signing_key_pub", err: errors.New(`db: missing required field "Keys.signing_key_pub"`)}
}
if _, ok := _c.mutation.NextRotation(); !ok {
return &ValidationError{Name: "next_rotation", err: errors.New(`db: missing required field "Keys.next_rotation"`)}
}
if v, ok := _c.mutation.ID(); ok {
if err := keys.IDValidator(v); err != nil {
return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "Keys.id": %w`, err)}
}
}
return nil
}
func (_c *KeysCreate) sqlSave(ctx context.Context) (*Keys, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != nil {
if id, ok := _spec.ID.Value.(string); ok {
_node.ID = id
} else {
return nil, fmt.Errorf("unexpected Keys.ID type: %T", _spec.ID.Value)
}
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *KeysCreate) createSpec() (*Keys, *sqlgraph.CreateSpec) {
var (
_node = &Keys{config: _c.config}
_spec = sqlgraph.NewCreateSpec(keys.Table, sqlgraph.NewFieldSpec(keys.FieldID, field.TypeString))
)
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.VerificationKeys(); ok {
_spec.SetField(keys.FieldVerificationKeys, field.TypeJSON, value)
_node.VerificationKeys = value
}
if value, ok := _c.mutation.SigningKey(); ok {
_spec.SetField(keys.FieldSigningKey, field.TypeJSON, value)
_node.SigningKey = value
}
if value, ok := _c.mutation.SigningKeyPub(); ok {
_spec.SetField(keys.FieldSigningKeyPub, field.TypeJSON, value)
_node.SigningKeyPub = value
}
if value, ok := _c.mutation.NextRotation(); ok {
_spec.SetField(keys.FieldNextRotation, field.TypeTime, value)
_node.NextRotation = value
}
return _node, _spec
}
// KeysCreateBulk is the builder for creating many Keys entities in bulk.
type KeysCreateBulk struct {
config
err error
builders []*KeysCreate
}
// Save creates the Keys entities in the database.
func (_c *KeysCreateBulk) Save(ctx context.Context) ([]*Keys, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Keys, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
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)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *KeysCreateBulk) SaveX(ctx context.Context) []*Keys {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *KeysCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *KeysCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}