Skip to content

Commit b1d4bea

Browse files
authored
refactor(notificationchannels): refactor secure notification channels to use v2 client (#309)
* refactor(notificationchannels): refactor secure notification channels to v2 client * refactor(notificationchannels): remove unused code from secure models
1 parent 3593fdb commit b1d4bea

19 files changed

+66
-411
lines changed

sysdig/data_source_sysdig_secure_notification_channel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func dataSourceSysdigSecureNotificationChannel() *schema.Resource {
106106

107107
// Retrieves the information of a resource form the file and loads it in Terraform
108108
func dataSourceSysdigNotificationChannelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
109-
client, err := meta.(SysdigClients).sysdigSecureClient()
109+
client, err := getSecureNotificationChannelClient(meta.(SysdigClients))
110110
if err != nil {
111111
return diag.FromErr(err)
112112
}

sysdig/internal/client/secure/client.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ type SysdigSecureClient interface {
2222
UpdateRule(context.Context, Rule) (Rule, error)
2323
DeleteRule(context.Context, int) error
2424

25-
CreateNotificationChannel(context.Context, NotificationChannel) (NotificationChannel, error)
26-
GetNotificationChannelById(context.Context, int) (NotificationChannel, error)
27-
GetNotificationChannelByName(context.Context, string) (NotificationChannel, error)
28-
DeleteNotificationChannel(context.Context, int) error
29-
UpdateNotificationChannel(context.Context, NotificationChannel) (NotificationChannel, error)
30-
3125
CreateList(context.Context, List) (List, error)
3226
GetListById(context.Context, int) (List, error)
3327
DeleteList(context.Context, int) error

sysdig/internal/client/secure/models.go

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -42,84 +42,6 @@ func PolicyFromJSON(body []byte) (result Policy) {
4242
return result
4343
}
4444

45-
// -------- User Rules File --------
46-
47-
type UserRulesFile struct {
48-
Content string `json:"content"`
49-
Version int `json:"version"`
50-
}
51-
52-
type userRulesFileWrapper struct {
53-
UserRulesFile UserRulesFile `json:"userRulesFile"`
54-
}
55-
56-
func (userRulesFile *UserRulesFile) ToJSON() io.Reader {
57-
payload, _ := json.Marshal(userRulesFileWrapper{*userRulesFile})
58-
return bytes.NewBuffer(payload)
59-
}
60-
61-
func UserRulesFileFromJSON(body []byte) UserRulesFile {
62-
var result userRulesFileWrapper
63-
_ = json.Unmarshal(body, &result)
64-
65-
return result.UserRulesFile
66-
}
67-
68-
// -------- Notification Channels --------
69-
70-
type NotificationChannelOptions struct {
71-
EmailRecipients []string `json:"emailRecipients,omitempty"` // Type: email
72-
SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS
73-
APIKey string `json:"apiKey,omitempty"` // Type: VictorOps, OpsGenie
74-
RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps
75-
Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook and Slack
76-
Channel string `json:"channel,omitempty"` // Type: Slack
77-
Account string `json:"account,omitempty"` // Type: PagerDuty
78-
ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty
79-
ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty
80-
Region string `json:"region,omitempty"` // Type: OpsGenie
81-
82-
NotifyOnOk bool `json:"notifyOnOk"`
83-
NotifyOnResolve bool `json:"notifyOnResolve"`
84-
SendTestNotification bool `json:"sendTestNotification"`
85-
}
86-
87-
type NotificationChannel struct {
88-
ID int `json:"id,omitempty"`
89-
Version int `json:"version,omitempty"`
90-
Type string `json:"type"`
91-
Name string `json:"name"`
92-
Enabled bool `json:"enabled"`
93-
Options NotificationChannelOptions `json:"options"`
94-
}
95-
96-
func (n *NotificationChannel) ToJSON() io.Reader {
97-
payload, _ := json.Marshal(notificationChannelWrapper{*n})
98-
return bytes.NewBuffer(payload)
99-
}
100-
101-
func NotificationChannelFromJSON(body []byte) NotificationChannel {
102-
var result notificationChannelWrapper
103-
_ = json.Unmarshal(body, &result)
104-
105-
return result.NotificationChannel
106-
}
107-
108-
func NotificationChannelListFromJSON(body []byte) []NotificationChannel {
109-
var result notificationChannelListWrapper
110-
_ = json.Unmarshal(body, &result)
111-
112-
return result.NotificationChannels
113-
}
114-
115-
type notificationChannelListWrapper struct {
116-
NotificationChannels []NotificationChannel `json:"notificationChannels"`
117-
}
118-
119-
type notificationChannelWrapper struct {
120-
NotificationChannel NotificationChannel `json:"notificationChannel"`
121-
}
122-
12345
// -------- Rules --------
12446

12547
type Rule struct {
@@ -265,61 +187,6 @@ func MacroFromJSON(body []byte) (macro Macro, err error) {
265187
return
266188
}
267189

268-
// -------- Team --------
269-
type Team struct {
270-
ID int `json:"id,omitempty"`
271-
Version int `json:"version,omitempty"`
272-
Theme string `json:"theme"`
273-
Name string `json:"name"`
274-
Description string `json:"description"`
275-
ScopeBy string `json:"show"`
276-
Filter string `json:"filter"`
277-
CanUseSysdigCapture bool `json:"canUseSysdigCapture"`
278-
UserRoles []UserRoles `json:"userRoles,omitempty"`
279-
DefaultTeam bool `json:"default"`
280-
Products []string `json:"products"`
281-
}
282-
283-
type UserRoles struct {
284-
UserId int `json:"userId"`
285-
Email string `json:"userName,omitempty"`
286-
Role string `json:"role"`
287-
Admin bool `json:"admin,omitempty"`
288-
}
289-
290-
func (t *Team) ToJSON() io.Reader {
291-
payload, _ := json.Marshal(*t)
292-
return bytes.NewBuffer(payload)
293-
}
294-
295-
func TeamFromJSON(body []byte) Team {
296-
var result teamWrapper
297-
_ = json.Unmarshal(body, &result)
298-
299-
return result.Team
300-
}
301-
302-
type teamWrapper struct {
303-
Team Team `json:"team"`
304-
}
305-
306-
// -------- UsersList --------
307-
type UsersList struct {
308-
ID int `json:"id"`
309-
Email string `json:"username"`
310-
}
311-
312-
func UsersListFromJSON(body []byte) []UsersList {
313-
var result usersListWrapper
314-
_ = json.Unmarshal(body, &result)
315-
316-
return result.UsersList
317-
}
318-
319-
type usersListWrapper struct {
320-
UsersList []UsersList `json:"users"`
321-
}
322-
323190
// -------- VulnerabilityExceptionList --------
324191

325192
type VulnerabilityExceptionList struct {
@@ -389,35 +256,6 @@ func CloudAccountFromJSON(body []byte) *CloudAccount {
389256
return &result
390257
}
391258

392-
// -------- BenchmarkTask --------
393-
394-
var SupportedBenchmarkTaskSchemas = []string{
395-
"aws_foundations_bench-1.3.0",
396-
"gcp_foundations_bench-1.2.0",
397-
"azure_foundations_bench-1.3.0",
398-
}
399-
400-
type BenchmarkTask struct {
401-
ID int `json:"id,omitempty"`
402-
Name string `json:"name"`
403-
Schema string `json:"schema"`
404-
Scope string `json:"scope"`
405-
Schedule string `json:"schedule"`
406-
Enabled bool `json:"enabled"`
407-
}
408-
409-
func (t *BenchmarkTask) ToJSON() io.Reader {
410-
payload, _ := json.Marshal(*t)
411-
return bytes.NewBuffer(payload)
412-
}
413-
414-
func BenchmarkTaskFromJSON(body []byte) *BenchmarkTask {
415-
var result BenchmarkTask
416-
_ = json.Unmarshal(body, &result)
417-
418-
return &result
419-
}
420-
421259
// -------- Scanning Policies --------
422260
type ScanningPolicy struct {
423261
ID string `json:"id,omitempty"`

sysdig/internal/client/secure/notification_channels.go

Lines changed: 0 additions & 111 deletions
This file was deleted.

sysdig/resource_sysdig_secure_notification_channel_common.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package sysdig
22

33
import (
4+
v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
45
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
5-
6-
"github.com/draios/terraform-provider-sysdig/sysdig/internal/client/secure"
76
)
87

98
func createSecureNotificationChannelSchema(original map[string]*schema.Schema) map[string]*schema.Schema {
@@ -42,11 +41,11 @@ func createSecureNotificationChannelSchema(original map[string]*schema.Schema) m
4241
return notificationChannelSchema
4342
}
4443

45-
func secureNotificationChannelFromResourceData(d *schema.ResourceData) (nc secure.NotificationChannel, err error) {
46-
nc = secure.NotificationChannel{
44+
func secureNotificationChannelFromResourceData(d *schema.ResourceData) (nc v2.NotificationChannel, err error) {
45+
nc = v2.NotificationChannel{
4746
Name: d.Get("name").(string),
4847
Enabled: d.Get("enabled").(bool),
49-
Options: secure.NotificationChannelOptions{
48+
Options: v2.NotificationChannelOptions{
5049
NotifyOnOk: d.Get("notify_when_ok").(bool),
5150
NotifyOnResolve: d.Get("notify_when_resolved").(bool),
5251
SendTestNotification: d.Get("send_test_notification").(bool),
@@ -55,7 +54,7 @@ func secureNotificationChannelFromResourceData(d *schema.ResourceData) (nc secur
5554
return
5655
}
5756

58-
func secureNotificationChannelToResourceData(nc *secure.NotificationChannel, data *schema.ResourceData) (err error) {
57+
func secureNotificationChannelToResourceData(nc *v2.NotificationChannel, data *schema.ResourceData) (err error) {
5958
_ = data.Set("version", nc.Version)
6059
_ = data.Set("name", nc.Name)
6160
_ = data.Set("enabled", nc.Enabled)
@@ -65,3 +64,7 @@ func secureNotificationChannelToResourceData(nc *secure.NotificationChannel, dat
6564

6665
return
6766
}
67+
68+
func getSecureNotificationChannelClient(c SysdigClients) (v2.NotificationChannelInterface, error) {
69+
return c.sysdigSecureClientV2()
70+
}

0 commit comments

Comments
 (0)