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.
 
 
 
 
 
 

450 lines
14 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/authcode"
)
// AuthCodeCreate is the builder for creating a AuthCode entity.
type AuthCodeCreate struct {
config
mutation *AuthCodeMutation
hooks []Hook
}
// SetClientID sets the "client_id" field.
func (_c *AuthCodeCreate) SetClientID(v string) *AuthCodeCreate {
_c.mutation.SetClientID(v)
return _c
}
// SetScopes sets the "scopes" field.
func (_c *AuthCodeCreate) SetScopes(v []string) *AuthCodeCreate {
_c.mutation.SetScopes(v)
return _c
}
// SetNonce sets the "nonce" field.
func (_c *AuthCodeCreate) SetNonce(v string) *AuthCodeCreate {
_c.mutation.SetNonce(v)
return _c
}
// SetRedirectURI sets the "redirect_uri" field.
func (_c *AuthCodeCreate) SetRedirectURI(v string) *AuthCodeCreate {
_c.mutation.SetRedirectURI(v)
return _c
}
// SetClaimsUserID sets the "claims_user_id" field.
func (_c *AuthCodeCreate) SetClaimsUserID(v string) *AuthCodeCreate {
_c.mutation.SetClaimsUserID(v)
return _c
}
// SetClaimsUsername sets the "claims_username" field.
func (_c *AuthCodeCreate) SetClaimsUsername(v string) *AuthCodeCreate {
_c.mutation.SetClaimsUsername(v)
return _c
}
// SetClaimsEmail sets the "claims_email" field.
func (_c *AuthCodeCreate) SetClaimsEmail(v string) *AuthCodeCreate {
_c.mutation.SetClaimsEmail(v)
return _c
}
// SetClaimsEmailVerified sets the "claims_email_verified" field.
func (_c *AuthCodeCreate) SetClaimsEmailVerified(v bool) *AuthCodeCreate {
_c.mutation.SetClaimsEmailVerified(v)
return _c
}
// SetClaimsGroups sets the "claims_groups" field.
func (_c *AuthCodeCreate) SetClaimsGroups(v []string) *AuthCodeCreate {
_c.mutation.SetClaimsGroups(v)
return _c
}
// SetClaimsPreferredUsername sets the "claims_preferred_username" field.
func (_c *AuthCodeCreate) SetClaimsPreferredUsername(v string) *AuthCodeCreate {
_c.mutation.SetClaimsPreferredUsername(v)
return _c
}
// SetNillableClaimsPreferredUsername sets the "claims_preferred_username" field if the given value is not nil.
func (_c *AuthCodeCreate) SetNillableClaimsPreferredUsername(v *string) *AuthCodeCreate {
if v != nil {
_c.SetClaimsPreferredUsername(*v)
}
return _c
}
// SetConnectorID sets the "connector_id" field.
func (_c *AuthCodeCreate) SetConnectorID(v string) *AuthCodeCreate {
_c.mutation.SetConnectorID(v)
return _c
}
// SetConnectorData sets the "connector_data" field.
func (_c *AuthCodeCreate) SetConnectorData(v []byte) *AuthCodeCreate {
_c.mutation.SetConnectorData(v)
return _c
}
// SetExpiry sets the "expiry" field.
func (_c *AuthCodeCreate) SetExpiry(v time.Time) *AuthCodeCreate {
_c.mutation.SetExpiry(v)
return _c
}
// SetCodeChallenge sets the "code_challenge" field.
func (_c *AuthCodeCreate) SetCodeChallenge(v string) *AuthCodeCreate {
_c.mutation.SetCodeChallenge(v)
return _c
}
// SetNillableCodeChallenge sets the "code_challenge" field if the given value is not nil.
func (_c *AuthCodeCreate) SetNillableCodeChallenge(v *string) *AuthCodeCreate {
if v != nil {
_c.SetCodeChallenge(*v)
}
return _c
}
// SetCodeChallengeMethod sets the "code_challenge_method" field.
func (_c *AuthCodeCreate) SetCodeChallengeMethod(v string) *AuthCodeCreate {
_c.mutation.SetCodeChallengeMethod(v)
return _c
}
// SetNillableCodeChallengeMethod sets the "code_challenge_method" field if the given value is not nil.
func (_c *AuthCodeCreate) SetNillableCodeChallengeMethod(v *string) *AuthCodeCreate {
if v != nil {
_c.SetCodeChallengeMethod(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *AuthCodeCreate) SetID(v string) *AuthCodeCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the AuthCodeMutation object of the builder.
func (_c *AuthCodeCreate) Mutation() *AuthCodeMutation {
return _c.mutation
}
// Save creates the AuthCode in the database.
func (_c *AuthCodeCreate) Save(ctx context.Context) (*AuthCode, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *AuthCodeCreate) SaveX(ctx context.Context) *AuthCode {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AuthCodeCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AuthCodeCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *AuthCodeCreate) defaults() {
if _, ok := _c.mutation.ClaimsPreferredUsername(); !ok {
v := authcode.DefaultClaimsPreferredUsername
_c.mutation.SetClaimsPreferredUsername(v)
}
if _, ok := _c.mutation.CodeChallenge(); !ok {
v := authcode.DefaultCodeChallenge
_c.mutation.SetCodeChallenge(v)
}
if _, ok := _c.mutation.CodeChallengeMethod(); !ok {
v := authcode.DefaultCodeChallengeMethod
_c.mutation.SetCodeChallengeMethod(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *AuthCodeCreate) check() error {
if _, ok := _c.mutation.ClientID(); !ok {
return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "AuthCode.client_id"`)}
}
if v, ok := _c.mutation.ClientID(); ok {
if err := authcode.ClientIDValidator(v); err != nil {
return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.client_id": %w`, err)}
}
}
if _, ok := _c.mutation.Nonce(); !ok {
return &ValidationError{Name: "nonce", err: errors.New(`db: missing required field "AuthCode.nonce"`)}
}
if v, ok := _c.mutation.Nonce(); ok {
if err := authcode.NonceValidator(v); err != nil {
return &ValidationError{Name: "nonce", err: fmt.Errorf(`db: validator failed for field "AuthCode.nonce": %w`, err)}
}
}
if _, ok := _c.mutation.RedirectURI(); !ok {
return &ValidationError{Name: "redirect_uri", err: errors.New(`db: missing required field "AuthCode.redirect_uri"`)}
}
if v, ok := _c.mutation.RedirectURI(); ok {
if err := authcode.RedirectURIValidator(v); err != nil {
return &ValidationError{Name: "redirect_uri", err: fmt.Errorf(`db: validator failed for field "AuthCode.redirect_uri": %w`, err)}
}
}
if _, ok := _c.mutation.ClaimsUserID(); !ok {
return &ValidationError{Name: "claims_user_id", err: errors.New(`db: missing required field "AuthCode.claims_user_id"`)}
}
if v, ok := _c.mutation.ClaimsUserID(); ok {
if err := authcode.ClaimsUserIDValidator(v); err != nil {
return &ValidationError{Name: "claims_user_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_user_id": %w`, err)}
}
}
if _, ok := _c.mutation.ClaimsUsername(); !ok {
return &ValidationError{Name: "claims_username", err: errors.New(`db: missing required field "AuthCode.claims_username"`)}
}
if v, ok := _c.mutation.ClaimsUsername(); ok {
if err := authcode.ClaimsUsernameValidator(v); err != nil {
return &ValidationError{Name: "claims_username", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_username": %w`, err)}
}
}
if _, ok := _c.mutation.ClaimsEmail(); !ok {
return &ValidationError{Name: "claims_email", err: errors.New(`db: missing required field "AuthCode.claims_email"`)}
}
if v, ok := _c.mutation.ClaimsEmail(); ok {
if err := authcode.ClaimsEmailValidator(v); err != nil {
return &ValidationError{Name: "claims_email", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_email": %w`, err)}
}
}
if _, ok := _c.mutation.ClaimsEmailVerified(); !ok {
return &ValidationError{Name: "claims_email_verified", err: errors.New(`db: missing required field "AuthCode.claims_email_verified"`)}
}
if _, ok := _c.mutation.ClaimsPreferredUsername(); !ok {
return &ValidationError{Name: "claims_preferred_username", err: errors.New(`db: missing required field "AuthCode.claims_preferred_username"`)}
}
if _, ok := _c.mutation.ConnectorID(); !ok {
return &ValidationError{Name: "connector_id", err: errors.New(`db: missing required field "AuthCode.connector_id"`)}
}
if v, ok := _c.mutation.ConnectorID(); ok {
if err := authcode.ConnectorIDValidator(v); err != nil {
return &ValidationError{Name: "connector_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.connector_id": %w`, err)}
}
}
if _, ok := _c.mutation.Expiry(); !ok {
return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "AuthCode.expiry"`)}
}
if _, ok := _c.mutation.CodeChallenge(); !ok {
return &ValidationError{Name: "code_challenge", err: errors.New(`db: missing required field "AuthCode.code_challenge"`)}
}
if _, ok := _c.mutation.CodeChallengeMethod(); !ok {
return &ValidationError{Name: "code_challenge_method", err: errors.New(`db: missing required field "AuthCode.code_challenge_method"`)}
}
if v, ok := _c.mutation.ID(); ok {
if err := authcode.IDValidator(v); err != nil {
return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "AuthCode.id": %w`, err)}
}
}
return nil
}
func (_c *AuthCodeCreate) sqlSave(ctx context.Context) (*AuthCode, 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 AuthCode.ID type: %T", _spec.ID.Value)
}
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *AuthCodeCreate) createSpec() (*AuthCode, *sqlgraph.CreateSpec) {
var (
_node = &AuthCode{config: _c.config}
_spec = sqlgraph.NewCreateSpec(authcode.Table, sqlgraph.NewFieldSpec(authcode.FieldID, field.TypeString))
)
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.ClientID(); ok {
_spec.SetField(authcode.FieldClientID, field.TypeString, value)
_node.ClientID = value
}
if value, ok := _c.mutation.Scopes(); ok {
_spec.SetField(authcode.FieldScopes, field.TypeJSON, value)
_node.Scopes = value
}
if value, ok := _c.mutation.Nonce(); ok {
_spec.SetField(authcode.FieldNonce, field.TypeString, value)
_node.Nonce = value
}
if value, ok := _c.mutation.RedirectURI(); ok {
_spec.SetField(authcode.FieldRedirectURI, field.TypeString, value)
_node.RedirectURI = value
}
if value, ok := _c.mutation.ClaimsUserID(); ok {
_spec.SetField(authcode.FieldClaimsUserID, field.TypeString, value)
_node.ClaimsUserID = value
}
if value, ok := _c.mutation.ClaimsUsername(); ok {
_spec.SetField(authcode.FieldClaimsUsername, field.TypeString, value)
_node.ClaimsUsername = value
}
if value, ok := _c.mutation.ClaimsEmail(); ok {
_spec.SetField(authcode.FieldClaimsEmail, field.TypeString, value)
_node.ClaimsEmail = value
}
if value, ok := _c.mutation.ClaimsEmailVerified(); ok {
_spec.SetField(authcode.FieldClaimsEmailVerified, field.TypeBool, value)
_node.ClaimsEmailVerified = value
}
if value, ok := _c.mutation.ClaimsGroups(); ok {
_spec.SetField(authcode.FieldClaimsGroups, field.TypeJSON, value)
_node.ClaimsGroups = value
}
if value, ok := _c.mutation.ClaimsPreferredUsername(); ok {
_spec.SetField(authcode.FieldClaimsPreferredUsername, field.TypeString, value)
_node.ClaimsPreferredUsername = value
}
if value, ok := _c.mutation.ConnectorID(); ok {
_spec.SetField(authcode.FieldConnectorID, field.TypeString, value)
_node.ConnectorID = value
}
if value, ok := _c.mutation.ConnectorData(); ok {
_spec.SetField(authcode.FieldConnectorData, field.TypeBytes, value)
_node.ConnectorData = &value
}
if value, ok := _c.mutation.Expiry(); ok {
_spec.SetField(authcode.FieldExpiry, field.TypeTime, value)
_node.Expiry = value
}
if value, ok := _c.mutation.CodeChallenge(); ok {
_spec.SetField(authcode.FieldCodeChallenge, field.TypeString, value)
_node.CodeChallenge = value
}
if value, ok := _c.mutation.CodeChallengeMethod(); ok {
_spec.SetField(authcode.FieldCodeChallengeMethod, field.TypeString, value)
_node.CodeChallengeMethod = value
}
return _node, _spec
}
// AuthCodeCreateBulk is the builder for creating many AuthCode entities in bulk.
type AuthCodeCreateBulk struct {
config
err error
builders []*AuthCodeCreate
}
// Save creates the AuthCode entities in the database.
func (_c *AuthCodeCreateBulk) Save(ctx context.Context) ([]*AuthCode, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*AuthCode, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*AuthCodeMutation)
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 *AuthCodeCreateBulk) SaveX(ctx context.Context) []*AuthCode {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AuthCodeCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AuthCodeCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}