notification.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package notifications
  2. import (
  3. "time"
  4. "github.com/google/uuid"
  5. )
  6. // Notification is a struct that contains all actionable information from an app event
  7. type Notification struct {
  8. // AppRevisionID is the ID of the app revision that the notification belongs to
  9. AppRevisionID string `json:"app_revision_id"`
  10. // Error is the Porter error parsed from the agent event
  11. Error PorterError `json:"error"`
  12. // Timestamp is the time that the notification was created
  13. Timestamp time.Time `json:"timestamp"`
  14. // ID is the ID of the notification
  15. ID uuid.UUID `json:"id"`
  16. // Scope is the scope of the notification
  17. Scope Scope `json:"scope"`
  18. // Metadata is the metadata of the notification
  19. Metadata Metadata `json:"metadata"`
  20. }
  21. // Metadata is the metadata of the notification
  22. type Metadata struct {
  23. // Deployment is the deployment metadata, used to determine if the notification occurred during deployment or after
  24. Deployment Deployment `json:"deployment"`
  25. // ServiceName is the name of the service
  26. ServiceName string `json:"service_name"`
  27. // JobRunID is the id of the job run, if the service is a job
  28. JobRunID string `json:"job_run_id"`
  29. }
  30. // Scope is the scope of the notification
  31. type Scope string
  32. const (
  33. // Scope_Application indicates that the notification is scoped to the application
  34. Scope_Application Scope = "APPLICATION"
  35. // Scope_Revision indicates that the notification is scoped to the revision
  36. Scope_Revision Scope = "REVISION"
  37. // Scope_Service indicates that the notification is scoped to the service
  38. Scope_Service Scope = "SERVICE"
  39. )
  40. // PorterError is the translation of a generic error from the agent into an actionable error for the user
  41. type PorterError struct {
  42. // Code is the error code that can be used to determine the type of error
  43. Code PorterErrorCode `json:"code"`
  44. // Summary is a short description of the error
  45. Summary string `json:"summary"`
  46. // Detail is a longer description of the error
  47. Detail string `json:"detail"`
  48. // MitigationSteps are the steps that can be taken to resolve the error
  49. MitigationSteps string `json:"mitigation_steps"`
  50. // Documentation is a list of links to documentation that can be used to resolve the error
  51. Documentation []string `json:"documentation"`
  52. // ShouldViewLogs is a boolean indicating whether the user should look at container logs for more information
  53. ShouldViewLogs bool `json:"should_view_logs"`
  54. }
  55. // PorterErrorCode is the error code that can be used to determine the type of error
  56. type PorterErrorCode int
  57. // Deployment represents metadata about a k8s deployment
  58. type Deployment struct {
  59. Status DeploymentStatus `json:"status"`
  60. }
  61. // DeploymentStatus represents the status of a k8s deployment
  62. type DeploymentStatus string
  63. const (
  64. // DeploymentStatus_Unknown indicates that the status of the deployment is unknown because we have not queried for it yet
  65. DeploymentStatus_Unknown DeploymentStatus = "UNKNOWN"
  66. // DeploymentStatus_Pending indicates that the deployment is still in progress
  67. DeploymentStatus_Pending DeploymentStatus = "PENDING"
  68. // DeploymentStatus_Success indicates that the deployment was successful
  69. DeploymentStatus_Success DeploymentStatus = "SUCCESS"
  70. // DeploymentStatus_Failure indicates that the deployment failed
  71. DeploymentStatus_Failure DeploymentStatus = "FAILURE"
  72. )