github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/machine.go (about) 1 // Code generated by ent, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "fmt" 7 "strings" 8 "time" 9 10 "entgo.io/ent" 11 "entgo.io/ent/dialect/sql" 12 "github.com/crowdsecurity/crowdsec/pkg/database/ent/machine" 13 ) 14 15 // Machine is the model entity for the Machine schema. 16 type Machine struct { 17 config `json:"-"` 18 // ID of the ent. 19 ID int `json:"id,omitempty"` 20 // CreatedAt holds the value of the "created_at" field. 21 CreatedAt *time.Time `json:"created_at,omitempty"` 22 // UpdatedAt holds the value of the "updated_at" field. 23 UpdatedAt *time.Time `json:"updated_at,omitempty"` 24 // LastPush holds the value of the "last_push" field. 25 LastPush *time.Time `json:"last_push,omitempty"` 26 // LastHeartbeat holds the value of the "last_heartbeat" field. 27 LastHeartbeat *time.Time `json:"last_heartbeat,omitempty"` 28 // MachineId holds the value of the "machineId" field. 29 MachineId string `json:"machineId,omitempty"` 30 // Password holds the value of the "password" field. 31 Password string `json:"-"` 32 // IpAddress holds the value of the "ipAddress" field. 33 IpAddress string `json:"ipAddress,omitempty"` 34 // Scenarios holds the value of the "scenarios" field. 35 Scenarios string `json:"scenarios,omitempty"` 36 // Version holds the value of the "version" field. 37 Version string `json:"version,omitempty"` 38 // IsValidated holds the value of the "isValidated" field. 39 IsValidated bool `json:"isValidated,omitempty"` 40 // Status holds the value of the "status" field. 41 Status string `json:"status,omitempty"` 42 // AuthType holds the value of the "auth_type" field. 43 AuthType string `json:"auth_type"` 44 // Edges holds the relations/edges for other nodes in the graph. 45 // The values are being populated by the MachineQuery when eager-loading is set. 46 Edges MachineEdges `json:"edges"` 47 selectValues sql.SelectValues 48 } 49 50 // MachineEdges holds the relations/edges for other nodes in the graph. 51 type MachineEdges struct { 52 // Alerts holds the value of the alerts edge. 53 Alerts []*Alert `json:"alerts,omitempty"` 54 // loadedTypes holds the information for reporting if a 55 // type was loaded (or requested) in eager-loading or not. 56 loadedTypes [1]bool 57 } 58 59 // AlertsOrErr returns the Alerts value or an error if the edge 60 // was not loaded in eager-loading. 61 func (e MachineEdges) AlertsOrErr() ([]*Alert, error) { 62 if e.loadedTypes[0] { 63 return e.Alerts, nil 64 } 65 return nil, &NotLoadedError{edge: "alerts"} 66 } 67 68 // scanValues returns the types for scanning values from sql.Rows. 69 func (*Machine) scanValues(columns []string) ([]any, error) { 70 values := make([]any, len(columns)) 71 for i := range columns { 72 switch columns[i] { 73 case machine.FieldIsValidated: 74 values[i] = new(sql.NullBool) 75 case machine.FieldID: 76 values[i] = new(sql.NullInt64) 77 case machine.FieldMachineId, machine.FieldPassword, machine.FieldIpAddress, machine.FieldScenarios, machine.FieldVersion, machine.FieldStatus, machine.FieldAuthType: 78 values[i] = new(sql.NullString) 79 case machine.FieldCreatedAt, machine.FieldUpdatedAt, machine.FieldLastPush, machine.FieldLastHeartbeat: 80 values[i] = new(sql.NullTime) 81 default: 82 values[i] = new(sql.UnknownType) 83 } 84 } 85 return values, nil 86 } 87 88 // assignValues assigns the values that were returned from sql.Rows (after scanning) 89 // to the Machine fields. 90 func (m *Machine) assignValues(columns []string, values []any) error { 91 if m, n := len(values), len(columns); m < n { 92 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) 93 } 94 for i := range columns { 95 switch columns[i] { 96 case machine.FieldID: 97 value, ok := values[i].(*sql.NullInt64) 98 if !ok { 99 return fmt.Errorf("unexpected type %T for field id", value) 100 } 101 m.ID = int(value.Int64) 102 case machine.FieldCreatedAt: 103 if value, ok := values[i].(*sql.NullTime); !ok { 104 return fmt.Errorf("unexpected type %T for field created_at", values[i]) 105 } else if value.Valid { 106 m.CreatedAt = new(time.Time) 107 *m.CreatedAt = value.Time 108 } 109 case machine.FieldUpdatedAt: 110 if value, ok := values[i].(*sql.NullTime); !ok { 111 return fmt.Errorf("unexpected type %T for field updated_at", values[i]) 112 } else if value.Valid { 113 m.UpdatedAt = new(time.Time) 114 *m.UpdatedAt = value.Time 115 } 116 case machine.FieldLastPush: 117 if value, ok := values[i].(*sql.NullTime); !ok { 118 return fmt.Errorf("unexpected type %T for field last_push", values[i]) 119 } else if value.Valid { 120 m.LastPush = new(time.Time) 121 *m.LastPush = value.Time 122 } 123 case machine.FieldLastHeartbeat: 124 if value, ok := values[i].(*sql.NullTime); !ok { 125 return fmt.Errorf("unexpected type %T for field last_heartbeat", values[i]) 126 } else if value.Valid { 127 m.LastHeartbeat = new(time.Time) 128 *m.LastHeartbeat = value.Time 129 } 130 case machine.FieldMachineId: 131 if value, ok := values[i].(*sql.NullString); !ok { 132 return fmt.Errorf("unexpected type %T for field machineId", values[i]) 133 } else if value.Valid { 134 m.MachineId = value.String 135 } 136 case machine.FieldPassword: 137 if value, ok := values[i].(*sql.NullString); !ok { 138 return fmt.Errorf("unexpected type %T for field password", values[i]) 139 } else if value.Valid { 140 m.Password = value.String 141 } 142 case machine.FieldIpAddress: 143 if value, ok := values[i].(*sql.NullString); !ok { 144 return fmt.Errorf("unexpected type %T for field ipAddress", values[i]) 145 } else if value.Valid { 146 m.IpAddress = value.String 147 } 148 case machine.FieldScenarios: 149 if value, ok := values[i].(*sql.NullString); !ok { 150 return fmt.Errorf("unexpected type %T for field scenarios", values[i]) 151 } else if value.Valid { 152 m.Scenarios = value.String 153 } 154 case machine.FieldVersion: 155 if value, ok := values[i].(*sql.NullString); !ok { 156 return fmt.Errorf("unexpected type %T for field version", values[i]) 157 } else if value.Valid { 158 m.Version = value.String 159 } 160 case machine.FieldIsValidated: 161 if value, ok := values[i].(*sql.NullBool); !ok { 162 return fmt.Errorf("unexpected type %T for field isValidated", values[i]) 163 } else if value.Valid { 164 m.IsValidated = value.Bool 165 } 166 case machine.FieldStatus: 167 if value, ok := values[i].(*sql.NullString); !ok { 168 return fmt.Errorf("unexpected type %T for field status", values[i]) 169 } else if value.Valid { 170 m.Status = value.String 171 } 172 case machine.FieldAuthType: 173 if value, ok := values[i].(*sql.NullString); !ok { 174 return fmt.Errorf("unexpected type %T for field auth_type", values[i]) 175 } else if value.Valid { 176 m.AuthType = value.String 177 } 178 default: 179 m.selectValues.Set(columns[i], values[i]) 180 } 181 } 182 return nil 183 } 184 185 // Value returns the ent.Value that was dynamically selected and assigned to the Machine. 186 // This includes values selected through modifiers, order, etc. 187 func (m *Machine) Value(name string) (ent.Value, error) { 188 return m.selectValues.Get(name) 189 } 190 191 // QueryAlerts queries the "alerts" edge of the Machine entity. 192 func (m *Machine) QueryAlerts() *AlertQuery { 193 return NewMachineClient(m.config).QueryAlerts(m) 194 } 195 196 // Update returns a builder for updating this Machine. 197 // Note that you need to call Machine.Unwrap() before calling this method if this Machine 198 // was returned from a transaction, and the transaction was committed or rolled back. 199 func (m *Machine) Update() *MachineUpdateOne { 200 return NewMachineClient(m.config).UpdateOne(m) 201 } 202 203 // Unwrap unwraps the Machine entity that was returned from a transaction after it was closed, 204 // so that all future queries will be executed through the driver which created the transaction. 205 func (m *Machine) Unwrap() *Machine { 206 _tx, ok := m.config.driver.(*txDriver) 207 if !ok { 208 panic("ent: Machine is not a transactional entity") 209 } 210 m.config.driver = _tx.drv 211 return m 212 } 213 214 // String implements the fmt.Stringer. 215 func (m *Machine) String() string { 216 var builder strings.Builder 217 builder.WriteString("Machine(") 218 builder.WriteString(fmt.Sprintf("id=%v, ", m.ID)) 219 if v := m.CreatedAt; v != nil { 220 builder.WriteString("created_at=") 221 builder.WriteString(v.Format(time.ANSIC)) 222 } 223 builder.WriteString(", ") 224 if v := m.UpdatedAt; v != nil { 225 builder.WriteString("updated_at=") 226 builder.WriteString(v.Format(time.ANSIC)) 227 } 228 builder.WriteString(", ") 229 if v := m.LastPush; v != nil { 230 builder.WriteString("last_push=") 231 builder.WriteString(v.Format(time.ANSIC)) 232 } 233 builder.WriteString(", ") 234 if v := m.LastHeartbeat; v != nil { 235 builder.WriteString("last_heartbeat=") 236 builder.WriteString(v.Format(time.ANSIC)) 237 } 238 builder.WriteString(", ") 239 builder.WriteString("machineId=") 240 builder.WriteString(m.MachineId) 241 builder.WriteString(", ") 242 builder.WriteString("password=<sensitive>") 243 builder.WriteString(", ") 244 builder.WriteString("ipAddress=") 245 builder.WriteString(m.IpAddress) 246 builder.WriteString(", ") 247 builder.WriteString("scenarios=") 248 builder.WriteString(m.Scenarios) 249 builder.WriteString(", ") 250 builder.WriteString("version=") 251 builder.WriteString(m.Version) 252 builder.WriteString(", ") 253 builder.WriteString("isValidated=") 254 builder.WriteString(fmt.Sprintf("%v", m.IsValidated)) 255 builder.WriteString(", ") 256 builder.WriteString("status=") 257 builder.WriteString(m.Status) 258 builder.WriteString(", ") 259 builder.WriteString("auth_type=") 260 builder.WriteString(m.AuthType) 261 builder.WriteByte(')') 262 return builder.String() 263 } 264 265 // Machines is a parsable slice of Machine. 266 type Machines []*Machine