events.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package forms
  2. import (
  3. "strings"
  4. "time"
  5. "github.com/porter-dev/porter/internal/models"
  6. )
  7. // CreateEventForm is the input for creating a new event
  8. type CreateEventForm struct {
  9. ResourceType string `json:"resource_type"`
  10. Name string `json:"name"`
  11. OwnerType string `json:"owner_type"`
  12. OwnerName string `json:"owner_name"`
  13. EventType string `json:"event_type"`
  14. Namespace string `json:"namespace"`
  15. Message string `json:"message"`
  16. Reason string `json:"reason"`
  17. Timestamp time.Time `json:"timestamp"`
  18. Data []string `json:"data"`
  19. }
  20. func (c *CreateEventForm) ToEvent(projID uint, clusterID uint) *models.Event {
  21. return &models.Event{
  22. ProjectID: projID,
  23. ClusterID: clusterID,
  24. OwnerType: c.OwnerType,
  25. OwnerName: c.OwnerName,
  26. EventType: c.EventType,
  27. RefType: c.ResourceType,
  28. RefName: c.Name,
  29. RefNamespace: c.Namespace,
  30. Message: c.Message,
  31. Reason: c.Reason,
  32. Timestamp: c.Timestamp,
  33. Data: []byte(strings.Join(c.Data, "\n")),
  34. Expiry: time.Now().Add(24 * 14 * time.Hour),
  35. }
  36. }