@@ -8,21 +8,61 @@ import (
8
8
"net/http"
9
9
)
10
10
11
- func (c * Client ) CreateSpaceEmailNotification (space_name string , notification_name string , environment_launched bool ,
11
+ const (
12
+ email_notification_type = "Email"
13
+ slack_notification_type = "Slack"
14
+ teams_notification_type = "Teams"
15
+ webhook_notification_type = "GenericWebhook"
16
+ )
17
+
18
+ func (c * Client ) CreateSpaceNotification (notification_type string , space_name string , notification_name string , environment_launched bool ,
12
19
environment_deployed bool , environment_force_ended bool , environment_idle bool , environment_extended bool ,
13
20
drift_detected bool , workflow_failed bool , workflow_started bool , updates_detected bool ,
14
21
collaborator_added bool , action_failed bool , environment_ending_failed bool , environment_ended bool ,
15
- environment_active_with_error bool , workflow_start_reminder int64 , end_threshold int64 , idle_reminder []int64 ) (string , error ) {
16
-
17
- data := SubscriptionsRequest {
18
- Name : notification_name ,
19
- Description : "" ,
20
- Target : SubscriptionsTargetRequest {
21
- Type : "Email" ,
22
+ environment_active_with_error bool , workflow_start_reminder int64 , end_threshold int64 , blueprint_published bool , blueprint_unpublished bool , idle_reminder []int64 , webhook * string , token * string ) (string , error ) {
23
+ var data SubscriptionsRequest
24
+ switch notification_type {
25
+ case email_notification_type :
26
+ data = SubscriptionsRequest {
27
+ Name : notification_name ,
28
+ Description : "" ,
29
+ Target : SubscriptionsTargetRequest {
30
+ Type : email_notification_type ,
31
+ Description : "" ,
32
+ },
33
+ }
34
+ case slack_notification_type :
35
+ data = SubscriptionsRequest {
36
+ Name : notification_name ,
37
+ Description : "" ,
38
+ Target : SubscriptionsTargetRequest {
39
+ Type : slack_notification_type ,
40
+ Description : "" ,
41
+ WebHook : webhook ,
42
+ },
43
+ }
44
+ case teams_notification_type :
45
+ data = SubscriptionsRequest {
46
+ Name : notification_name ,
22
47
Description : "" ,
23
- },
48
+ Target : SubscriptionsTargetRequest {
49
+ Type : teams_notification_type ,
50
+ Description : "" ,
51
+ WebHook : webhook ,
52
+ },
53
+ }
54
+ case webhook_notification_type :
55
+ data = SubscriptionsRequest {
56
+ Name : notification_name ,
57
+ Description : "" ,
58
+ Target : SubscriptionsTargetRequest {
59
+ Type : webhook_notification_type ,
60
+ Description : "" ,
61
+ WebHook : webhook ,
62
+ Token : token ,
63
+ },
64
+ }
24
65
}
25
-
26
66
if environment_launched {
27
67
data .Events = append (data .Events , "EnvironmentLaunched" )
28
68
}
@@ -73,10 +113,15 @@ func (c *Client) CreateSpaceEmailNotification(space_name string, notification_na
73
113
if environment_active_with_error {
74
114
data .Events = append (data .Events , "EnvironmentActiveWithError" )
75
115
}
76
-
116
+ if blueprint_published {
117
+ data .Events = append (data .Events , "BlueprintPublished" )
118
+ }
119
+ if blueprint_unpublished {
120
+ data .Events = append (data .Events , "BlueprintUnpublished" )
121
+ }
77
122
payload , err := json .Marshal (data )
78
123
if err != nil {
79
- log .Fatalf ("impossible to marshall update space request: %s" , err )
124
+ log .Fatalf ("impossible to marshall space notification request: %s" , err )
80
125
}
81
126
82
127
req , err := http .NewRequest ("POST" , fmt .Sprintf ("%sapi/spaces/%s/subscriptions" , c .HostURL , space_name ), bytes .NewReader (payload ))
@@ -95,19 +140,54 @@ func (c *Client) CreateSpaceEmailNotification(space_name string, notification_na
95
140
return string (body ), nil
96
141
}
97
142
98
- func (c * Client ) UpdateSpaceEmailNotification (notification_id string , space_name string , notification_name string , environment_launched bool ,
143
+ func (c * Client ) UpdateSpaceNotification (notification_id string , notification_type string , space_name string , notification_name string , environment_launched bool ,
99
144
environment_deployed bool , environment_force_ended bool , environment_idle bool , environment_extended bool ,
100
145
drift_detected bool , workflow_failed bool , workflow_started bool , updates_detected bool ,
101
146
collaborator_added bool , action_failed bool , environment_ending_failed bool , environment_ended bool ,
102
- environment_active_with_error bool , workflow_start_reminder int64 , end_threshold int64 , idle_reminder []int64 ) (string , error ) {
147
+ environment_active_with_error bool , workflow_start_reminder int64 , end_threshold int64 , blueprint_published bool , blueprint_unpublished bool , idle_reminder []int64 , webhook * string , token * string ) (string , error ) {
103
148
104
- data := SubscriptionsRequest {
105
- Name : notification_name ,
106
- Description : "" ,
107
- Target : SubscriptionsTargetRequest {
108
- Type : "Email" ,
149
+ var data SubscriptionsRequest
150
+ switch notification_type {
151
+ case email_notification_type :
152
+ data = SubscriptionsRequest {
153
+ Name : notification_name ,
154
+ Description : "" ,
155
+ Target : SubscriptionsTargetRequest {
156
+ Type : email_notification_type ,
157
+ Description : "" ,
158
+ },
159
+ }
160
+ case slack_notification_type :
161
+ data = SubscriptionsRequest {
162
+ Name : notification_name ,
163
+ Description : "" ,
164
+ Target : SubscriptionsTargetRequest {
165
+ Type : slack_notification_type ,
166
+ Description : "" ,
167
+ WebHook : webhook ,
168
+ },
169
+ }
170
+ case teams_notification_type :
171
+ data = SubscriptionsRequest {
172
+ Name : notification_name ,
109
173
Description : "" ,
110
- },
174
+ Target : SubscriptionsTargetRequest {
175
+ Type : teams_notification_type ,
176
+ Description : "" ,
177
+ WebHook : webhook ,
178
+ },
179
+ }
180
+ case webhook_notification_type :
181
+ data = SubscriptionsRequest {
182
+ Name : notification_name ,
183
+ Description : "" ,
184
+ Target : SubscriptionsTargetRequest {
185
+ Type : webhook_notification_type ,
186
+ Description : "" ,
187
+ WebHook : webhook ,
188
+ Token : token ,
189
+ },
190
+ }
111
191
}
112
192
113
193
if environment_launched {
@@ -160,7 +240,12 @@ func (c *Client) UpdateSpaceEmailNotification(notification_id string, space_name
160
240
if environment_active_with_error {
161
241
data .Events = append (data .Events , "EnvironmentActiveWithError" )
162
242
}
163
-
243
+ if blueprint_published {
244
+ data .Events = append (data .Events , "BlueprintPublished" )
245
+ }
246
+ if blueprint_unpublished {
247
+ data .Events = append (data .Events , "BlueprintUnpublished" )
248
+ }
164
249
payload , err := json .Marshal (data )
165
250
if err != nil {
166
251
log .Fatalf ("impossible to marshall update space request: %s" , err )
0 commit comments