diff --git a/ent/agenttask.go b/ent/agenttask.go index 8629ddda..f350bb54 100755 --- a/ent/agenttask.go +++ b/ent/agenttask.go @@ -10,6 +10,7 @@ import ( "github.com/gen0cide/laforge/ent/agenttask" "github.com/gen0cide/laforge/ent/provisionedhost" "github.com/gen0cide/laforge/ent/provisioningstep" + "github.com/gen0cide/laforge/ent/validation" "github.com/google/uuid" ) @@ -41,6 +42,8 @@ type AgentTask struct { HCLAgentTaskToProvisionedHost *ProvisionedHost `json:"AgentTaskToProvisionedHost,omitempty"` // AgentTaskToAdhocPlan holds the value of the AgentTaskToAdhocPlan edge. HCLAgentTaskToAdhocPlan []*AdhocPlan `json:"AgentTaskToAdhocPlan,omitempty"` + // AgentTaskToValidation holds the value of the AgentTaskToValidation edge. + HCLAgentTaskToValidation *Validation `json:"AgentTaskToValidation,omitempty"` // agent_task_agent_task_to_provisioning_step *uuid.UUID agent_task_agent_task_to_provisioned_host *uuid.UUID @@ -54,9 +57,11 @@ type AgentTaskEdges struct { AgentTaskToProvisionedHost *ProvisionedHost `json:"AgentTaskToProvisionedHost,omitempty"` // AgentTaskToAdhocPlan holds the value of the AgentTaskToAdhocPlan edge. AgentTaskToAdhocPlan []*AdhocPlan `json:"AgentTaskToAdhocPlan,omitempty"` + // AgentTaskToValidation holds the value of the AgentTaskToValidation edge. + AgentTaskToValidation *Validation `json:"AgentTaskToValidation,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [3]bool + loadedTypes [4]bool } // AgentTaskToProvisioningStepOrErr returns the AgentTaskToProvisioningStep value or an error if the edge @@ -96,6 +101,20 @@ func (e AgentTaskEdges) AgentTaskToAdhocPlanOrErr() ([]*AdhocPlan, error) { return nil, &NotLoadedError{edge: "AgentTaskToAdhocPlan"} } +// AgentTaskToValidationOrErr returns the AgentTaskToValidation value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e AgentTaskEdges) AgentTaskToValidationOrErr() (*Validation, error) { + if e.loadedTypes[3] { + if e.AgentTaskToValidation == nil { + // The edge AgentTaskToValidation was loaded in eager-loading, + // but was not found. + return nil, &NotFoundError{label: validation.Label} + } + return e.AgentTaskToValidation, nil + } + return nil, &NotLoadedError{edge: "AgentTaskToValidation"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*AgentTask) scanValues(columns []string) ([]interface{}, error) { values := make([]interface{}, len(columns)) @@ -202,6 +221,11 @@ func (at *AgentTask) QueryAgentTaskToAdhocPlan() *AdhocPlanQuery { return (&AgentTaskClient{config: at.config}).QueryAgentTaskToAdhocPlan(at) } +// QueryAgentTaskToValidation queries the "AgentTaskToValidation" edge of the AgentTask entity. +func (at *AgentTask) QueryAgentTaskToValidation() *ValidationQuery { + return (&AgentTaskClient{config: at.config}).QueryAgentTaskToValidation(at) +} + // Update returns a builder for updating this AgentTask. // Note that you need to call AgentTask.Unwrap() before calling this method if this AgentTask // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/ent/agenttask/agenttask.go b/ent/agenttask/agenttask.go index 7e7be785..de02d887 100755 --- a/ent/agenttask/agenttask.go +++ b/ent/agenttask/agenttask.go @@ -33,6 +33,8 @@ const ( EdgeAgentTaskToProvisionedHost = "AgentTaskToProvisionedHost" // EdgeAgentTaskToAdhocPlan holds the string denoting the agenttasktoadhocplan edge name in mutations. EdgeAgentTaskToAdhocPlan = "AgentTaskToAdhocPlan" + // EdgeAgentTaskToValidation holds the string denoting the agenttasktovalidation edge name in mutations. + EdgeAgentTaskToValidation = "AgentTaskToValidation" // Table holds the table name of the agenttask in the database. Table = "agent_tasks" // AgentTaskToProvisioningStepTable is the table that holds the AgentTaskToProvisioningStep relation/edge. @@ -56,6 +58,13 @@ const ( AgentTaskToAdhocPlanInverseTable = "adhoc_plans" // AgentTaskToAdhocPlanColumn is the table column denoting the AgentTaskToAdhocPlan relation/edge. AgentTaskToAdhocPlanColumn = "adhoc_plan_adhoc_plan_to_agent_task" + // AgentTaskToValidationTable is the table that holds the AgentTaskToValidation relation/edge. + AgentTaskToValidationTable = "validations" + // AgentTaskToValidationInverseTable is the table name for the Validation entity. + // It exists in this package in order to avoid circular dependency with the "validation" package. + AgentTaskToValidationInverseTable = "validations" + // AgentTaskToValidationColumn is the table column denoting the AgentTaskToValidation relation/edge. + AgentTaskToValidationColumn = "agent_task_agent_task_to_validation" ) // Columns holds all SQL columns for agenttask fields. @@ -117,6 +126,7 @@ const ( CommandVALIDATE Command = "VALIDATE" CommandCHANGEPERMS Command = "CHANGEPERMS" CommandAPPENDFILE Command = "APPENDFILE" + CommandVALIDATOR Command = "VALIDATOR" ) func (c Command) String() string { @@ -126,7 +136,7 @@ func (c Command) String() string { // CommandValidator is a validator for the "command" field enum values. It is called by the builders before save. func CommandValidator(c Command) error { switch c { - case CommandDEFAULT, CommandDELETE, CommandREBOOT, CommandEXTRACT, CommandDOWNLOAD, CommandCREATEUSER, CommandCREATEUSERPASS, CommandADDTOGROUP, CommandEXECUTE, CommandVALIDATE, CommandCHANGEPERMS, CommandAPPENDFILE: + case CommandDEFAULT, CommandDELETE, CommandREBOOT, CommandEXTRACT, CommandDOWNLOAD, CommandCREATEUSER, CommandCREATEUSERPASS, CommandADDTOGROUP, CommandEXECUTE, CommandVALIDATE, CommandCHANGEPERMS, CommandAPPENDFILE, CommandVALIDATOR: return nil default: return fmt.Errorf("agenttask: invalid enum value for command field: %q", c) diff --git a/ent/agenttask/where.go b/ent/agenttask/where.go index 9539f45a..ab94bb4e 100755 --- a/ent/agenttask/where.go +++ b/ent/agenttask/where.go @@ -709,6 +709,34 @@ func HasAgentTaskToAdhocPlanWith(preds ...predicate.AdhocPlan) predicate.AgentTa }) } +// HasAgentTaskToValidation applies the HasEdge predicate on the "AgentTaskToValidation" edge. +func HasAgentTaskToValidation() predicate.AgentTask { + return predicate.AgentTask(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AgentTaskToValidationTable, FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, AgentTaskToValidationTable, AgentTaskToValidationColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasAgentTaskToValidationWith applies the HasEdge predicate on the "AgentTaskToValidation" edge with a given conditions (other predicates). +func HasAgentTaskToValidationWith(preds ...predicate.Validation) predicate.AgentTask { + return predicate.AgentTask(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AgentTaskToValidationInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, AgentTaskToValidationTable, AgentTaskToValidationColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.AgentTask) predicate.AgentTask { return predicate.AgentTask(func(s *sql.Selector) { diff --git a/ent/agenttask_create.go b/ent/agenttask_create.go index 4c3197f1..9875b90f 100755 --- a/ent/agenttask_create.go +++ b/ent/agenttask_create.go @@ -13,6 +13,7 @@ import ( "github.com/gen0cide/laforge/ent/agenttask" "github.com/gen0cide/laforge/ent/provisionedhost" "github.com/gen0cide/laforge/ent/provisioningstep" + "github.com/gen0cide/laforge/ent/validation" "github.com/google/uuid" ) @@ -126,6 +127,25 @@ func (atc *AgentTaskCreate) AddAgentTaskToAdhocPlan(a ...*AdhocPlan) *AgentTaskC return atc.AddAgentTaskToAdhocPlanIDs(ids...) } +// SetAgentTaskToValidationID sets the "AgentTaskToValidation" edge to the Validation entity by ID. +func (atc *AgentTaskCreate) SetAgentTaskToValidationID(id uuid.UUID) *AgentTaskCreate { + atc.mutation.SetAgentTaskToValidationID(id) + return atc +} + +// SetNillableAgentTaskToValidationID sets the "AgentTaskToValidation" edge to the Validation entity by ID if the given value is not nil. +func (atc *AgentTaskCreate) SetNillableAgentTaskToValidationID(id *uuid.UUID) *AgentTaskCreate { + if id != nil { + atc = atc.SetAgentTaskToValidationID(*id) + } + return atc +} + +// SetAgentTaskToValidation sets the "AgentTaskToValidation" edge to the Validation entity. +func (atc *AgentTaskCreate) SetAgentTaskToValidation(v *Validation) *AgentTaskCreate { + return atc.SetAgentTaskToValidationID(v.ID) +} + // Mutation returns the AgentTaskMutation object of the builder. func (atc *AgentTaskCreate) Mutation() *AgentTaskMutation { return atc.mutation @@ -383,6 +403,25 @@ func (atc *AgentTaskCreate) createSpec() (*AgentTask, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := atc.mutation.AgentTaskToValidationIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: agenttask.AgentTaskToValidationTable, + Columns: []string{agenttask.AgentTaskToValidationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: validation.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/ent/agenttask_query.go b/ent/agenttask_query.go index b5f74a01..3968a7e9 100755 --- a/ent/agenttask_query.go +++ b/ent/agenttask_query.go @@ -17,6 +17,7 @@ import ( "github.com/gen0cide/laforge/ent/predicate" "github.com/gen0cide/laforge/ent/provisionedhost" "github.com/gen0cide/laforge/ent/provisioningstep" + "github.com/gen0cide/laforge/ent/validation" "github.com/google/uuid" ) @@ -33,6 +34,7 @@ type AgentTaskQuery struct { withAgentTaskToProvisioningStep *ProvisioningStepQuery withAgentTaskToProvisionedHost *ProvisionedHostQuery withAgentTaskToAdhocPlan *AdhocPlanQuery + withAgentTaskToValidation *ValidationQuery withFKs bool // intermediate query (i.e. traversal path). sql *sql.Selector @@ -136,6 +138,28 @@ func (atq *AgentTaskQuery) QueryAgentTaskToAdhocPlan() *AdhocPlanQuery { return query } +// QueryAgentTaskToValidation chains the current query on the "AgentTaskToValidation" edge. +func (atq *AgentTaskQuery) QueryAgentTaskToValidation() *ValidationQuery { + query := &ValidationQuery{config: atq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := atq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := atq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(agenttask.Table, agenttask.FieldID, selector), + sqlgraph.To(validation.Table, validation.FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, agenttask.AgentTaskToValidationTable, agenttask.AgentTaskToValidationColumn), + ) + fromU = sqlgraph.SetNeighbors(atq.driver.Dialect(), step) + return fromU, nil + } + return query +} + // First returns the first AgentTask entity from the query. // Returns a *NotFoundError when no AgentTask was found. func (atq *AgentTaskQuery) First(ctx context.Context) (*AgentTask, error) { @@ -320,6 +344,7 @@ func (atq *AgentTaskQuery) Clone() *AgentTaskQuery { withAgentTaskToProvisioningStep: atq.withAgentTaskToProvisioningStep.Clone(), withAgentTaskToProvisionedHost: atq.withAgentTaskToProvisionedHost.Clone(), withAgentTaskToAdhocPlan: atq.withAgentTaskToAdhocPlan.Clone(), + withAgentTaskToValidation: atq.withAgentTaskToValidation.Clone(), // clone intermediate query. sql: atq.sql.Clone(), path: atq.path, @@ -359,6 +384,17 @@ func (atq *AgentTaskQuery) WithAgentTaskToAdhocPlan(opts ...func(*AdhocPlanQuery return atq } +// WithAgentTaskToValidation tells the query-builder to eager-load the nodes that are connected to +// the "AgentTaskToValidation" edge. The optional arguments are used to configure the query builder of the edge. +func (atq *AgentTaskQuery) WithAgentTaskToValidation(opts ...func(*ValidationQuery)) *AgentTaskQuery { + query := &ValidationQuery{config: atq.config} + for _, opt := range opts { + opt(query) + } + atq.withAgentTaskToValidation = query + return atq +} + // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // @@ -425,10 +461,11 @@ func (atq *AgentTaskQuery) sqlAll(ctx context.Context) ([]*AgentTask, error) { nodes = []*AgentTask{} withFKs = atq.withFKs _spec = atq.querySpec() - loadedTypes = [3]bool{ + loadedTypes = [4]bool{ atq.withAgentTaskToProvisioningStep != nil, atq.withAgentTaskToProvisionedHost != nil, atq.withAgentTaskToAdhocPlan != nil, + atq.withAgentTaskToValidation != nil, } ) if atq.withAgentTaskToProvisioningStep != nil || atq.withAgentTaskToProvisionedHost != nil { @@ -544,6 +581,34 @@ func (atq *AgentTaskQuery) sqlAll(ctx context.Context) ([]*AgentTask, error) { } } + if query := atq.withAgentTaskToValidation; query != nil { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*AgentTask) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + } + query.withFKs = true + query.Where(predicate.Validation(func(s *sql.Selector) { + s.Where(sql.InValues(agenttask.AgentTaskToValidationColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + fk := n.agent_task_agent_task_to_validation + if fk == nil { + return nil, fmt.Errorf(`foreign-key "agent_task_agent_task_to_validation" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "agent_task_agent_task_to_validation" returned %v for node %v`, *fk, n.ID) + } + node.Edges.AgentTaskToValidation = n + } + } + return nodes, nil } diff --git a/ent/agenttask_update.go b/ent/agenttask_update.go index fe122b72..ae5c97ad 100755 --- a/ent/agenttask_update.go +++ b/ent/agenttask_update.go @@ -15,6 +15,7 @@ import ( "github.com/gen0cide/laforge/ent/predicate" "github.com/gen0cide/laforge/ent/provisionedhost" "github.com/gen0cide/laforge/ent/provisioningstep" + "github.com/gen0cide/laforge/ent/validation" "github.com/google/uuid" ) @@ -135,6 +136,25 @@ func (atu *AgentTaskUpdate) AddAgentTaskToAdhocPlan(a ...*AdhocPlan) *AgentTaskU return atu.AddAgentTaskToAdhocPlanIDs(ids...) } +// SetAgentTaskToValidationID sets the "AgentTaskToValidation" edge to the Validation entity by ID. +func (atu *AgentTaskUpdate) SetAgentTaskToValidationID(id uuid.UUID) *AgentTaskUpdate { + atu.mutation.SetAgentTaskToValidationID(id) + return atu +} + +// SetNillableAgentTaskToValidationID sets the "AgentTaskToValidation" edge to the Validation entity by ID if the given value is not nil. +func (atu *AgentTaskUpdate) SetNillableAgentTaskToValidationID(id *uuid.UUID) *AgentTaskUpdate { + if id != nil { + atu = atu.SetAgentTaskToValidationID(*id) + } + return atu +} + +// SetAgentTaskToValidation sets the "AgentTaskToValidation" edge to the Validation entity. +func (atu *AgentTaskUpdate) SetAgentTaskToValidation(v *Validation) *AgentTaskUpdate { + return atu.SetAgentTaskToValidationID(v.ID) +} + // Mutation returns the AgentTaskMutation object of the builder. func (atu *AgentTaskUpdate) Mutation() *AgentTaskMutation { return atu.mutation @@ -173,6 +193,12 @@ func (atu *AgentTaskUpdate) RemoveAgentTaskToAdhocPlan(a ...*AdhocPlan) *AgentTa return atu.RemoveAgentTaskToAdhocPlanIDs(ids...) } +// ClearAgentTaskToValidation clears the "AgentTaskToValidation" edge to the Validation entity. +func (atu *AgentTaskUpdate) ClearAgentTaskToValidation() *AgentTaskUpdate { + atu.mutation.ClearAgentTaskToValidation() + return atu +} + // Save executes the query and returns the number of nodes affected by the update operation. func (atu *AgentTaskUpdate) Save(ctx context.Context) (int, error) { var ( @@ -442,6 +468,41 @@ func (atu *AgentTaskUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if atu.mutation.AgentTaskToValidationCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: agenttask.AgentTaskToValidationTable, + Columns: []string{agenttask.AgentTaskToValidationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: validation.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := atu.mutation.AgentTaskToValidationIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: agenttask.AgentTaskToValidationTable, + Columns: []string{agenttask.AgentTaskToValidationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: validation.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if n, err = sqlgraph.UpdateNodes(ctx, atu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{agenttask.Label} @@ -565,6 +626,25 @@ func (atuo *AgentTaskUpdateOne) AddAgentTaskToAdhocPlan(a ...*AdhocPlan) *AgentT return atuo.AddAgentTaskToAdhocPlanIDs(ids...) } +// SetAgentTaskToValidationID sets the "AgentTaskToValidation" edge to the Validation entity by ID. +func (atuo *AgentTaskUpdateOne) SetAgentTaskToValidationID(id uuid.UUID) *AgentTaskUpdateOne { + atuo.mutation.SetAgentTaskToValidationID(id) + return atuo +} + +// SetNillableAgentTaskToValidationID sets the "AgentTaskToValidation" edge to the Validation entity by ID if the given value is not nil. +func (atuo *AgentTaskUpdateOne) SetNillableAgentTaskToValidationID(id *uuid.UUID) *AgentTaskUpdateOne { + if id != nil { + atuo = atuo.SetAgentTaskToValidationID(*id) + } + return atuo +} + +// SetAgentTaskToValidation sets the "AgentTaskToValidation" edge to the Validation entity. +func (atuo *AgentTaskUpdateOne) SetAgentTaskToValidation(v *Validation) *AgentTaskUpdateOne { + return atuo.SetAgentTaskToValidationID(v.ID) +} + // Mutation returns the AgentTaskMutation object of the builder. func (atuo *AgentTaskUpdateOne) Mutation() *AgentTaskMutation { return atuo.mutation @@ -603,6 +683,12 @@ func (atuo *AgentTaskUpdateOne) RemoveAgentTaskToAdhocPlan(a ...*AdhocPlan) *Age return atuo.RemoveAgentTaskToAdhocPlanIDs(ids...) } +// ClearAgentTaskToValidation clears the "AgentTaskToValidation" edge to the Validation entity. +func (atuo *AgentTaskUpdateOne) ClearAgentTaskToValidation() *AgentTaskUpdateOne { + atuo.mutation.ClearAgentTaskToValidation() + return atuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (atuo *AgentTaskUpdateOne) Select(field string, fields ...string) *AgentTaskUpdateOne { @@ -896,6 +982,41 @@ func (atuo *AgentTaskUpdateOne) sqlSave(ctx context.Context) (_node *AgentTask, } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if atuo.mutation.AgentTaskToValidationCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: agenttask.AgentTaskToValidationTable, + Columns: []string{agenttask.AgentTaskToValidationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: validation.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := atuo.mutation.AgentTaskToValidationIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: agenttask.AgentTaskToValidationTable, + Columns: []string{agenttask.AgentTaskToValidationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: validation.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _node = &AgentTask{config: atuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/ent/client.go b/ent/client.go index fb405c92..4a15be4e 100755 --- a/ent/client.go +++ b/ent/client.go @@ -45,6 +45,7 @@ import ( "github.com/gen0cide/laforge/ent/team" "github.com/gen0cide/laforge/ent/token" "github.com/gen0cide/laforge/ent/user" + "github.com/gen0cide/laforge/ent/validation" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" @@ -126,6 +127,8 @@ type Client struct { Token *TokenClient // User is the client for interacting with the User builders. User *UserClient + // Validation is the client for interacting with the Validation builders. + Validation *ValidationClient } // NewClient creates a new client configured with the given options. @@ -174,6 +177,7 @@ func (c *Client) init() { c.Team = NewTeamClient(c.config) c.Token = NewTokenClient(c.config) c.User = NewUserClient(c.config) + c.Validation = NewValidationClient(c.config) } // Open opens a database/sql.DB specified by the driver name and @@ -242,6 +246,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { Team: NewTeamClient(cfg), Token: NewTokenClient(cfg), User: NewUserClient(cfg), + Validation: NewValidationClient(cfg), }, nil } @@ -295,6 +300,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) Team: NewTeamClient(cfg), Token: NewTokenClient(cfg), User: NewUserClient(cfg), + Validation: NewValidationClient(cfg), }, nil } @@ -359,6 +365,7 @@ func (c *Client) Use(hooks ...Hook) { c.Team.Use(hooks...) c.Token.Use(hooks...) c.User.Use(hooks...) + c.Validation.Use(hooks...) } // AdhocPlanClient is a client for the AdhocPlan schema. @@ -802,6 +809,22 @@ func (c *AgentTaskClient) QueryAgentTaskToAdhocPlan(at *AgentTask) *AdhocPlanQue return query } +// QueryAgentTaskToValidation queries the AgentTaskToValidation edge of a AgentTask. +func (c *AgentTaskClient) QueryAgentTaskToValidation(at *AgentTask) *ValidationQuery { + query := &ValidationQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := at.ID + step := sqlgraph.NewStep( + sqlgraph.From(agenttask.Table, agenttask.FieldID, id), + sqlgraph.To(validation.Table, validation.FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, agenttask.AgentTaskToValidationTable, agenttask.AgentTaskToValidationColumn), + ) + fromV = sqlgraph.Neighbors(at.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *AgentTaskClient) Hooks() []Hook { return c.hooks.AgentTask @@ -4870,6 +4893,22 @@ func (c *ScriptClient) QueryScriptToEnvironment(s *Script) *EnvironmentQuery { return query } +// QueryScriptToValidation queries the ScriptToValidation edge of a Script. +func (c *ScriptClient) QueryScriptToValidation(s *Script) *ValidationQuery { + query := &ValidationQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := s.ID + step := sqlgraph.NewStep( + sqlgraph.From(script.Table, script.FieldID, id), + sqlgraph.To(validation.Table, validation.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, script.ScriptToValidationTable, script.ScriptToValidationColumn), + ) + fromV = sqlgraph.Neighbors(s.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *ScriptClient) Hooks() []Hook { return c.hooks.Script @@ -5734,3 +5773,125 @@ func (c *UserClient) QueryUserToEnvironment(u *User) *EnvironmentQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +// ValidationClient is a client for the Validation schema. +type ValidationClient struct { + config +} + +// NewValidationClient returns a client for the Validation from the given config. +func NewValidationClient(c config) *ValidationClient { + return &ValidationClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `validation.Hooks(f(g(h())))`. +func (c *ValidationClient) Use(hooks ...Hook) { + c.hooks.Validation = append(c.hooks.Validation, hooks...) +} + +// Create returns a create builder for Validation. +func (c *ValidationClient) Create() *ValidationCreate { + mutation := newValidationMutation(c.config, OpCreate) + return &ValidationCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Validation entities. +func (c *ValidationClient) CreateBulk(builders ...*ValidationCreate) *ValidationCreateBulk { + return &ValidationCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Validation. +func (c *ValidationClient) Update() *ValidationUpdate { + mutation := newValidationMutation(c.config, OpUpdate) + return &ValidationUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ValidationClient) UpdateOne(v *Validation) *ValidationUpdateOne { + mutation := newValidationMutation(c.config, OpUpdateOne, withValidation(v)) + return &ValidationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ValidationClient) UpdateOneID(id uuid.UUID) *ValidationUpdateOne { + mutation := newValidationMutation(c.config, OpUpdateOne, withValidationID(id)) + return &ValidationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Validation. +func (c *ValidationClient) Delete() *ValidationDelete { + mutation := newValidationMutation(c.config, OpDelete) + return &ValidationDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *ValidationClient) DeleteOne(v *Validation) *ValidationDeleteOne { + return c.DeleteOneID(v.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *ValidationClient) DeleteOneID(id uuid.UUID) *ValidationDeleteOne { + builder := c.Delete().Where(validation.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ValidationDeleteOne{builder} +} + +// Query returns a query builder for Validation. +func (c *ValidationClient) Query() *ValidationQuery { + return &ValidationQuery{ + config: c.config, + } +} + +// Get returns a Validation entity by its id. +func (c *ValidationClient) Get(ctx context.Context, id uuid.UUID) (*Validation, error) { + return c.Query().Where(validation.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ValidationClient) GetX(ctx context.Context, id uuid.UUID) *Validation { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryValidationToAgentTask queries the ValidationToAgentTask edge of a Validation. +func (c *ValidationClient) QueryValidationToAgentTask(v *Validation) *AgentTaskQuery { + query := &AgentTaskQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := v.ID + step := sqlgraph.NewStep( + sqlgraph.From(validation.Table, validation.FieldID, id), + sqlgraph.To(agenttask.Table, agenttask.FieldID), + sqlgraph.Edge(sqlgraph.O2O, true, validation.ValidationToAgentTaskTable, validation.ValidationToAgentTaskColumn), + ) + fromV = sqlgraph.Neighbors(v.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryValidationToScript queries the ValidationToScript edge of a Validation. +func (c *ValidationClient) QueryValidationToScript(v *Validation) *ScriptQuery { + query := &ScriptQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := v.ID + step := sqlgraph.NewStep( + sqlgraph.From(validation.Table, validation.FieldID, id), + sqlgraph.To(script.Table, script.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, validation.ValidationToScriptTable, validation.ValidationToScriptColumn), + ) + fromV = sqlgraph.Neighbors(v.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *ValidationClient) Hooks() []Hook { + return c.hooks.Validation +} diff --git a/ent/collection.go b/ent/collection.go index 79b91862..6c1d8af9 100755 --- a/ent/collection.go +++ b/ent/collection.go @@ -427,3 +427,15 @@ func (u *UserQuery) CollectFields(ctx context.Context, satisfies ...string) *Use func (u *UserQuery) collectField(ctx *graphql.OperationContext, field graphql.CollectedField, satisfies ...string) *UserQuery { return u } + +// CollectFields tells the query-builder to eagerly load connected nodes by resolver context. +func (v *ValidationQuery) CollectFields(ctx context.Context, satisfies ...string) *ValidationQuery { + if fc := graphql.GetFieldContext(ctx); fc != nil { + v = v.collectField(graphql.GetOperationContext(ctx), fc.Field, satisfies...) + } + return v +} + +func (v *ValidationQuery) collectField(ctx *graphql.OperationContext, field graphql.CollectedField, satisfies ...string) *ValidationQuery { + return v +} diff --git a/ent/config.go b/ent/config.go index a31d8c1d..774953f4 100755 --- a/ent/config.go +++ b/ent/config.go @@ -59,6 +59,7 @@ type hooks struct { Team []ent.Hook Token []ent.Hook User []ent.Hook + Validation []ent.Hook } // Options applies the options on the config object. diff --git a/ent/edge.go b/ent/edge.go index 0552d3d8..0423956c 100755 --- a/ent/edge.go +++ b/ent/edge.go @@ -92,6 +92,14 @@ func (at *AgentTask) AgentTaskToAdhocPlan(ctx context.Context) ([]*AdhocPlan, er return result, err } +func (at *AgentTask) AgentTaskToValidation(ctx context.Context) (*Validation, error) { + result, err := at.Edges.AgentTaskToValidationOrErr() + if IsNotLoaded(err) { + result, err = at.QueryAgentTaskToValidation().Only(ctx) + } + return result, MaskNotFound(err) +} + func (au *AuthUser) AuthUserToToken(ctx context.Context) ([]*Token, error) { result, err := au.Edges.AuthUserToTokenOrErr() if IsNotLoaded(err) { @@ -956,6 +964,14 @@ func (s *Script) ScriptToEnvironment(ctx context.Context) (*Environment, error) return result, MaskNotFound(err) } +func (s *Script) ScriptToValidation(ctx context.Context) (*Validation, error) { + result, err := s.Edges.ScriptToValidationOrErr() + if IsNotLoaded(err) { + result, err = s.QueryScriptToValidation().Only(ctx) + } + return result, MaskNotFound(err) +} + func (st *ServerTask) ServerTaskToAuthUser(ctx context.Context) (*AuthUser, error) { result, err := st.Edges.ServerTaskToAuthUserOrErr() if IsNotLoaded(err) { @@ -1115,3 +1131,19 @@ func (u *User) UserToEnvironment(ctx context.Context) ([]*Environment, error) { } return result, err } + +func (v *Validation) ValidationToAgentTask(ctx context.Context) (*AgentTask, error) { + result, err := v.Edges.ValidationToAgentTaskOrErr() + if IsNotLoaded(err) { + result, err = v.QueryValidationToAgentTask().Only(ctx) + } + return result, MaskNotFound(err) +} + +func (v *Validation) ValidationToScript(ctx context.Context) ([]*Script, error) { + result, err := v.Edges.ValidationToScriptOrErr() + if IsNotLoaded(err) { + result, err = v.QueryValidationToScript().All(ctx) + } + return result, err +} diff --git a/ent/ent.go b/ent/ent.go index 807323a8..27014257 100755 --- a/ent/ent.go +++ b/ent/ent.go @@ -43,6 +43,7 @@ import ( "github.com/gen0cide/laforge/ent/team" "github.com/gen0cide/laforge/ent/token" "github.com/gen0cide/laforge/ent/user" + "github.com/gen0cide/laforge/ent/validation" ) // ent aliases to avoid import conflicts in user's code. @@ -98,6 +99,7 @@ func columnChecker(table string) func(string) error { team.Table: team.ValidColumn, token.Table: token.ValidColumn, user.Table: user.ValidColumn, + validation.Table: validation.ValidColumn, } check, ok := checks[table] if !ok { diff --git a/ent/hook/hook.go b/ent/hook/hook.go index f439f75d..a4cf37f2 100755 --- a/ent/hook/hook.go +++ b/ent/hook/hook.go @@ -464,6 +464,19 @@ func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) return f(ctx, mv) } +// The ValidationFunc type is an adapter to allow the use of ordinary +// function as Validation mutator. +type ValidationFunc func(context.Context, *ent.ValidationMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f ValidationFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + mv, ok := m.(*ent.ValidationMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ValidationMutation", m) + } + return f(ctx, mv) +} + // Condition is a hook condition function. type Condition func(context.Context, ent.Mutation) bool diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index 9cfa6f66..eb5ae0de 100755 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -84,7 +84,7 @@ var ( // AgentTasksColumns holds the columns for the "agent_tasks" table. AgentTasksColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, - {Name: "command", Type: field.TypeEnum, Enums: []string{"DEFAULT", "DELETE", "REBOOT", "EXTRACT", "DOWNLOAD", "CREATEUSER", "CREATEUSERPASS", "ADDTOGROUP", "EXECUTE", "VALIDATE", "CHANGEPERMS", "APPENDFILE"}}, + {Name: "command", Type: field.TypeEnum, Enums: []string{"DEFAULT", "DELETE", "REBOOT", "EXTRACT", "DOWNLOAD", "CREATEUSER", "CREATEUSERPASS", "ADDTOGROUP", "EXECUTE", "VALIDATE", "CHANGEPERMS", "APPENDFILE", "VALIDATOR"}}, {Name: "args", Type: field.TypeString}, {Name: "number", Type: field.TypeInt}, {Name: "output", Type: field.TypeString, Default: ""}, @@ -764,7 +764,7 @@ var ( // ProvisioningStepsColumns holds the columns for the "provisioning_steps" table. ProvisioningStepsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, - {Name: "type", Type: field.TypeEnum, Enums: []string{"Script", "Command", "DNSRecord", "FileDelete", "FileDownload", "FileExtract"}}, + {Name: "type", Type: field.TypeEnum, Enums: []string{"Script", "Command", "DNSRecord", "FileDelete", "FileDownload", "FileExtract", "Validate"}}, {Name: "step_number", Type: field.TypeInt}, {Name: "gin_file_middleware_gin_file_middleware_to_provisioning_step", Type: field.TypeUUID, Unique: true, Nullable: true}, {Name: "plan_plan_to_provisioning_step", Type: field.TypeUUID, Unique: true, Nullable: true}, @@ -871,6 +871,7 @@ var ( {Name: "abs_path", Type: field.TypeString}, {Name: "tags", Type: field.TypeJSON}, {Name: "environment_environment_to_script", Type: field.TypeUUID, Nullable: true}, + {Name: "script_script_to_validation", Type: field.TypeUUID, Nullable: true}, } // ScriptsTable holds the schema information for the "scripts" table. ScriptsTable = &schema.Table{ @@ -884,6 +885,12 @@ var ( RefColumns: []*schema.Column{EnvironmentsColumns[0]}, OnDelete: schema.Cascade, }, + { + Symbol: "scripts_validations_ScriptToValidation", + Columns: []*schema.Column{ScriptsColumns[16]}, + RefColumns: []*schema.Column{ValidationsColumns[0]}, + OnDelete: schema.SetNull, + }, }, } // ServerTasksColumns holds the columns for the "server_tasks" table. @@ -1121,6 +1128,41 @@ var ( }, }, } + // ValidationsColumns holds the columns for the "validations" table. + ValidationsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "hcl_id", Type: field.TypeString}, + {Name: "validation_type", Type: field.TypeString, Default: ""}, + {Name: "output", Type: field.TypeString, Default: ""}, + {Name: "state", Type: field.TypeEnum, Enums: []string{"AWAITING", "INPROGRESS", "FAILED", "COMPLETE"}}, + {Name: "error_message", Type: field.TypeString, Default: ""}, + {Name: "regex", Type: field.TypeString}, + {Name: "ip", Type: field.TypeString}, + {Name: "port", Type: field.TypeInt}, + {Name: "hostname", Type: field.TypeString}, + {Name: "nameservers", Type: field.TypeJSON}, + {Name: "package_name", Type: field.TypeString}, + {Name: "username", Type: field.TypeString}, + {Name: "group_name", Type: field.TypeString}, + {Name: "field_path", Type: field.TypeString}, + {Name: "service_name", Type: field.TypeString}, + {Name: "process_name", Type: field.TypeString}, + {Name: "agent_task_agent_task_to_validation", Type: field.TypeUUID, Unique: true, Nullable: true}, + } + // ValidationsTable holds the schema information for the "validations" table. + ValidationsTable = &schema.Table{ + Name: "validations", + Columns: ValidationsColumns, + PrimaryKey: []*schema.Column{ValidationsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "validations_agent_tasks_AgentTaskToValidation", + Columns: []*schema.Column{ValidationsColumns[17]}, + RefColumns: []*schema.Column{AgentTasksColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } // AdhocPlanNextAdhocPlanColumns holds the columns for the "adhoc_plan_NextAdhocPlan" table. AdhocPlanNextAdhocPlanColumns = []*schema.Column{ {Name: "adhoc_plan_id", Type: field.TypeUUID}, @@ -1358,6 +1400,7 @@ var ( TeamsTable, TokensTable, UsersTable, + ValidationsTable, AdhocPlanNextAdhocPlanTable, CompetitionCompetitionToDNSTable, EnvironmentEnvironmentToUserTable, @@ -1423,6 +1466,7 @@ func init() { ProvisioningStepsTable.ForeignKeys[7].RefTable = FileDownloadsTable ProvisioningStepsTable.ForeignKeys[8].RefTable = FileExtractsTable ScriptsTable.ForeignKeys[0].RefTable = EnvironmentsTable + ScriptsTable.ForeignKeys[1].RefTable = ValidationsTable ServerTasksTable.ForeignKeys[0].RefTable = AuthUsersTable ServerTasksTable.ForeignKeys[1].RefTable = EnvironmentsTable ServerTasksTable.ForeignKeys[2].RefTable = BuildsTable @@ -1443,6 +1487,7 @@ func init() { UsersTable.ForeignKeys[1].RefTable = FindingsTable UsersTable.ForeignKeys[2].RefTable = HostsTable UsersTable.ForeignKeys[3].RefTable = ScriptsTable + ValidationsTable.ForeignKeys[0].RefTable = AgentTasksTable AdhocPlanNextAdhocPlanTable.ForeignKeys[0].RefTable = AdhocPlansTable AdhocPlanNextAdhocPlanTable.ForeignKeys[1].RefTable = AdhocPlansTable CompetitionCompetitionToDNSTable.ForeignKeys[0].RefTable = CompetitionsTable diff --git a/ent/mutation.go b/ent/mutation.go index 75c398ec..a1f8b3b9 100755 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -44,6 +44,7 @@ import ( "github.com/gen0cide/laforge/ent/team" "github.com/gen0cide/laforge/ent/token" "github.com/gen0cide/laforge/ent/user" + "github.com/gen0cide/laforge/ent/validation" "github.com/google/uuid" "entgo.io/ent" @@ -93,6 +94,7 @@ const ( TypeTeam = "Team" TypeToken = "Token" TypeUser = "User" + TypeValidation = "Validation" ) // AdhocPlanMutation represents an operation that mutates the AdhocPlan nodes in the graph. @@ -2225,6 +2227,8 @@ type AgentTaskMutation struct { _AgentTaskToAdhocPlan map[uuid.UUID]struct{} removed_AgentTaskToAdhocPlan map[uuid.UUID]struct{} cleared_AgentTaskToAdhocPlan bool + _AgentTaskToValidation *uuid.UUID + cleared_AgentTaskToValidation bool done bool oldValue func(context.Context) (*AgentTask, error) predicates []predicate.AgentTask @@ -2683,6 +2687,45 @@ func (m *AgentTaskMutation) ResetAgentTaskToAdhocPlan() { m.removed_AgentTaskToAdhocPlan = nil } +// SetAgentTaskToValidationID sets the "AgentTaskToValidation" edge to the Validation entity by id. +func (m *AgentTaskMutation) SetAgentTaskToValidationID(id uuid.UUID) { + m._AgentTaskToValidation = &id +} + +// ClearAgentTaskToValidation clears the "AgentTaskToValidation" edge to the Validation entity. +func (m *AgentTaskMutation) ClearAgentTaskToValidation() { + m.cleared_AgentTaskToValidation = true +} + +// AgentTaskToValidationCleared reports if the "AgentTaskToValidation" edge to the Validation entity was cleared. +func (m *AgentTaskMutation) AgentTaskToValidationCleared() bool { + return m.cleared_AgentTaskToValidation +} + +// AgentTaskToValidationID returns the "AgentTaskToValidation" edge ID in the mutation. +func (m *AgentTaskMutation) AgentTaskToValidationID() (id uuid.UUID, exists bool) { + if m._AgentTaskToValidation != nil { + return *m._AgentTaskToValidation, true + } + return +} + +// AgentTaskToValidationIDs returns the "AgentTaskToValidation" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// AgentTaskToValidationID instead. It exists only for internal usage by the builders. +func (m *AgentTaskMutation) AgentTaskToValidationIDs() (ids []uuid.UUID) { + if id := m._AgentTaskToValidation; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetAgentTaskToValidation resets all changes to the "AgentTaskToValidation" edge. +func (m *AgentTaskMutation) ResetAgentTaskToValidation() { + m._AgentTaskToValidation = nil + m.cleared_AgentTaskToValidation = false +} + // Where appends a list predicates to the AgentTaskMutation builder. func (m *AgentTaskMutation) Where(ps ...predicate.AgentTask) { m.predicates = append(m.predicates, ps...) @@ -2901,7 +2944,7 @@ func (m *AgentTaskMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *AgentTaskMutation) AddedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 4) if m._AgentTaskToProvisioningStep != nil { edges = append(edges, agenttask.EdgeAgentTaskToProvisioningStep) } @@ -2911,6 +2954,9 @@ func (m *AgentTaskMutation) AddedEdges() []string { if m._AgentTaskToAdhocPlan != nil { edges = append(edges, agenttask.EdgeAgentTaskToAdhocPlan) } + if m._AgentTaskToValidation != nil { + edges = append(edges, agenttask.EdgeAgentTaskToValidation) + } return edges } @@ -2932,13 +2978,17 @@ func (m *AgentTaskMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case agenttask.EdgeAgentTaskToValidation: + if id := m._AgentTaskToValidation; id != nil { + return []ent.Value{*id} + } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *AgentTaskMutation) RemovedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 4) if m.removed_AgentTaskToAdhocPlan != nil { edges = append(edges, agenttask.EdgeAgentTaskToAdhocPlan) } @@ -2961,7 +3011,7 @@ func (m *AgentTaskMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AgentTaskMutation) ClearedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 4) if m.cleared_AgentTaskToProvisioningStep { edges = append(edges, agenttask.EdgeAgentTaskToProvisioningStep) } @@ -2971,6 +3021,9 @@ func (m *AgentTaskMutation) ClearedEdges() []string { if m.cleared_AgentTaskToAdhocPlan { edges = append(edges, agenttask.EdgeAgentTaskToAdhocPlan) } + if m.cleared_AgentTaskToValidation { + edges = append(edges, agenttask.EdgeAgentTaskToValidation) + } return edges } @@ -2984,6 +3037,8 @@ func (m *AgentTaskMutation) EdgeCleared(name string) bool { return m.cleared_AgentTaskToProvisionedHost case agenttask.EdgeAgentTaskToAdhocPlan: return m.cleared_AgentTaskToAdhocPlan + case agenttask.EdgeAgentTaskToValidation: + return m.cleared_AgentTaskToValidation } return false } @@ -2998,6 +3053,9 @@ func (m *AgentTaskMutation) ClearEdge(name string) error { case agenttask.EdgeAgentTaskToProvisionedHost: m.ClearAgentTaskToProvisionedHost() return nil + case agenttask.EdgeAgentTaskToValidation: + m.ClearAgentTaskToValidation() + return nil } return fmt.Errorf("unknown AgentTask unique edge %s", name) } @@ -3015,6 +3073,9 @@ func (m *AgentTaskMutation) ResetEdge(name string) error { case agenttask.EdgeAgentTaskToAdhocPlan: m.ResetAgentTaskToAdhocPlan() return nil + case agenttask.EdgeAgentTaskToValidation: + m.ResetAgentTaskToValidation() + return nil } return fmt.Errorf("unknown AgentTask edge %s", name) } @@ -24420,6 +24481,8 @@ type ScriptMutation struct { cleared_ScriptToFinding bool _ScriptToEnvironment *uuid.UUID cleared_ScriptToEnvironment bool + _ScriptToValidation *uuid.UUID + cleared_ScriptToValidation bool done bool oldValue func(context.Context) (*Script, error) predicates []predicate.Script @@ -25201,6 +25264,45 @@ func (m *ScriptMutation) ResetScriptToEnvironment() { m.cleared_ScriptToEnvironment = false } +// SetScriptToValidationID sets the "ScriptToValidation" edge to the Validation entity by id. +func (m *ScriptMutation) SetScriptToValidationID(id uuid.UUID) { + m._ScriptToValidation = &id +} + +// ClearScriptToValidation clears the "ScriptToValidation" edge to the Validation entity. +func (m *ScriptMutation) ClearScriptToValidation() { + m.cleared_ScriptToValidation = true +} + +// ScriptToValidationCleared reports if the "ScriptToValidation" edge to the Validation entity was cleared. +func (m *ScriptMutation) ScriptToValidationCleared() bool { + return m.cleared_ScriptToValidation +} + +// ScriptToValidationID returns the "ScriptToValidation" edge ID in the mutation. +func (m *ScriptMutation) ScriptToValidationID() (id uuid.UUID, exists bool) { + if m._ScriptToValidation != nil { + return *m._ScriptToValidation, true + } + return +} + +// ScriptToValidationIDs returns the "ScriptToValidation" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ScriptToValidationID instead. It exists only for internal usage by the builders. +func (m *ScriptMutation) ScriptToValidationIDs() (ids []uuid.UUID) { + if id := m._ScriptToValidation; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetScriptToValidation resets all changes to the "ScriptToValidation" edge. +func (m *ScriptMutation) ResetScriptToValidation() { + m._ScriptToValidation = nil + m.cleared_ScriptToValidation = false +} + // Where appends a list predicates to the ScriptMutation builder. func (m *ScriptMutation) Where(ps ...predicate.Script) { m.predicates = append(m.predicates, ps...) @@ -25567,7 +25669,7 @@ func (m *ScriptMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *ScriptMutation) AddedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 4) if m._ScriptToUser != nil { edges = append(edges, script.EdgeScriptToUser) } @@ -25577,6 +25679,9 @@ func (m *ScriptMutation) AddedEdges() []string { if m._ScriptToEnvironment != nil { edges = append(edges, script.EdgeScriptToEnvironment) } + if m._ScriptToValidation != nil { + edges = append(edges, script.EdgeScriptToValidation) + } return edges } @@ -25600,13 +25705,17 @@ func (m *ScriptMutation) AddedIDs(name string) []ent.Value { if id := m._ScriptToEnvironment; id != nil { return []ent.Value{*id} } + case script.EdgeScriptToValidation: + if id := m._ScriptToValidation; id != nil { + return []ent.Value{*id} + } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ScriptMutation) RemovedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 4) if m.removed_ScriptToUser != nil { edges = append(edges, script.EdgeScriptToUser) } @@ -25638,7 +25747,7 @@ func (m *ScriptMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ScriptMutation) ClearedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 4) if m.cleared_ScriptToUser { edges = append(edges, script.EdgeScriptToUser) } @@ -25648,6 +25757,9 @@ func (m *ScriptMutation) ClearedEdges() []string { if m.cleared_ScriptToEnvironment { edges = append(edges, script.EdgeScriptToEnvironment) } + if m.cleared_ScriptToValidation { + edges = append(edges, script.EdgeScriptToValidation) + } return edges } @@ -25661,6 +25773,8 @@ func (m *ScriptMutation) EdgeCleared(name string) bool { return m.cleared_ScriptToFinding case script.EdgeScriptToEnvironment: return m.cleared_ScriptToEnvironment + case script.EdgeScriptToValidation: + return m.cleared_ScriptToValidation } return false } @@ -25672,6 +25786,9 @@ func (m *ScriptMutation) ClearEdge(name string) error { case script.EdgeScriptToEnvironment: m.ClearScriptToEnvironment() return nil + case script.EdgeScriptToValidation: + m.ClearScriptToValidation() + return nil } return fmt.Errorf("unknown Script unique edge %s", name) } @@ -25689,6 +25806,9 @@ func (m *ScriptMutation) ResetEdge(name string) error { case script.EdgeScriptToEnvironment: m.ResetScriptToEnvironment() return nil + case script.EdgeScriptToValidation: + m.ResetScriptToValidation() + return nil } return fmt.Errorf("unknown Script edge %s", name) } @@ -29935,3 +30055,1299 @@ func (m *UserMutation) ResetEdge(name string) error { } return fmt.Errorf("unknown User edge %s", name) } + +// ValidationMutation represents an operation that mutates the Validation nodes in the graph. +type ValidationMutation struct { + config + op Op + typ string + id *uuid.UUID + hcl_id *string + validation_type *string + output *string + state *validation.State + error_message *string + regex *string + ip *string + port *int + addport *int + hostname *string + nameservers *[]string + package_name *string + username *string + group_name *string + field_path *string + service_name *string + process_name *string + clearedFields map[string]struct{} + _ValidationToAgentTask *uuid.UUID + cleared_ValidationToAgentTask bool + _ValidationToScript map[uuid.UUID]struct{} + removed_ValidationToScript map[uuid.UUID]struct{} + cleared_ValidationToScript bool + done bool + oldValue func(context.Context) (*Validation, error) + predicates []predicate.Validation +} + +var _ ent.Mutation = (*ValidationMutation)(nil) + +// validationOption allows management of the mutation configuration using functional options. +type validationOption func(*ValidationMutation) + +// newValidationMutation creates new mutation for the Validation entity. +func newValidationMutation(c config, op Op, opts ...validationOption) *ValidationMutation { + m := &ValidationMutation{ + config: c, + op: op, + typ: TypeValidation, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withValidationID sets the ID field of the mutation. +func withValidationID(id uuid.UUID) validationOption { + return func(m *ValidationMutation) { + var ( + err error + once sync.Once + value *Validation + ) + m.oldValue = func(ctx context.Context) (*Validation, error) { + once.Do(func() { + if m.done { + err = fmt.Errorf("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Validation.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withValidation sets the old Validation of the mutation. +func withValidation(node *Validation) validationOption { + return func(m *ValidationMutation) { + m.oldValue = func(context.Context) (*Validation, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m ValidationMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ValidationMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, fmt.Errorf("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Validation entities. +func (m *ValidationMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *ValidationMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// SetHclID sets the "hcl_id" field. +func (m *ValidationMutation) SetHclID(s string) { + m.hcl_id = &s +} + +// HclID returns the value of the "hcl_id" field in the mutation. +func (m *ValidationMutation) HclID() (r string, exists bool) { + v := m.hcl_id + if v == nil { + return + } + return *v, true +} + +// OldHclID returns the old "hcl_id" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldHclID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldHclID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldHclID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldHclID: %w", err) + } + return oldValue.HclID, nil +} + +// ResetHclID resets all changes to the "hcl_id" field. +func (m *ValidationMutation) ResetHclID() { + m.hcl_id = nil +} + +// SetValidationType sets the "validation_type" field. +func (m *ValidationMutation) SetValidationType(s string) { + m.validation_type = &s +} + +// ValidationType returns the value of the "validation_type" field in the mutation. +func (m *ValidationMutation) ValidationType() (r string, exists bool) { + v := m.validation_type + if v == nil { + return + } + return *v, true +} + +// OldValidationType returns the old "validation_type" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldValidationType(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldValidationType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldValidationType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldValidationType: %w", err) + } + return oldValue.ValidationType, nil +} + +// ResetValidationType resets all changes to the "validation_type" field. +func (m *ValidationMutation) ResetValidationType() { + m.validation_type = nil +} + +// SetOutput sets the "output" field. +func (m *ValidationMutation) SetOutput(s string) { + m.output = &s +} + +// Output returns the value of the "output" field in the mutation. +func (m *ValidationMutation) Output() (r string, exists bool) { + v := m.output + if v == nil { + return + } + return *v, true +} + +// OldOutput returns the old "output" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldOutput(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldOutput is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldOutput requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldOutput: %w", err) + } + return oldValue.Output, nil +} + +// ResetOutput resets all changes to the "output" field. +func (m *ValidationMutation) ResetOutput() { + m.output = nil +} + +// SetState sets the "state" field. +func (m *ValidationMutation) SetState(v validation.State) { + m.state = &v +} + +// State returns the value of the "state" field in the mutation. +func (m *ValidationMutation) State() (r validation.State, exists bool) { + v := m.state + if v == nil { + return + } + return *v, true +} + +// OldState returns the old "state" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldState(ctx context.Context) (v validation.State, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldState is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldState requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldState: %w", err) + } + return oldValue.State, nil +} + +// ResetState resets all changes to the "state" field. +func (m *ValidationMutation) ResetState() { + m.state = nil +} + +// SetErrorMessage sets the "error_message" field. +func (m *ValidationMutation) SetErrorMessage(s string) { + m.error_message = &s +} + +// ErrorMessage returns the value of the "error_message" field in the mutation. +func (m *ValidationMutation) ErrorMessage() (r string, exists bool) { + v := m.error_message + if v == nil { + return + } + return *v, true +} + +// OldErrorMessage returns the old "error_message" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldErrorMessage(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldErrorMessage is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldErrorMessage requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldErrorMessage: %w", err) + } + return oldValue.ErrorMessage, nil +} + +// ResetErrorMessage resets all changes to the "error_message" field. +func (m *ValidationMutation) ResetErrorMessage() { + m.error_message = nil +} + +// SetRegex sets the "regex" field. +func (m *ValidationMutation) SetRegex(s string) { + m.regex = &s +} + +// Regex returns the value of the "regex" field in the mutation. +func (m *ValidationMutation) Regex() (r string, exists bool) { + v := m.regex + if v == nil { + return + } + return *v, true +} + +// OldRegex returns the old "regex" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldRegex(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldRegex is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldRegex requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRegex: %w", err) + } + return oldValue.Regex, nil +} + +// ResetRegex resets all changes to the "regex" field. +func (m *ValidationMutation) ResetRegex() { + m.regex = nil +} + +// SetIP sets the "ip" field. +func (m *ValidationMutation) SetIP(s string) { + m.ip = &s +} + +// IP returns the value of the "ip" field in the mutation. +func (m *ValidationMutation) IP() (r string, exists bool) { + v := m.ip + if v == nil { + return + } + return *v, true +} + +// OldIP returns the old "ip" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldIP(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldIP is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldIP requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIP: %w", err) + } + return oldValue.IP, nil +} + +// ResetIP resets all changes to the "ip" field. +func (m *ValidationMutation) ResetIP() { + m.ip = nil +} + +// SetPort sets the "port" field. +func (m *ValidationMutation) SetPort(i int) { + m.port = &i + m.addport = nil +} + +// Port returns the value of the "port" field in the mutation. +func (m *ValidationMutation) Port() (r int, exists bool) { + v := m.port + if v == nil { + return + } + return *v, true +} + +// OldPort returns the old "port" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldPort(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldPort is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldPort requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPort: %w", err) + } + return oldValue.Port, nil +} + +// AddPort adds i to the "port" field. +func (m *ValidationMutation) AddPort(i int) { + if m.addport != nil { + *m.addport += i + } else { + m.addport = &i + } +} + +// AddedPort returns the value that was added to the "port" field in this mutation. +func (m *ValidationMutation) AddedPort() (r int, exists bool) { + v := m.addport + if v == nil { + return + } + return *v, true +} + +// ResetPort resets all changes to the "port" field. +func (m *ValidationMutation) ResetPort() { + m.port = nil + m.addport = nil +} + +// SetHostname sets the "hostname" field. +func (m *ValidationMutation) SetHostname(s string) { + m.hostname = &s +} + +// Hostname returns the value of the "hostname" field in the mutation. +func (m *ValidationMutation) Hostname() (r string, exists bool) { + v := m.hostname + if v == nil { + return + } + return *v, true +} + +// OldHostname returns the old "hostname" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldHostname(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldHostname is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldHostname requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldHostname: %w", err) + } + return oldValue.Hostname, nil +} + +// ResetHostname resets all changes to the "hostname" field. +func (m *ValidationMutation) ResetHostname() { + m.hostname = nil +} + +// SetNameservers sets the "nameservers" field. +func (m *ValidationMutation) SetNameservers(s []string) { + m.nameservers = &s +} + +// Nameservers returns the value of the "nameservers" field in the mutation. +func (m *ValidationMutation) Nameservers() (r []string, exists bool) { + v := m.nameservers + if v == nil { + return + } + return *v, true +} + +// OldNameservers returns the old "nameservers" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldNameservers(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldNameservers is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldNameservers requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNameservers: %w", err) + } + return oldValue.Nameservers, nil +} + +// ResetNameservers resets all changes to the "nameservers" field. +func (m *ValidationMutation) ResetNameservers() { + m.nameservers = nil +} + +// SetPackageName sets the "package_name" field. +func (m *ValidationMutation) SetPackageName(s string) { + m.package_name = &s +} + +// PackageName returns the value of the "package_name" field in the mutation. +func (m *ValidationMutation) PackageName() (r string, exists bool) { + v := m.package_name + if v == nil { + return + } + return *v, true +} + +// OldPackageName returns the old "package_name" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldPackageName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldPackageName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldPackageName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPackageName: %w", err) + } + return oldValue.PackageName, nil +} + +// ResetPackageName resets all changes to the "package_name" field. +func (m *ValidationMutation) ResetPackageName() { + m.package_name = nil +} + +// SetUsername sets the "username" field. +func (m *ValidationMutation) SetUsername(s string) { + m.username = &s +} + +// Username returns the value of the "username" field in the mutation. +func (m *ValidationMutation) Username() (r string, exists bool) { + v := m.username + if v == nil { + return + } + return *v, true +} + +// OldUsername returns the old "username" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldUsername(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldUsername is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldUsername requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUsername: %w", err) + } + return oldValue.Username, nil +} + +// ResetUsername resets all changes to the "username" field. +func (m *ValidationMutation) ResetUsername() { + m.username = nil +} + +// SetGroupName sets the "group_name" field. +func (m *ValidationMutation) SetGroupName(s string) { + m.group_name = &s +} + +// GroupName returns the value of the "group_name" field in the mutation. +func (m *ValidationMutation) GroupName() (r string, exists bool) { + v := m.group_name + if v == nil { + return + } + return *v, true +} + +// OldGroupName returns the old "group_name" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldGroupName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldGroupName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldGroupName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldGroupName: %w", err) + } + return oldValue.GroupName, nil +} + +// ResetGroupName resets all changes to the "group_name" field. +func (m *ValidationMutation) ResetGroupName() { + m.group_name = nil +} + +// SetFieldPath sets the "field_path" field. +func (m *ValidationMutation) SetFieldPath(s string) { + m.field_path = &s +} + +// FieldPath returns the value of the "field_path" field in the mutation. +func (m *ValidationMutation) FieldPath() (r string, exists bool) { + v := m.field_path + if v == nil { + return + } + return *v, true +} + +// OldFieldPath returns the old "field_path" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldFieldPath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldFieldPath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldFieldPath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFieldPath: %w", err) + } + return oldValue.FieldPath, nil +} + +// ResetFieldPath resets all changes to the "field_path" field. +func (m *ValidationMutation) ResetFieldPath() { + m.field_path = nil +} + +// SetServiceName sets the "service_name" field. +func (m *ValidationMutation) SetServiceName(s string) { + m.service_name = &s +} + +// ServiceName returns the value of the "service_name" field in the mutation. +func (m *ValidationMutation) ServiceName() (r string, exists bool) { + v := m.service_name + if v == nil { + return + } + return *v, true +} + +// OldServiceName returns the old "service_name" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldServiceName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldServiceName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldServiceName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServiceName: %w", err) + } + return oldValue.ServiceName, nil +} + +// ResetServiceName resets all changes to the "service_name" field. +func (m *ValidationMutation) ResetServiceName() { + m.service_name = nil +} + +// SetProcessName sets the "process_name" field. +func (m *ValidationMutation) SetProcessName(s string) { + m.process_name = &s +} + +// ProcessName returns the value of the "process_name" field in the mutation. +func (m *ValidationMutation) ProcessName() (r string, exists bool) { + v := m.process_name + if v == nil { + return + } + return *v, true +} + +// OldProcessName returns the old "process_name" field's value of the Validation entity. +// If the Validation object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ValidationMutation) OldProcessName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldProcessName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldProcessName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldProcessName: %w", err) + } + return oldValue.ProcessName, nil +} + +// ResetProcessName resets all changes to the "process_name" field. +func (m *ValidationMutation) ResetProcessName() { + m.process_name = nil +} + +// SetValidationToAgentTaskID sets the "ValidationToAgentTask" edge to the AgentTask entity by id. +func (m *ValidationMutation) SetValidationToAgentTaskID(id uuid.UUID) { + m._ValidationToAgentTask = &id +} + +// ClearValidationToAgentTask clears the "ValidationToAgentTask" edge to the AgentTask entity. +func (m *ValidationMutation) ClearValidationToAgentTask() { + m.cleared_ValidationToAgentTask = true +} + +// ValidationToAgentTaskCleared reports if the "ValidationToAgentTask" edge to the AgentTask entity was cleared. +func (m *ValidationMutation) ValidationToAgentTaskCleared() bool { + return m.cleared_ValidationToAgentTask +} + +// ValidationToAgentTaskID returns the "ValidationToAgentTask" edge ID in the mutation. +func (m *ValidationMutation) ValidationToAgentTaskID() (id uuid.UUID, exists bool) { + if m._ValidationToAgentTask != nil { + return *m._ValidationToAgentTask, true + } + return +} + +// ValidationToAgentTaskIDs returns the "ValidationToAgentTask" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ValidationToAgentTaskID instead. It exists only for internal usage by the builders. +func (m *ValidationMutation) ValidationToAgentTaskIDs() (ids []uuid.UUID) { + if id := m._ValidationToAgentTask; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetValidationToAgentTask resets all changes to the "ValidationToAgentTask" edge. +func (m *ValidationMutation) ResetValidationToAgentTask() { + m._ValidationToAgentTask = nil + m.cleared_ValidationToAgentTask = false +} + +// AddValidationToScriptIDs adds the "ValidationToScript" edge to the Script entity by ids. +func (m *ValidationMutation) AddValidationToScriptIDs(ids ...uuid.UUID) { + if m._ValidationToScript == nil { + m._ValidationToScript = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m._ValidationToScript[ids[i]] = struct{}{} + } +} + +// ClearValidationToScript clears the "ValidationToScript" edge to the Script entity. +func (m *ValidationMutation) ClearValidationToScript() { + m.cleared_ValidationToScript = true +} + +// ValidationToScriptCleared reports if the "ValidationToScript" edge to the Script entity was cleared. +func (m *ValidationMutation) ValidationToScriptCleared() bool { + return m.cleared_ValidationToScript +} + +// RemoveValidationToScriptIDs removes the "ValidationToScript" edge to the Script entity by IDs. +func (m *ValidationMutation) RemoveValidationToScriptIDs(ids ...uuid.UUID) { + if m.removed_ValidationToScript == nil { + m.removed_ValidationToScript = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m._ValidationToScript, ids[i]) + m.removed_ValidationToScript[ids[i]] = struct{}{} + } +} + +// RemovedValidationToScript returns the removed IDs of the "ValidationToScript" edge to the Script entity. +func (m *ValidationMutation) RemovedValidationToScriptIDs() (ids []uuid.UUID) { + for id := range m.removed_ValidationToScript { + ids = append(ids, id) + } + return +} + +// ValidationToScriptIDs returns the "ValidationToScript" edge IDs in the mutation. +func (m *ValidationMutation) ValidationToScriptIDs() (ids []uuid.UUID) { + for id := range m._ValidationToScript { + ids = append(ids, id) + } + return +} + +// ResetValidationToScript resets all changes to the "ValidationToScript" edge. +func (m *ValidationMutation) ResetValidationToScript() { + m._ValidationToScript = nil + m.cleared_ValidationToScript = false + m.removed_ValidationToScript = nil +} + +// Where appends a list predicates to the ValidationMutation builder. +func (m *ValidationMutation) Where(ps ...predicate.Validation) { + m.predicates = append(m.predicates, ps...) +} + +// Op returns the operation name. +func (m *ValidationMutation) Op() Op { + return m.op +} + +// Type returns the node type of this mutation (Validation). +func (m *ValidationMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *ValidationMutation) Fields() []string { + fields := make([]string, 0, 16) + if m.hcl_id != nil { + fields = append(fields, validation.FieldHclID) + } + if m.validation_type != nil { + fields = append(fields, validation.FieldValidationType) + } + if m.output != nil { + fields = append(fields, validation.FieldOutput) + } + if m.state != nil { + fields = append(fields, validation.FieldState) + } + if m.error_message != nil { + fields = append(fields, validation.FieldErrorMessage) + } + if m.regex != nil { + fields = append(fields, validation.FieldRegex) + } + if m.ip != nil { + fields = append(fields, validation.FieldIP) + } + if m.port != nil { + fields = append(fields, validation.FieldPort) + } + if m.hostname != nil { + fields = append(fields, validation.FieldHostname) + } + if m.nameservers != nil { + fields = append(fields, validation.FieldNameservers) + } + if m.package_name != nil { + fields = append(fields, validation.FieldPackageName) + } + if m.username != nil { + fields = append(fields, validation.FieldUsername) + } + if m.group_name != nil { + fields = append(fields, validation.FieldGroupName) + } + if m.field_path != nil { + fields = append(fields, validation.FieldFieldPath) + } + if m.service_name != nil { + fields = append(fields, validation.FieldServiceName) + } + if m.process_name != nil { + fields = append(fields, validation.FieldProcessName) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *ValidationMutation) Field(name string) (ent.Value, bool) { + switch name { + case validation.FieldHclID: + return m.HclID() + case validation.FieldValidationType: + return m.ValidationType() + case validation.FieldOutput: + return m.Output() + case validation.FieldState: + return m.State() + case validation.FieldErrorMessage: + return m.ErrorMessage() + case validation.FieldRegex: + return m.Regex() + case validation.FieldIP: + return m.IP() + case validation.FieldPort: + return m.Port() + case validation.FieldHostname: + return m.Hostname() + case validation.FieldNameservers: + return m.Nameservers() + case validation.FieldPackageName: + return m.PackageName() + case validation.FieldUsername: + return m.Username() + case validation.FieldGroupName: + return m.GroupName() + case validation.FieldFieldPath: + return m.FieldPath() + case validation.FieldServiceName: + return m.ServiceName() + case validation.FieldProcessName: + return m.ProcessName() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *ValidationMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case validation.FieldHclID: + return m.OldHclID(ctx) + case validation.FieldValidationType: + return m.OldValidationType(ctx) + case validation.FieldOutput: + return m.OldOutput(ctx) + case validation.FieldState: + return m.OldState(ctx) + case validation.FieldErrorMessage: + return m.OldErrorMessage(ctx) + case validation.FieldRegex: + return m.OldRegex(ctx) + case validation.FieldIP: + return m.OldIP(ctx) + case validation.FieldPort: + return m.OldPort(ctx) + case validation.FieldHostname: + return m.OldHostname(ctx) + case validation.FieldNameservers: + return m.OldNameservers(ctx) + case validation.FieldPackageName: + return m.OldPackageName(ctx) + case validation.FieldUsername: + return m.OldUsername(ctx) + case validation.FieldGroupName: + return m.OldGroupName(ctx) + case validation.FieldFieldPath: + return m.OldFieldPath(ctx) + case validation.FieldServiceName: + return m.OldServiceName(ctx) + case validation.FieldProcessName: + return m.OldProcessName(ctx) + } + return nil, fmt.Errorf("unknown Validation field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ValidationMutation) SetField(name string, value ent.Value) error { + switch name { + case validation.FieldHclID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetHclID(v) + return nil + case validation.FieldValidationType: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetValidationType(v) + return nil + case validation.FieldOutput: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetOutput(v) + return nil + case validation.FieldState: + v, ok := value.(validation.State) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetState(v) + return nil + case validation.FieldErrorMessage: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetErrorMessage(v) + return nil + case validation.FieldRegex: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRegex(v) + return nil + case validation.FieldIP: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIP(v) + return nil + case validation.FieldPort: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPort(v) + return nil + case validation.FieldHostname: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetHostname(v) + return nil + case validation.FieldNameservers: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNameservers(v) + return nil + case validation.FieldPackageName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPackageName(v) + return nil + case validation.FieldUsername: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUsername(v) + return nil + case validation.FieldGroupName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetGroupName(v) + return nil + case validation.FieldFieldPath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFieldPath(v) + return nil + case validation.FieldServiceName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServiceName(v) + return nil + case validation.FieldProcessName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetProcessName(v) + return nil + } + return fmt.Errorf("unknown Validation field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ValidationMutation) AddedFields() []string { + var fields []string + if m.addport != nil { + fields = append(fields, validation.FieldPort) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *ValidationMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case validation.FieldPort: + return m.AddedPort() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ValidationMutation) AddField(name string, value ent.Value) error { + switch name { + case validation.FieldPort: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddPort(v) + return nil + } + return fmt.Errorf("unknown Validation numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ValidationMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ValidationMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *ValidationMutation) ClearField(name string) error { + return fmt.Errorf("unknown Validation nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *ValidationMutation) ResetField(name string) error { + switch name { + case validation.FieldHclID: + m.ResetHclID() + return nil + case validation.FieldValidationType: + m.ResetValidationType() + return nil + case validation.FieldOutput: + m.ResetOutput() + return nil + case validation.FieldState: + m.ResetState() + return nil + case validation.FieldErrorMessage: + m.ResetErrorMessage() + return nil + case validation.FieldRegex: + m.ResetRegex() + return nil + case validation.FieldIP: + m.ResetIP() + return nil + case validation.FieldPort: + m.ResetPort() + return nil + case validation.FieldHostname: + m.ResetHostname() + return nil + case validation.FieldNameservers: + m.ResetNameservers() + return nil + case validation.FieldPackageName: + m.ResetPackageName() + return nil + case validation.FieldUsername: + m.ResetUsername() + return nil + case validation.FieldGroupName: + m.ResetGroupName() + return nil + case validation.FieldFieldPath: + m.ResetFieldPath() + return nil + case validation.FieldServiceName: + m.ResetServiceName() + return nil + case validation.FieldProcessName: + m.ResetProcessName() + return nil + } + return fmt.Errorf("unknown Validation field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ValidationMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m._ValidationToAgentTask != nil { + edges = append(edges, validation.EdgeValidationToAgentTask) + } + if m._ValidationToScript != nil { + edges = append(edges, validation.EdgeValidationToScript) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ValidationMutation) AddedIDs(name string) []ent.Value { + switch name { + case validation.EdgeValidationToAgentTask: + if id := m._ValidationToAgentTask; id != nil { + return []ent.Value{*id} + } + case validation.EdgeValidationToScript: + ids := make([]ent.Value, 0, len(m._ValidationToScript)) + for id := range m._ValidationToScript { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ValidationMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + if m.removed_ValidationToScript != nil { + edges = append(edges, validation.EdgeValidationToScript) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ValidationMutation) RemovedIDs(name string) []ent.Value { + switch name { + case validation.EdgeValidationToScript: + ids := make([]ent.Value, 0, len(m.removed_ValidationToScript)) + for id := range m.removed_ValidationToScript { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ValidationMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.cleared_ValidationToAgentTask { + edges = append(edges, validation.EdgeValidationToAgentTask) + } + if m.cleared_ValidationToScript { + edges = append(edges, validation.EdgeValidationToScript) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ValidationMutation) EdgeCleared(name string) bool { + switch name { + case validation.EdgeValidationToAgentTask: + return m.cleared_ValidationToAgentTask + case validation.EdgeValidationToScript: + return m.cleared_ValidationToScript + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *ValidationMutation) ClearEdge(name string) error { + switch name { + case validation.EdgeValidationToAgentTask: + m.ClearValidationToAgentTask() + return nil + } + return fmt.Errorf("unknown Validation unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *ValidationMutation) ResetEdge(name string) error { + switch name { + case validation.EdgeValidationToAgentTask: + m.ResetValidationToAgentTask() + return nil + case validation.EdgeValidationToScript: + m.ResetValidationToScript() + return nil + } + return fmt.Errorf("unknown Validation edge %s", name) +} diff --git a/ent/node.go b/ent/node.go index abbed233..2030a487 100755 --- a/ent/node.go +++ b/ent/node.go @@ -44,6 +44,7 @@ import ( "github.com/gen0cide/laforge/ent/team" "github.com/gen0cide/laforge/ent/token" "github.com/gen0cide/laforge/ent/user" + "github.com/gen0cide/laforge/ent/validation" "github.com/google/uuid" "github.com/hashicorp/go-multierror" ) @@ -293,7 +294,7 @@ func (at *AgentTask) Node(ctx context.Context) (node *Node, err error) { ID: at.ID, Type: "AgentTask", Fields: make([]*Field, 6), - Edges: make([]*Edge, 3), + Edges: make([]*Edge, 4), } var buf []byte if buf, err = json.Marshal(at.Command); err != nil { @@ -374,6 +375,16 @@ func (at *AgentTask) Node(ctx context.Context) (node *Node, err error) { if err != nil { return nil, err } + node.Edges[3] = &Edge{ + Type: "Validation", + Name: "AgentTaskToValidation", + } + err = at.QueryAgentTaskToValidation(). + Select(validation.FieldID). + Scan(ctx, &node.Edges[3].IDs) + if err != nil { + return nil, err + } return node, nil } @@ -2771,7 +2782,7 @@ func (s *Script) Node(ctx context.Context) (node *Node, err error) { ID: s.ID, Type: "Script", Fields: make([]*Field, 14), - Edges: make([]*Edge, 3), + Edges: make([]*Edge, 4), } var buf []byte if buf, err = json.Marshal(s.HclID); err != nil { @@ -2916,6 +2927,16 @@ func (s *Script) Node(ctx context.Context) (node *Node, err error) { if err != nil { return nil, err } + node.Edges[3] = &Edge{ + Type: "Validation", + Name: "ScriptToValidation", + } + err = s.QueryScriptToValidation(). + Select(validation.FieldID). + Scan(ctx, &node.Edges[3].IDs) + if err != nil { + return nil, err + } return node, nil } @@ -3369,6 +3390,165 @@ func (u *User) Node(ctx context.Context) (node *Node, err error) { return node, nil } +func (v *Validation) Node(ctx context.Context) (node *Node, err error) { + node = &Node{ + ID: v.ID, + Type: "Validation", + Fields: make([]*Field, 16), + Edges: make([]*Edge, 2), + } + var buf []byte + if buf, err = json.Marshal(v.HclID); err != nil { + return nil, err + } + node.Fields[0] = &Field{ + Type: "string", + Name: "hcl_id", + Value: string(buf), + } + if buf, err = json.Marshal(v.ValidationType); err != nil { + return nil, err + } + node.Fields[1] = &Field{ + Type: "string", + Name: "validation_type", + Value: string(buf), + } + if buf, err = json.Marshal(v.Output); err != nil { + return nil, err + } + node.Fields[2] = &Field{ + Type: "string", + Name: "output", + Value: string(buf), + } + if buf, err = json.Marshal(v.State); err != nil { + return nil, err + } + node.Fields[3] = &Field{ + Type: "validation.State", + Name: "state", + Value: string(buf), + } + if buf, err = json.Marshal(v.ErrorMessage); err != nil { + return nil, err + } + node.Fields[4] = &Field{ + Type: "string", + Name: "error_message", + Value: string(buf), + } + if buf, err = json.Marshal(v.Regex); err != nil { + return nil, err + } + node.Fields[5] = &Field{ + Type: "string", + Name: "regex", + Value: string(buf), + } + if buf, err = json.Marshal(v.IP); err != nil { + return nil, err + } + node.Fields[6] = &Field{ + Type: "string", + Name: "ip", + Value: string(buf), + } + if buf, err = json.Marshal(v.Port); err != nil { + return nil, err + } + node.Fields[7] = &Field{ + Type: "int", + Name: "port", + Value: string(buf), + } + if buf, err = json.Marshal(v.Hostname); err != nil { + return nil, err + } + node.Fields[8] = &Field{ + Type: "string", + Name: "hostname", + Value: string(buf), + } + if buf, err = json.Marshal(v.Nameservers); err != nil { + return nil, err + } + node.Fields[9] = &Field{ + Type: "[]string", + Name: "nameservers", + Value: string(buf), + } + if buf, err = json.Marshal(v.PackageName); err != nil { + return nil, err + } + node.Fields[10] = &Field{ + Type: "string", + Name: "package_name", + Value: string(buf), + } + if buf, err = json.Marshal(v.Username); err != nil { + return nil, err + } + node.Fields[11] = &Field{ + Type: "string", + Name: "username", + Value: string(buf), + } + if buf, err = json.Marshal(v.GroupName); err != nil { + return nil, err + } + node.Fields[12] = &Field{ + Type: "string", + Name: "group_name", + Value: string(buf), + } + if buf, err = json.Marshal(v.FieldPath); err != nil { + return nil, err + } + node.Fields[13] = &Field{ + Type: "string", + Name: "field_path", + Value: string(buf), + } + if buf, err = json.Marshal(v.ServiceName); err != nil { + return nil, err + } + node.Fields[14] = &Field{ + Type: "string", + Name: "service_name", + Value: string(buf), + } + if buf, err = json.Marshal(v.ProcessName); err != nil { + return nil, err + } + node.Fields[15] = &Field{ + Type: "string", + Name: "process_name", + Value: string(buf), + } + node.Edges[0] = &Edge{ + Type: "AgentTask", + Name: "ValidationToAgentTask", + } + err = v.QueryValidationToAgentTask(). + Select(agenttask.FieldID). + Scan(ctx, &node.Edges[0].IDs) + if err != nil { + return nil, err + } + node.Edges[1] = &Edge{ + Type: "Script", + Name: "ValidationToScript", + } + err = v.QueryValidationToScript(). + Select(script.FieldID). + Scan(ctx, &node.Edges[1].IDs) + if err != nil { + return nil, err + } + return node, nil +} + func (c *Client) Node(ctx context.Context, id uuid.UUID) (*Node, error) { n, err := c.Noder(ctx, id) if err != nil { @@ -3751,6 +3931,15 @@ func (c *Client) noder(ctx context.Context, table string, id uuid.UUID) (Noder, return nil, err } return n, nil + case validation.Table: + n, err := c.Validation.Query(). + Where(validation.ID(id)). + CollectFields(ctx, "Validation"). + Only(ctx) + if err != nil { + return nil, err + } + return n, nil default: return nil, fmt.Errorf("cannot resolve noder from table %q: %w", table, errNodeInvalidID) } @@ -4279,6 +4468,19 @@ func (c *Client) noders(ctx context.Context, table string, ids []uuid.UUID) ([]N *noder = node } } + case validation.Table: + nodes, err := c.Validation.Query(). + Where(validation.IDIn(ids...)). + CollectFields(ctx, "Validation"). + All(ctx) + if err != nil { + return nil, err + } + for _, node := range nodes { + for _, noder := range idmap[node.ID] { + *noder = node + } + } default: return nil, fmt.Errorf("cannot resolve noders from table %q: %w", table, errNodeInvalidID) } diff --git a/ent/pagination.go b/ent/pagination.go index 4d3d62e7..939ef25a 100755 --- a/ent/pagination.go +++ b/ent/pagination.go @@ -49,6 +49,7 @@ import ( "github.com/gen0cide/laforge/ent/team" "github.com/gen0cide/laforge/ent/token" "github.com/gen0cide/laforge/ent/user" + "github.com/gen0cide/laforge/ent/validation" "github.com/google/uuid" "github.com/vektah/gqlparser/v2/gqlerror" "github.com/vmihailenco/msgpack/v5" @@ -8211,3 +8212,230 @@ func (u *User) ToEdge(order *UserOrder) *UserEdge { Cursor: order.Field.toCursor(u), } } + +// ValidationEdge is the edge representation of Validation. +type ValidationEdge struct { + Node *Validation `json:"node"` + Cursor Cursor `json:"cursor"` +} + +// ValidationConnection is the connection containing edges to Validation. +type ValidationConnection struct { + Edges []*ValidationEdge `json:"edges"` + PageInfo PageInfo `json:"pageInfo"` + TotalCount int `json:"totalCount"` +} + +// ValidationPaginateOption enables pagination customization. +type ValidationPaginateOption func(*validationPager) error + +// WithValidationOrder configures pagination ordering. +func WithValidationOrder(order *ValidationOrder) ValidationPaginateOption { + if order == nil { + order = DefaultValidationOrder + } + o := *order + return func(pager *validationPager) error { + if err := o.Direction.Validate(); err != nil { + return err + } + if o.Field == nil { + o.Field = DefaultValidationOrder.Field + } + pager.order = &o + return nil + } +} + +// WithValidationFilter configures pagination filter. +func WithValidationFilter(filter func(*ValidationQuery) (*ValidationQuery, error)) ValidationPaginateOption { + return func(pager *validationPager) error { + if filter == nil { + return errors.New("ValidationQuery filter cannot be nil") + } + pager.filter = filter + return nil + } +} + +type validationPager struct { + order *ValidationOrder + filter func(*ValidationQuery) (*ValidationQuery, error) +} + +func newValidationPager(opts []ValidationPaginateOption) (*validationPager, error) { + pager := &validationPager{} + for _, opt := range opts { + if err := opt(pager); err != nil { + return nil, err + } + } + if pager.order == nil { + pager.order = DefaultValidationOrder + } + return pager, nil +} + +func (p *validationPager) applyFilter(query *ValidationQuery) (*ValidationQuery, error) { + if p.filter != nil { + return p.filter(query) + } + return query, nil +} + +func (p *validationPager) toCursor(v *Validation) Cursor { + return p.order.Field.toCursor(v) +} + +func (p *validationPager) applyCursors(query *ValidationQuery, after, before *Cursor) *ValidationQuery { + for _, predicate := range cursorsToPredicates( + p.order.Direction, after, before, + p.order.Field.field, DefaultValidationOrder.Field.field, + ) { + query = query.Where(predicate) + } + return query +} + +func (p *validationPager) applyOrder(query *ValidationQuery, reverse bool) *ValidationQuery { + direction := p.order.Direction + if reverse { + direction = direction.reverse() + } + query = query.Order(direction.orderFunc(p.order.Field.field)) + if p.order.Field != DefaultValidationOrder.Field { + query = query.Order(direction.orderFunc(DefaultValidationOrder.Field.field)) + } + return query +} + +// Paginate executes the query and returns a relay based cursor connection to Validation. +func (v *ValidationQuery) Paginate( + ctx context.Context, after *Cursor, first *int, + before *Cursor, last *int, opts ...ValidationPaginateOption, +) (*ValidationConnection, error) { + if err := validateFirstLast(first, last); err != nil { + return nil, err + } + pager, err := newValidationPager(opts) + if err != nil { + return nil, err + } + + if v, err = pager.applyFilter(v); err != nil { + return nil, err + } + + conn := &ValidationConnection{Edges: []*ValidationEdge{}} + if !hasCollectedField(ctx, edgesField) || first != nil && *first == 0 || last != nil && *last == 0 { + if hasCollectedField(ctx, totalCountField) || + hasCollectedField(ctx, pageInfoField) { + count, err := v.Count(ctx) + if err != nil { + return nil, err + } + conn.TotalCount = count + conn.PageInfo.HasNextPage = first != nil && count > 0 + conn.PageInfo.HasPreviousPage = last != nil && count > 0 + } + return conn, nil + } + + if (after != nil || first != nil || before != nil || last != nil) && hasCollectedField(ctx, totalCountField) { + count, err := v.Clone().Count(ctx) + if err != nil { + return nil, err + } + conn.TotalCount = count + } + + v = pager.applyCursors(v, after, before) + v = pager.applyOrder(v, last != nil) + var limit int + if first != nil { + limit = *first + 1 + } else if last != nil { + limit = *last + 1 + } + if limit > 0 { + v = v.Limit(limit) + } + + if field := getCollectedField(ctx, edgesField, nodeField); field != nil { + v = v.collectField(graphql.GetOperationContext(ctx), *field) + } + + nodes, err := v.All(ctx) + if err != nil || len(nodes) == 0 { + return conn, err + } + + if len(nodes) == limit { + conn.PageInfo.HasNextPage = first != nil + conn.PageInfo.HasPreviousPage = last != nil + nodes = nodes[:len(nodes)-1] + } + + var nodeAt func(int) *Validation + if last != nil { + n := len(nodes) - 1 + nodeAt = func(i int) *Validation { + return nodes[n-i] + } + } else { + nodeAt = func(i int) *Validation { + return nodes[i] + } + } + + conn.Edges = make([]*ValidationEdge, len(nodes)) + for i := range nodes { + node := nodeAt(i) + conn.Edges[i] = &ValidationEdge{ + Node: node, + Cursor: pager.toCursor(node), + } + } + + conn.PageInfo.StartCursor = &conn.Edges[0].Cursor + conn.PageInfo.EndCursor = &conn.Edges[len(conn.Edges)-1].Cursor + if conn.TotalCount == 0 { + conn.TotalCount = len(nodes) + } + + return conn, nil +} + +// ValidationOrderField defines the ordering field of Validation. +type ValidationOrderField struct { + field string + toCursor func(*Validation) Cursor +} + +// ValidationOrder defines the ordering of Validation. +type ValidationOrder struct { + Direction OrderDirection `json:"direction"` + Field *ValidationOrderField `json:"field"` +} + +// DefaultValidationOrder is the default ordering of Validation. +var DefaultValidationOrder = &ValidationOrder{ + Direction: OrderDirectionAsc, + Field: &ValidationOrderField{ + field: validation.FieldID, + toCursor: func(v *Validation) Cursor { + return Cursor{ID: v.ID} + }, + }, +} + +// ToEdge converts Validation into ValidationEdge. +func (v *Validation) ToEdge(order *ValidationOrder) *ValidationEdge { + if order == nil { + order = DefaultValidationOrder + } + return &ValidationEdge{ + Node: v, + Cursor: order.Field.toCursor(v), + } +} diff --git a/ent/predicate/predicate.go b/ent/predicate/predicate.go index aa8ea9a6..911cd856 100755 --- a/ent/predicate/predicate.go +++ b/ent/predicate/predicate.go @@ -110,3 +110,6 @@ type Token func(*sql.Selector) // User is the predicate function for user builders. type User func(*sql.Selector) + +// Validation is the predicate function for validation builders. +type Validation func(*sql.Selector) diff --git a/ent/provisioningstep/provisioningstep.go b/ent/provisioningstep/provisioningstep.go index a4e3896d..c704a1b3 100755 --- a/ent/provisioningstep/provisioningstep.go +++ b/ent/provisioningstep/provisioningstep.go @@ -174,6 +174,7 @@ const ( TypeFileDelete Type = "FileDelete" TypeFileDownload Type = "FileDownload" TypeFileExtract Type = "FileExtract" + TypeValidate Type = "Validate" ) func (_type Type) String() string { @@ -183,7 +184,7 @@ func (_type Type) String() string { // TypeValidator is a validator for the "type" field enum values. It is called by the builders before save. func TypeValidator(_type Type) error { switch _type { - case TypeScript, TypeCommand, TypeDNSRecord, TypeFileDelete, TypeFileDownload, TypeFileExtract: + case TypeScript, TypeCommand, TypeDNSRecord, TypeFileDelete, TypeFileDownload, TypeFileExtract, TypeValidate: return nil default: return fmt.Errorf("provisioningstep: invalid enum value for type field: %q", _type) diff --git a/ent/runtime.go b/ent/runtime.go index e9f4831a..c83fa507 100755 --- a/ent/runtime.go +++ b/ent/runtime.go @@ -39,6 +39,7 @@ import ( "github.com/gen0cide/laforge/ent/team" "github.com/gen0cide/laforge/ent/token" "github.com/gen0cide/laforge/ent/user" + "github.com/gen0cide/laforge/ent/validation" "github.com/google/uuid" ) @@ -332,4 +333,22 @@ func init() { userDescID := userFields[0].Descriptor() // user.DefaultID holds the default value on creation for the id field. user.DefaultID = userDescID.Default.(func() uuid.UUID) + validationFields := schema.Validation{}.Fields() + _ = validationFields + // validationDescValidationType is the schema descriptor for validation_type field. + validationDescValidationType := validationFields[2].Descriptor() + // validation.DefaultValidationType holds the default value on creation for the validation_type field. + validation.DefaultValidationType = validationDescValidationType.Default.(string) + // validationDescOutput is the schema descriptor for output field. + validationDescOutput := validationFields[3].Descriptor() + // validation.DefaultOutput holds the default value on creation for the output field. + validation.DefaultOutput = validationDescOutput.Default.(string) + // validationDescErrorMessage is the schema descriptor for error_message field. + validationDescErrorMessage := validationFields[5].Descriptor() + // validation.DefaultErrorMessage holds the default value on creation for the error_message field. + validation.DefaultErrorMessage = validationDescErrorMessage.Default.(string) + // validationDescID is the schema descriptor for id field. + validationDescID := validationFields[0].Descriptor() + // validation.DefaultID holds the default value on creation for the id field. + validation.DefaultID = validationDescID.Default.(func() uuid.UUID) } diff --git a/ent/schema-viz.html b/ent/schema-viz.html index 419a825e..3027da80 100644 --- a/ent/schema-viz.html +++ b/ent/schema-viz.html @@ -4,6 +4,7 @@