@@ -20,10 +20,10 @@ var _ NotificationConfigurations = (*notificationConfigurations)(nil)
20
20
// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/notification-configurations
21
21
type NotificationConfigurations interface {
22
22
// List all the notification configurations within a workspace.
23
- List (ctx context.Context , workspaceID string , options * NotificationConfigurationListOptions ) (* NotificationConfigurationList , error )
23
+ List (ctx context.Context , subscribableID string , options * NotificationConfigurationListOptions ) (* NotificationConfigurationList , error )
24
24
25
25
// Create a new notification configuration with the given options.
26
- Create (ctx context.Context , workspaceID string , options NotificationConfigurationCreateOptions ) (* NotificationConfiguration , error )
26
+ Create (ctx context.Context , subscribableID string , options NotificationConfigurationCreateOptions ) (* NotificationConfiguration , error )
27
27
28
28
// Read a notification configuration by its ID.
29
29
Read (ctx context.Context , notificationConfigurationID string ) (* NotificationConfiguration , error )
@@ -107,7 +107,7 @@ type NotificationConfiguration struct {
107
107
108
108
// Relations
109
109
// DEPRECATED. The subscribable field is polymorphic. Use NotificationConfigurationSubscribableChoice instead.
110
- Subscribable * Workspace `jsonapi:"relation,subscribable"`
110
+ Subscribable * Workspace `jsonapi:"relation,subscribable,omitempty "`
111
111
SubscribableChoice * NotificationConfigurationSubscribableChoice `jsonapi:"polyrelation,subscribable"`
112
112
113
113
EmailUsers []* User `jsonapi:"relation,users"`
@@ -128,7 +128,7 @@ type DeliveryResponse struct {
128
128
type NotificationConfigurationListOptions struct {
129
129
ListOptions
130
130
131
- SubscribableChoice * NotificationConfigurationSubscribableChoice `jsonapi:"polyrelation,subscribable"`
131
+ SubscribableChoice * NotificationConfigurationSubscribableChoice
132
132
}
133
133
134
134
// NotificationConfigurationCreateOptions represents the options for
@@ -204,18 +204,28 @@ type NotificationConfigurationUpdateOptions struct {
204
204
// List all the notification configurations associated with a workspace.
205
205
func (s * notificationConfigurations ) List (ctx context.Context , subscribableID string , options * NotificationConfigurationListOptions ) (* NotificationConfigurationList , error ) {
206
206
var u string
207
- if options == nil || options .SubscribableChoice == nil || options .SubscribableChoice .Workspace != nil {
208
- if ! validStringID (& subscribableID ) {
209
- return nil , ErrInvalidWorkspaceID
207
+ if options == nil {
208
+ options = & NotificationConfigurationListOptions {
209
+ SubscribableChoice : & NotificationConfigurationSubscribableChoice {
210
+ Workspace : & Workspace {ID : subscribableID },
211
+ },
210
212
}
211
- u = fmt .Sprintf ("workspaces/%s/notification-configurations" , url .PathEscape (subscribableID ))
212
- } else if options .SubscribableChoice .Team != nil {
213
+ } else if options .SubscribableChoice == nil {
214
+ options .SubscribableChoice = & NotificationConfigurationSubscribableChoice {
215
+ Workspace : & Workspace {ID : subscribableID },
216
+ }
217
+ }
218
+
219
+ if options .SubscribableChoice .Team != nil {
213
220
if ! validStringID (& subscribableID ) {
214
221
return nil , ErrInvalidTeamID
215
222
}
216
223
u = fmt .Sprintf ("teams/%s/notification-configurations" , url .PathEscape (subscribableID ))
217
224
} else {
218
- return nil , ErrInvalidNotificationConfigSubscribableChoice
225
+ if ! validStringID (& subscribableID ) {
226
+ return nil , ErrInvalidWorkspaceID
227
+ }
228
+ u = fmt .Sprintf ("workspaces/%s/notification-configurations" , url .PathEscape (subscribableID ))
219
229
}
220
230
221
231
req , err := s .client .NewRequest ("GET" , u , options )
@@ -229,6 +239,10 @@ func (s *notificationConfigurations) List(ctx context.Context, subscribableID st
229
239
return nil , err
230
240
}
231
241
242
+ for i := range ncl .Items {
243
+ backfillDeprecatedSubscribable (ncl .Items [i ])
244
+ }
245
+
232
246
return ncl , nil
233
247
}
234
248
@@ -270,6 +284,8 @@ func (s *notificationConfigurations) Create(ctx context.Context, subscribableID
270
284
return nil , err
271
285
}
272
286
287
+ backfillDeprecatedSubscribable (nc )
288
+
273
289
return nc , nil
274
290
}
275
291
@@ -394,6 +410,16 @@ func (o NotificationConfigurationUpdateOptions) valid() error {
394
410
return nil
395
411
}
396
412
413
+ func backfillDeprecatedSubscribable (notification * NotificationConfiguration ) {
414
+ if notification .Subscribable != nil || notification .SubscribableChoice == nil {
415
+ return
416
+ }
417
+
418
+ if notification .SubscribableChoice .Workspace != nil {
419
+ notification .Subscribable = notification .SubscribableChoice .Workspace
420
+ }
421
+ }
422
+
397
423
func validNotificationTriggerType (triggers []NotificationTriggerType ) bool {
398
424
for _ , t := range triggers {
399
425
switch t {
0 commit comments