machine.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package schema
  2. import (
  3. "entgo.io/ent"
  4. "entgo.io/ent/schema/edge"
  5. "entgo.io/ent/schema/field"
  6. "github.com/crowdsecurity/crowdsec/pkg/types"
  7. )
  8. // Machine holds the schema definition for the Machine entity.
  9. type Machine struct {
  10. ent.Schema
  11. }
  12. // Fields of the Machine.
  13. func (Machine) Fields() []ent.Field {
  14. return []ent.Field{
  15. field.Time("created_at").
  16. Default(types.UtcNow).
  17. UpdateDefault(types.UtcNow).Nillable().Optional(),
  18. field.Time("updated_at").
  19. Default(types.UtcNow).
  20. UpdateDefault(types.UtcNow).Nillable().Optional(),
  21. field.Time("last_push").
  22. Default(types.UtcNow).
  23. UpdateDefault(types.UtcNow).Nillable().Optional(),
  24. field.String("machineId").Unique(),
  25. field.String("password").Sensitive(),
  26. field.String("ipAddress"),
  27. field.String("scenarios").MaxLen(4095).Optional(),
  28. field.String("version").Optional(),
  29. field.Bool("isValidated").
  30. Default(false),
  31. field.String("status").Optional(),
  32. }
  33. }
  34. // Edges of the Machine.
  35. func (Machine) Edges() []ent.Edge {
  36. return []ent.Edge{
  37. edge.To("alerts", Alert.Type),
  38. }
  39. }