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.
 
 
 
 
 
 

266 lines
8.1 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/ent/db/devicerequest"
)
// DeviceRequestCreate is the builder for creating a DeviceRequest entity.
type DeviceRequestCreate struct {
config
mutation *DeviceRequestMutation
hooks []Hook
}
// SetUserCode sets the "user_code" field.
func (_c *DeviceRequestCreate) SetUserCode(v string) *DeviceRequestCreate {
_c.mutation.SetUserCode(v)
return _c
}
// SetDeviceCode sets the "device_code" field.
func (_c *DeviceRequestCreate) SetDeviceCode(v string) *DeviceRequestCreate {
_c.mutation.SetDeviceCode(v)
return _c
}
// SetClientID sets the "client_id" field.
func (_c *DeviceRequestCreate) SetClientID(v string) *DeviceRequestCreate {
_c.mutation.SetClientID(v)
return _c
}
// SetClientSecret sets the "client_secret" field.
func (_c *DeviceRequestCreate) SetClientSecret(v string) *DeviceRequestCreate {
_c.mutation.SetClientSecret(v)
return _c
}
// SetScopes sets the "scopes" field.
func (_c *DeviceRequestCreate) SetScopes(v []string) *DeviceRequestCreate {
_c.mutation.SetScopes(v)
return _c
}
// SetExpiry sets the "expiry" field.
func (_c *DeviceRequestCreate) SetExpiry(v time.Time) *DeviceRequestCreate {
_c.mutation.SetExpiry(v)
return _c
}
// Mutation returns the DeviceRequestMutation object of the builder.
func (_c *DeviceRequestCreate) Mutation() *DeviceRequestMutation {
return _c.mutation
}
// Save creates the DeviceRequest in the database.
func (_c *DeviceRequestCreate) Save(ctx context.Context) (*DeviceRequest, error) {
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *DeviceRequestCreate) SaveX(ctx context.Context) *DeviceRequest {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *DeviceRequestCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *DeviceRequestCreate) 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 *DeviceRequestCreate) check() error {
if _, ok := _c.mutation.UserCode(); !ok {
return &ValidationError{Name: "user_code", err: errors.New(`db: missing required field "DeviceRequest.user_code"`)}
}
if v, ok := _c.mutation.UserCode(); ok {
if err := devicerequest.UserCodeValidator(v); err != nil {
return &ValidationError{Name: "user_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.user_code": %w`, err)}
}
}
if _, ok := _c.mutation.DeviceCode(); !ok {
return &ValidationError{Name: "device_code", err: errors.New(`db: missing required field "DeviceRequest.device_code"`)}
}
if v, ok := _c.mutation.DeviceCode(); ok {
if err := devicerequest.DeviceCodeValidator(v); err != nil {
return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.device_code": %w`, err)}
}
}
if _, ok := _c.mutation.ClientID(); !ok {
return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "DeviceRequest.client_id"`)}
}
if v, ok := _c.mutation.ClientID(); ok {
if err := devicerequest.ClientIDValidator(v); err != nil {
return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_id": %w`, err)}
}
}
if _, ok := _c.mutation.ClientSecret(); !ok {
return &ValidationError{Name: "client_secret", err: errors.New(`db: missing required field "DeviceRequest.client_secret"`)}
}
if v, ok := _c.mutation.ClientSecret(); ok {
if err := devicerequest.ClientSecretValidator(v); err != nil {
return &ValidationError{Name: "client_secret", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_secret": %w`, err)}
}
}
if _, ok := _c.mutation.Expiry(); !ok {
return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "DeviceRequest.expiry"`)}
}
return nil
}
func (_c *DeviceRequestCreate) sqlSave(ctx context.Context) (*DeviceRequest, 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
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *DeviceRequestCreate) createSpec() (*DeviceRequest, *sqlgraph.CreateSpec) {
var (
_node = &DeviceRequest{config: _c.config}
_spec = sqlgraph.NewCreateSpec(devicerequest.Table, sqlgraph.NewFieldSpec(devicerequest.FieldID, field.TypeInt))
)
if value, ok := _c.mutation.UserCode(); ok {
_spec.SetField(devicerequest.FieldUserCode, field.TypeString, value)
_node.UserCode = value
}
if value, ok := _c.mutation.DeviceCode(); ok {
_spec.SetField(devicerequest.FieldDeviceCode, field.TypeString, value)
_node.DeviceCode = value
}
if value, ok := _c.mutation.ClientID(); ok {
_spec.SetField(devicerequest.FieldClientID, field.TypeString, value)
_node.ClientID = value
}
if value, ok := _c.mutation.ClientSecret(); ok {
_spec.SetField(devicerequest.FieldClientSecret, field.TypeString, value)
_node.ClientSecret = value
}
if value, ok := _c.mutation.Scopes(); ok {
_spec.SetField(devicerequest.FieldScopes, field.TypeJSON, value)
_node.Scopes = value
}
if value, ok := _c.mutation.Expiry(); ok {
_spec.SetField(devicerequest.FieldExpiry, field.TypeTime, value)
_node.Expiry = value
}
return _node, _spec
}
// DeviceRequestCreateBulk is the builder for creating many DeviceRequest entities in bulk.
type DeviceRequestCreateBulk struct {
config
err error
builders []*DeviceRequestCreate
}
// Save creates the DeviceRequest entities in the database.
func (_c *DeviceRequestCreateBulk) Save(ctx context.Context) ([]*DeviceRequest, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*DeviceRequest, 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.(*DeviceRequestMutation)
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
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(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 *DeviceRequestCreateBulk) SaveX(ctx context.Context) []*DeviceRequest {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *DeviceRequestCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *DeviceRequestCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}