2022-10-06 12:55:42 +00:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
2020-11-30 09:37:17 +00:00
|
|
|
|
|
|
|
package ent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2024-02-14 10:19:13 +00:00
|
|
|
"entgo.io/ent"
|
2021-03-15 17:46:52 +00:00
|
|
|
"entgo.io/ent/dialect/sql"
|
2020-11-30 09:37:17 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/machine"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Machine is the model entity for the Machine schema.
|
|
|
|
type Machine struct {
|
|
|
|
config `json:"-"`
|
|
|
|
// ID of the ent.
|
|
|
|
ID int `json:"id,omitempty"`
|
|
|
|
// CreatedAt holds the value of the "created_at" field.
|
2022-01-19 13:56:05 +00:00
|
|
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
// UpdatedAt holds the value of the "updated_at" field.
|
2022-01-19 13:56:05 +00:00
|
|
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
2022-01-13 15:46:16 +00:00
|
|
|
// LastPush holds the value of the "last_push" field.
|
2022-01-19 13:56:05 +00:00
|
|
|
LastPush *time.Time `json:"last_push,omitempty"`
|
2022-05-19 13:47:27 +00:00
|
|
|
// LastHeartbeat holds the value of the "last_heartbeat" field.
|
|
|
|
LastHeartbeat *time.Time `json:"last_heartbeat,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
// MachineId holds the value of the "machineId" field.
|
|
|
|
MachineId string `json:"machineId,omitempty"`
|
|
|
|
// Password holds the value of the "password" field.
|
|
|
|
Password string `json:"-"`
|
|
|
|
// IpAddress holds the value of the "ipAddress" field.
|
|
|
|
IpAddress string `json:"ipAddress,omitempty"`
|
|
|
|
// Scenarios holds the value of the "scenarios" field.
|
|
|
|
Scenarios string `json:"scenarios,omitempty"`
|
|
|
|
// Version holds the value of the "version" field.
|
|
|
|
Version string `json:"version,omitempty"`
|
|
|
|
// IsValidated holds the value of the "isValidated" field.
|
|
|
|
IsValidated bool `json:"isValidated,omitempty"`
|
|
|
|
// Status holds the value of the "status" field.
|
|
|
|
Status string `json:"status,omitempty"`
|
2022-06-08 14:05:52 +00:00
|
|
|
// AuthType holds the value of the "auth_type" field.
|
|
|
|
AuthType string `json:"auth_type"`
|
2020-11-30 09:37:17 +00:00
|
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
|
|
// The values are being populated by the MachineQuery when eager-loading is set.
|
2024-02-14 10:19:13 +00:00
|
|
|
Edges MachineEdges `json:"edges"`
|
|
|
|
selectValues sql.SelectValues
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MachineEdges holds the relations/edges for other nodes in the graph.
|
|
|
|
type MachineEdges struct {
|
|
|
|
// Alerts holds the value of the alerts edge.
|
2021-03-15 17:46:52 +00:00
|
|
|
Alerts []*Alert `json:"alerts,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
// loadedTypes holds the information for reporting if a
|
|
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
|
|
loadedTypes [1]bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// AlertsOrErr returns the Alerts value or an error if the edge
|
|
|
|
// was not loaded in eager-loading.
|
|
|
|
func (e MachineEdges) AlertsOrErr() ([]*Alert, error) {
|
|
|
|
if e.loadedTypes[0] {
|
|
|
|
return e.Alerts, nil
|
|
|
|
}
|
|
|
|
return nil, &NotLoadedError{edge: "alerts"}
|
|
|
|
}
|
|
|
|
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
2022-10-06 12:55:42 +00:00
|
|
|
func (*Machine) scanValues(columns []string) ([]any, error) {
|
|
|
|
values := make([]any, len(columns))
|
2021-01-14 15:27:45 +00:00
|
|
|
for i := range columns {
|
|
|
|
switch columns[i] {
|
|
|
|
case machine.FieldIsValidated:
|
2021-10-22 14:15:57 +00:00
|
|
|
values[i] = new(sql.NullBool)
|
2021-01-14 15:27:45 +00:00
|
|
|
case machine.FieldID:
|
2021-10-22 14:15:57 +00:00
|
|
|
values[i] = new(sql.NullInt64)
|
2022-06-08 14:05:52 +00:00
|
|
|
case machine.FieldMachineId, machine.FieldPassword, machine.FieldIpAddress, machine.FieldScenarios, machine.FieldVersion, machine.FieldStatus, machine.FieldAuthType:
|
2021-10-22 14:15:57 +00:00
|
|
|
values[i] = new(sql.NullString)
|
2022-05-19 13:47:27 +00:00
|
|
|
case machine.FieldCreatedAt, machine.FieldUpdatedAt, machine.FieldLastPush, machine.FieldLastHeartbeat:
|
2021-10-22 14:15:57 +00:00
|
|
|
values[i] = new(sql.NullTime)
|
2021-01-14 15:27:45 +00:00
|
|
|
default:
|
2024-02-14 10:19:13 +00:00
|
|
|
values[i] = new(sql.UnknownType)
|
2021-01-14 15:27:45 +00:00
|
|
|
}
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
2021-01-14 15:27:45 +00:00
|
|
|
return values, nil
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
|
|
// to the Machine fields.
|
2022-10-06 12:55:42 +00:00
|
|
|
func (m *Machine) assignValues(columns []string, values []any) error {
|
2021-01-14 15:27:45 +00:00
|
|
|
if m, n := len(values), len(columns); m < n {
|
2020-11-30 09:37:17 +00:00
|
|
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
|
|
|
}
|
2021-01-14 15:27:45 +00:00
|
|
|
for i := range columns {
|
|
|
|
switch columns[i] {
|
|
|
|
case machine.FieldID:
|
|
|
|
value, ok := values[i].(*sql.NullInt64)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field id", value)
|
|
|
|
}
|
|
|
|
m.ID = int(value.Int64)
|
|
|
|
case machine.FieldCreatedAt:
|
|
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
|
|
|
} else if value.Valid {
|
2022-01-19 13:56:05 +00:00
|
|
|
m.CreatedAt = new(time.Time)
|
|
|
|
*m.CreatedAt = value.Time
|
2021-01-14 15:27:45 +00:00
|
|
|
}
|
|
|
|
case machine.FieldUpdatedAt:
|
|
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
|
|
|
} else if value.Valid {
|
2022-01-19 13:56:05 +00:00
|
|
|
m.UpdatedAt = new(time.Time)
|
|
|
|
*m.UpdatedAt = value.Time
|
2021-01-14 15:27:45 +00:00
|
|
|
}
|
2022-01-13 15:46:16 +00:00
|
|
|
case machine.FieldLastPush:
|
|
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field last_push", values[i])
|
|
|
|
} else if value.Valid {
|
2022-01-19 13:56:05 +00:00
|
|
|
m.LastPush = new(time.Time)
|
|
|
|
*m.LastPush = value.Time
|
2022-01-13 15:46:16 +00:00
|
|
|
}
|
2022-05-19 13:47:27 +00:00
|
|
|
case machine.FieldLastHeartbeat:
|
|
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field last_heartbeat", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.LastHeartbeat = new(time.Time)
|
|
|
|
*m.LastHeartbeat = value.Time
|
|
|
|
}
|
2021-01-14 15:27:45 +00:00
|
|
|
case machine.FieldMachineId:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field machineId", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.MachineId = value.String
|
|
|
|
}
|
|
|
|
case machine.FieldPassword:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field password", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.Password = value.String
|
|
|
|
}
|
|
|
|
case machine.FieldIpAddress:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field ipAddress", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.IpAddress = value.String
|
|
|
|
}
|
|
|
|
case machine.FieldScenarios:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field scenarios", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.Scenarios = value.String
|
|
|
|
}
|
|
|
|
case machine.FieldVersion:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field version", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.Version = value.String
|
|
|
|
}
|
|
|
|
case machine.FieldIsValidated:
|
|
|
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field isValidated", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.IsValidated = value.Bool
|
|
|
|
}
|
|
|
|
case machine.FieldStatus:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.Status = value.String
|
|
|
|
}
|
2022-06-08 14:05:52 +00:00
|
|
|
case machine.FieldAuthType:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field auth_type", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.AuthType = value.String
|
|
|
|
}
|
2024-02-14 10:19:13 +00:00
|
|
|
default:
|
|
|
|
m.selectValues.Set(columns[i], values[i])
|
2021-01-14 15:27:45 +00:00
|
|
|
}
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-14 10:19:13 +00:00
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the Machine.
|
|
|
|
// This includes values selected through modifiers, order, etc.
|
|
|
|
func (m *Machine) Value(name string) (ent.Value, error) {
|
|
|
|
return m.selectValues.Get(name)
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// QueryAlerts queries the "alerts" edge of the Machine entity.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (m *Machine) QueryAlerts() *AlertQuery {
|
2024-02-14 10:19:13 +00:00
|
|
|
return NewMachineClient(m.config).QueryAlerts(m)
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update returns a builder for updating this Machine.
|
2021-01-14 15:27:45 +00:00
|
|
|
// Note that you need to call Machine.Unwrap() before calling this method if this Machine
|
2020-11-30 09:37:17 +00:00
|
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
|
|
func (m *Machine) Update() *MachineUpdateOne {
|
2024-02-14 10:19:13 +00:00
|
|
|
return NewMachineClient(m.config).UpdateOne(m)
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// Unwrap unwraps the Machine entity that was returned from a transaction after it was closed,
|
|
|
|
// so that all future queries will be executed through the driver which created the transaction.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (m *Machine) Unwrap() *Machine {
|
2022-10-06 12:55:42 +00:00
|
|
|
_tx, ok := m.config.driver.(*txDriver)
|
2020-11-30 09:37:17 +00:00
|
|
|
if !ok {
|
|
|
|
panic("ent: Machine is not a transactional entity")
|
|
|
|
}
|
2022-10-06 12:55:42 +00:00
|
|
|
m.config.driver = _tx.drv
|
2020-11-30 09:37:17 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
// String implements the fmt.Stringer.
|
|
|
|
func (m *Machine) String() string {
|
|
|
|
var builder strings.Builder
|
|
|
|
builder.WriteString("Machine(")
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
|
2022-01-19 13:56:05 +00:00
|
|
|
if v := m.CreatedAt; v != nil {
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString("created_at=")
|
2022-01-19 13:56:05 +00:00
|
|
|
builder.WriteString(v.Format(time.ANSIC))
|
|
|
|
}
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
2022-01-19 13:56:05 +00:00
|
|
|
if v := m.UpdatedAt; v != nil {
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString("updated_at=")
|
2022-01-19 13:56:05 +00:00
|
|
|
builder.WriteString(v.Format(time.ANSIC))
|
|
|
|
}
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
2022-01-19 13:56:05 +00:00
|
|
|
if v := m.LastPush; v != nil {
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString("last_push=")
|
2022-01-19 13:56:05 +00:00
|
|
|
builder.WriteString(v.Format(time.ANSIC))
|
|
|
|
}
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
2022-05-19 13:47:27 +00:00
|
|
|
if v := m.LastHeartbeat; v != nil {
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString("last_heartbeat=")
|
2022-05-19 13:47:27 +00:00
|
|
|
builder.WriteString(v.Format(time.ANSIC))
|
|
|
|
}
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("machineId=")
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteString(m.MachineId)
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("password=<sensitive>")
|
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("ipAddress=")
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteString(m.IpAddress)
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("scenarios=")
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteString(m.Scenarios)
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("version=")
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteString(m.Version)
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("isValidated=")
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteString(fmt.Sprintf("%v", m.IsValidated))
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("status=")
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteString(m.Status)
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("auth_type=")
|
2022-06-08 14:05:52 +00:00
|
|
|
builder.WriteString(m.AuthType)
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteByte(')')
|
|
|
|
return builder.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Machines is a parsable slice of Machine.
|
|
|
|
type Machines []*Machine
|