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.
 
 
 
 
 
 

532 lines
17 KiB

// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqljson"
"entgo.io/ent/schema/field"
"github.com/dexidp/dex/storage/ent/db/oauth2client"
"github.com/dexidp/dex/storage/ent/db/predicate"
)
// OAuth2ClientUpdate is the builder for updating OAuth2Client entities.
type OAuth2ClientUpdate struct {
config
hooks []Hook
mutation *OAuth2ClientMutation
}
// Where appends a list predicates to the OAuth2ClientUpdate builder.
func (_u *OAuth2ClientUpdate) Where(ps ...predicate.OAuth2Client) *OAuth2ClientUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetSecret sets the "secret" field.
func (_u *OAuth2ClientUpdate) SetSecret(v string) *OAuth2ClientUpdate {
_u.mutation.SetSecret(v)
return _u
}
// SetNillableSecret sets the "secret" field if the given value is not nil.
func (_u *OAuth2ClientUpdate) SetNillableSecret(v *string) *OAuth2ClientUpdate {
if v != nil {
_u.SetSecret(*v)
}
return _u
}
// SetRedirectUris sets the "redirect_uris" field.
func (_u *OAuth2ClientUpdate) SetRedirectUris(v []string) *OAuth2ClientUpdate {
_u.mutation.SetRedirectUris(v)
return _u
}
// AppendRedirectUris appends value to the "redirect_uris" field.
func (_u *OAuth2ClientUpdate) AppendRedirectUris(v []string) *OAuth2ClientUpdate {
_u.mutation.AppendRedirectUris(v)
return _u
}
// ClearRedirectUris clears the value of the "redirect_uris" field.
func (_u *OAuth2ClientUpdate) ClearRedirectUris() *OAuth2ClientUpdate {
_u.mutation.ClearRedirectUris()
return _u
}
// SetTrustedPeers sets the "trusted_peers" field.
func (_u *OAuth2ClientUpdate) SetTrustedPeers(v []string) *OAuth2ClientUpdate {
_u.mutation.SetTrustedPeers(v)
return _u
}
// AppendTrustedPeers appends value to the "trusted_peers" field.
func (_u *OAuth2ClientUpdate) AppendTrustedPeers(v []string) *OAuth2ClientUpdate {
_u.mutation.AppendTrustedPeers(v)
return _u
}
// ClearTrustedPeers clears the value of the "trusted_peers" field.
func (_u *OAuth2ClientUpdate) ClearTrustedPeers() *OAuth2ClientUpdate {
_u.mutation.ClearTrustedPeers()
return _u
}
// SetPublic sets the "public" field.
func (_u *OAuth2ClientUpdate) SetPublic(v bool) *OAuth2ClientUpdate {
_u.mutation.SetPublic(v)
return _u
}
// SetNillablePublic sets the "public" field if the given value is not nil.
func (_u *OAuth2ClientUpdate) SetNillablePublic(v *bool) *OAuth2ClientUpdate {
if v != nil {
_u.SetPublic(*v)
}
return _u
}
// SetName sets the "name" field.
func (_u *OAuth2ClientUpdate) SetName(v string) *OAuth2ClientUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *OAuth2ClientUpdate) SetNillableName(v *string) *OAuth2ClientUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetLogoURL sets the "logo_url" field.
func (_u *OAuth2ClientUpdate) SetLogoURL(v string) *OAuth2ClientUpdate {
_u.mutation.SetLogoURL(v)
return _u
}
// SetNillableLogoURL sets the "logo_url" field if the given value is not nil.
func (_u *OAuth2ClientUpdate) SetNillableLogoURL(v *string) *OAuth2ClientUpdate {
if v != nil {
_u.SetLogoURL(*v)
}
return _u
}
// SetAllowedConnectors sets the "allowed_connectors" field.
func (_u *OAuth2ClientUpdate) SetAllowedConnectors(v []string) *OAuth2ClientUpdate {
_u.mutation.SetAllowedConnectors(v)
return _u
}
// AppendAllowedConnectors appends value to the "allowed_connectors" field.
func (_u *OAuth2ClientUpdate) AppendAllowedConnectors(v []string) *OAuth2ClientUpdate {
_u.mutation.AppendAllowedConnectors(v)
return _u
}
// ClearAllowedConnectors clears the value of the "allowed_connectors" field.
func (_u *OAuth2ClientUpdate) ClearAllowedConnectors() *OAuth2ClientUpdate {
_u.mutation.ClearAllowedConnectors()
return _u
}
// Mutation returns the OAuth2ClientMutation object of the builder.
func (_u *OAuth2ClientUpdate) Mutation() *OAuth2ClientMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *OAuth2ClientUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *OAuth2ClientUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *OAuth2ClientUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *OAuth2ClientUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *OAuth2ClientUpdate) check() error {
if v, ok := _u.mutation.Secret(); ok {
if err := oauth2client.SecretValidator(v); err != nil {
return &ValidationError{Name: "secret", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.secret": %w`, err)}
}
}
if v, ok := _u.mutation.Name(); ok {
if err := oauth2client.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.name": %w`, err)}
}
}
if v, ok := _u.mutation.LogoURL(); ok {
if err := oauth2client.LogoURLValidator(v); err != nil {
return &ValidationError{Name: "logo_url", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.logo_url": %w`, err)}
}
}
return nil
}
func (_u *OAuth2ClientUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(oauth2client.Table, oauth2client.Columns, sqlgraph.NewFieldSpec(oauth2client.FieldID, field.TypeString))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Secret(); ok {
_spec.SetField(oauth2client.FieldSecret, field.TypeString, value)
}
if value, ok := _u.mutation.RedirectUris(); ok {
_spec.SetField(oauth2client.FieldRedirectUris, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedRedirectUris(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, oauth2client.FieldRedirectUris, value)
})
}
if _u.mutation.RedirectUrisCleared() {
_spec.ClearField(oauth2client.FieldRedirectUris, field.TypeJSON)
}
if value, ok := _u.mutation.TrustedPeers(); ok {
_spec.SetField(oauth2client.FieldTrustedPeers, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedTrustedPeers(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, oauth2client.FieldTrustedPeers, value)
})
}
if _u.mutation.TrustedPeersCleared() {
_spec.ClearField(oauth2client.FieldTrustedPeers, field.TypeJSON)
}
if value, ok := _u.mutation.Public(); ok {
_spec.SetField(oauth2client.FieldPublic, field.TypeBool, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(oauth2client.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.LogoURL(); ok {
_spec.SetField(oauth2client.FieldLogoURL, field.TypeString, value)
}
if value, ok := _u.mutation.AllowedConnectors(); ok {
_spec.SetField(oauth2client.FieldAllowedConnectors, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedAllowedConnectors(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, oauth2client.FieldAllowedConnectors, value)
})
}
if _u.mutation.AllowedConnectorsCleared() {
_spec.ClearField(oauth2client.FieldAllowedConnectors, field.TypeJSON)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{oauth2client.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// OAuth2ClientUpdateOne is the builder for updating a single OAuth2Client entity.
type OAuth2ClientUpdateOne struct {
config
fields []string
hooks []Hook
mutation *OAuth2ClientMutation
}
// SetSecret sets the "secret" field.
func (_u *OAuth2ClientUpdateOne) SetSecret(v string) *OAuth2ClientUpdateOne {
_u.mutation.SetSecret(v)
return _u
}
// SetNillableSecret sets the "secret" field if the given value is not nil.
func (_u *OAuth2ClientUpdateOne) SetNillableSecret(v *string) *OAuth2ClientUpdateOne {
if v != nil {
_u.SetSecret(*v)
}
return _u
}
// SetRedirectUris sets the "redirect_uris" field.
func (_u *OAuth2ClientUpdateOne) SetRedirectUris(v []string) *OAuth2ClientUpdateOne {
_u.mutation.SetRedirectUris(v)
return _u
}
// AppendRedirectUris appends value to the "redirect_uris" field.
func (_u *OAuth2ClientUpdateOne) AppendRedirectUris(v []string) *OAuth2ClientUpdateOne {
_u.mutation.AppendRedirectUris(v)
return _u
}
// ClearRedirectUris clears the value of the "redirect_uris" field.
func (_u *OAuth2ClientUpdateOne) ClearRedirectUris() *OAuth2ClientUpdateOne {
_u.mutation.ClearRedirectUris()
return _u
}
// SetTrustedPeers sets the "trusted_peers" field.
func (_u *OAuth2ClientUpdateOne) SetTrustedPeers(v []string) *OAuth2ClientUpdateOne {
_u.mutation.SetTrustedPeers(v)
return _u
}
// AppendTrustedPeers appends value to the "trusted_peers" field.
func (_u *OAuth2ClientUpdateOne) AppendTrustedPeers(v []string) *OAuth2ClientUpdateOne {
_u.mutation.AppendTrustedPeers(v)
return _u
}
// ClearTrustedPeers clears the value of the "trusted_peers" field.
func (_u *OAuth2ClientUpdateOne) ClearTrustedPeers() *OAuth2ClientUpdateOne {
_u.mutation.ClearTrustedPeers()
return _u
}
// SetPublic sets the "public" field.
func (_u *OAuth2ClientUpdateOne) SetPublic(v bool) *OAuth2ClientUpdateOne {
_u.mutation.SetPublic(v)
return _u
}
// SetNillablePublic sets the "public" field if the given value is not nil.
func (_u *OAuth2ClientUpdateOne) SetNillablePublic(v *bool) *OAuth2ClientUpdateOne {
if v != nil {
_u.SetPublic(*v)
}
return _u
}
// SetName sets the "name" field.
func (_u *OAuth2ClientUpdateOne) SetName(v string) *OAuth2ClientUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *OAuth2ClientUpdateOne) SetNillableName(v *string) *OAuth2ClientUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetLogoURL sets the "logo_url" field.
func (_u *OAuth2ClientUpdateOne) SetLogoURL(v string) *OAuth2ClientUpdateOne {
_u.mutation.SetLogoURL(v)
return _u
}
// SetNillableLogoURL sets the "logo_url" field if the given value is not nil.
func (_u *OAuth2ClientUpdateOne) SetNillableLogoURL(v *string) *OAuth2ClientUpdateOne {
if v != nil {
_u.SetLogoURL(*v)
}
return _u
}
// SetAllowedConnectors sets the "allowed_connectors" field.
func (_u *OAuth2ClientUpdateOne) SetAllowedConnectors(v []string) *OAuth2ClientUpdateOne {
_u.mutation.SetAllowedConnectors(v)
return _u
}
// AppendAllowedConnectors appends value to the "allowed_connectors" field.
func (_u *OAuth2ClientUpdateOne) AppendAllowedConnectors(v []string) *OAuth2ClientUpdateOne {
_u.mutation.AppendAllowedConnectors(v)
return _u
}
// ClearAllowedConnectors clears the value of the "allowed_connectors" field.
func (_u *OAuth2ClientUpdateOne) ClearAllowedConnectors() *OAuth2ClientUpdateOne {
_u.mutation.ClearAllowedConnectors()
return _u
}
// Mutation returns the OAuth2ClientMutation object of the builder.
func (_u *OAuth2ClientUpdateOne) Mutation() *OAuth2ClientMutation {
return _u.mutation
}
// Where appends a list predicates to the OAuth2ClientUpdate builder.
func (_u *OAuth2ClientUpdateOne) Where(ps ...predicate.OAuth2Client) *OAuth2ClientUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *OAuth2ClientUpdateOne) Select(field string, fields ...string) *OAuth2ClientUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated OAuth2Client entity.
func (_u *OAuth2ClientUpdateOne) Save(ctx context.Context) (*OAuth2Client, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *OAuth2ClientUpdateOne) SaveX(ctx context.Context) *OAuth2Client {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *OAuth2ClientUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *OAuth2ClientUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *OAuth2ClientUpdateOne) check() error {
if v, ok := _u.mutation.Secret(); ok {
if err := oauth2client.SecretValidator(v); err != nil {
return &ValidationError{Name: "secret", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.secret": %w`, err)}
}
}
if v, ok := _u.mutation.Name(); ok {
if err := oauth2client.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.name": %w`, err)}
}
}
if v, ok := _u.mutation.LogoURL(); ok {
if err := oauth2client.LogoURLValidator(v); err != nil {
return &ValidationError{Name: "logo_url", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.logo_url": %w`, err)}
}
}
return nil
}
func (_u *OAuth2ClientUpdateOne) sqlSave(ctx context.Context) (_node *OAuth2Client, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(oauth2client.Table, oauth2client.Columns, sqlgraph.NewFieldSpec(oauth2client.FieldID, field.TypeString))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "OAuth2Client.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, oauth2client.FieldID)
for _, f := range fields {
if !oauth2client.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != oauth2client.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Secret(); ok {
_spec.SetField(oauth2client.FieldSecret, field.TypeString, value)
}
if value, ok := _u.mutation.RedirectUris(); ok {
_spec.SetField(oauth2client.FieldRedirectUris, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedRedirectUris(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, oauth2client.FieldRedirectUris, value)
})
}
if _u.mutation.RedirectUrisCleared() {
_spec.ClearField(oauth2client.FieldRedirectUris, field.TypeJSON)
}
if value, ok := _u.mutation.TrustedPeers(); ok {
_spec.SetField(oauth2client.FieldTrustedPeers, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedTrustedPeers(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, oauth2client.FieldTrustedPeers, value)
})
}
if _u.mutation.TrustedPeersCleared() {
_spec.ClearField(oauth2client.FieldTrustedPeers, field.TypeJSON)
}
if value, ok := _u.mutation.Public(); ok {
_spec.SetField(oauth2client.FieldPublic, field.TypeBool, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(oauth2client.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.LogoURL(); ok {
_spec.SetField(oauth2client.FieldLogoURL, field.TypeString, value)
}
if value, ok := _u.mutation.AllowedConnectors(); ok {
_spec.SetField(oauth2client.FieldAllowedConnectors, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedAllowedConnectors(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, oauth2client.FieldAllowedConnectors, value)
})
}
if _u.mutation.AllowedConnectorsCleared() {
_spec.ClearField(oauth2client.FieldAllowedConnectors, field.TypeJSON)
}
_node = &OAuth2Client{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{oauth2client.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}