notification.go 3.2 KB

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