This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
notification_configuration.go
139 lines (112 loc) · 6.61 KB
/
notification_configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package types
import "time"
// NotificationTriggerType represents the different TFE notifications that can be sent
// as a run's progress transitions between different states
type NotificationTriggerType string
const (
NotificationTriggerCreated NotificationTriggerType = "run:created"
NotificationTriggerPlanning NotificationTriggerType = "run:planning"
NotificationTriggerNeedsAttention NotificationTriggerType = "run:needs_attention"
NotificationTriggerApplying NotificationTriggerType = "run:applying"
NotificationTriggerCompleted NotificationTriggerType = "run:completed"
NotificationTriggerErrored NotificationTriggerType = "run:errored"
NotificationTriggerAssessmentDrifted NotificationTriggerType = "assessment:drifted"
NotificationTriggerAssessmentFailed NotificationTriggerType = "assessment:failed"
NotificationTriggerAssessmentCheckFailed NotificationTriggerType = "assessment:check_failure"
)
// NotificationDestinationType represents the destination type of the
// notification configuration.
type NotificationDestinationType string
// List of available notification destination types.
const (
NotificationDestinationTypeEmail NotificationDestinationType = "email"
NotificationDestinationTypeGeneric NotificationDestinationType = "generic"
NotificationDestinationTypeSlack NotificationDestinationType = "slack"
NotificationDestinationTypeMicrosoftTeams NotificationDestinationType = "microsoft-teams"
)
func NotificationDestinationPtr(d NotificationDestinationType) *NotificationDestinationType {
return &d
}
// NotificationConfigurationList represents a list of Notification
// Configurations.
type NotificationConfigurationList struct {
*Pagination
Items []*NotificationConfiguration
}
// NotificationConfiguration represents a Notification Configuration.
type NotificationConfiguration struct {
ID string `jsonapi:"primary,notification-configurations"`
CreatedAt time.Time `jsonapi:"attribute" json:"created-at"`
DeliveryResponses []*DeliveryResponse `jsonapi:"attribute" json:"delivery-responses"`
DestinationType NotificationDestinationType `jsonapi:"attribute" json:"destination-type"`
Enabled bool `jsonapi:"attribute" json:"enabled"`
Name string `jsonapi:"attribute" json:"name"`
Token string `jsonapi:"attribute" json:"token"`
Triggers []string `jsonapi:"attribute" json:"triggers"`
UpdatedAt time.Time `jsonapi:"attribute" json:"updated-at"`
URL string `jsonapi:"attribute" json:"url"`
// EmailAddresses is only available for TFE users. It is not available in TFC.
EmailAddresses []string `jsonapi:"attribute" json:"email-addresses"`
// relationships
Subscribable *Workspace `jsonapi:"relationship" json:"subscribable"`
EmailUsers []*User `jsonapi:"relationship" json:"users"`
}
// DeliveryResponse represents a notification configuration delivery response.
type DeliveryResponse struct {
Body string `jsonapi:"attribute" json:"body"`
Code string `jsonapi:"attribute" json:"code"`
Headers map[string][]string `jsonapi:"attribute" json:"headers"`
SentAt time.Time `jsonapi:"attribute" json:"sent-at"`
Successful string `jsonapi:"attribute" json:"successful"`
URL string `jsonapi:"attribute" json:"url"`
}
// NotificationConfigurationCreateOptions represents the options for
// creating a new notification configuration.
type NotificationConfigurationCreateOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,notification-configurations"`
// Required: The destination type of the notification configuration
DestinationType *NotificationDestinationType `jsonapi:"attribute" json:"destination-type"`
// Required: Whether the notification configuration should be enabled or not
Enabled *bool `jsonapi:"attribute" json:"enabled"`
// Required: The name of the notification configuration
Name *string `jsonapi:"attribute" json:"name"`
// Optional: The token of the notification configuration
Token *string `jsonapi:"attribute" json:"token,omitempty"`
// Optional: The list of run events that will trigger notifications.
Triggers []NotificationTriggerType `jsonapi:"attribute" json:"triggers,omitempty"`
// Optional: The url of the notification configuration
URL *string `jsonapi:"attribute" json:"url,omitempty"`
// Optional: The list of email addresses that will receive notification emails.
// EmailAddresses is only available for TFE users. It is not available in TFC.
EmailAddresses []string `jsonapi:"attribute" json:"email-addresses,omitempty"`
// Optional: The list of users belonging to the organization that will receive notification emails.
EmailUsers []*User `jsonapi:"relationship" json:"users,omitempty"`
}
// NotificationConfigurationUpdateOptions represents the options for
// updating a existing notification configuration.
type NotificationConfigurationUpdateOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,notification-configurations"`
// Optional: Whether the notification configuration should be enabled or not
Enabled *bool `jsonapi:"attribute" json:"enabled,omitempty"`
// Optional: The name of the notification configuration
Name *string `jsonapi:"attribute" json:"name,omitempty"`
// Optional: The token of the notification configuration
Token *string `jsonapi:"attribute" json:"token,omitempty"`
// Optional: The list of run events that will trigger notifications.
Triggers []NotificationTriggerType `jsonapi:"attribute" json:"triggers,omitempty"`
// Optional: The url of the notification configuration
URL *string `jsonapi:"attribute" json:"url,omitempty"`
// Optional: The list of email addresses that will receive notification emails.
// EmailAddresses is only available for TFE users. It is not available in TFC.
EmailAddresses []string `jsonapi:"attribute" json:"email-addresses,omitempty"`
// Optional: The list of users belonging to the organization that will receive notification emails.
EmailUsers []*User `jsonapi:"relationship" json:"users,omitempty"`
}