Skip to content

Commit 55089cc

Browse files
authored
fix: Ignore name attribute in issue alert conditions (#483)
1 parent 1004388 commit 55089cc

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ require (
2424
github.com/mitchellh/mapstructure v1.5.0 // indirect
2525
github.com/yuin/goldmark v1.6.0 // indirect
2626
github.com/yuin/goldmark-meta v1.1.0 // indirect
27-
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect
28-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
27+
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
28+
golang.org/x/tools v0.24.0 // indirect
2929
gopkg.in/yaml.v2 v2.3.0 // indirect
3030
)
3131

@@ -80,8 +80,8 @@ require (
8080
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
8181
github.com/zclconf/go-cty v1.15.0 // indirect
8282
golang.org/x/crypto v0.26.0 // indirect
83-
golang.org/x/mod v0.19.0 // indirect
84-
golang.org/x/net v0.25.0 // indirect
83+
golang.org/x/mod v0.20.0 // indirect
84+
golang.org/x/net v0.28.0 // indirect
8585
golang.org/x/sys v0.23.0 // indirect
8686
golang.org/x/text v0.17.0 // indirect
8787
google.golang.org/appengine v1.6.8 // indirect

go.sum

+7
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,15 @@ golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
261261
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
262262
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U=
263263
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
264+
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
265+
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
264266
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
265267
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
266268
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
267269
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
268270
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
271+
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
272+
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
269273
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
270274
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
271275
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -275,6 +279,8 @@ golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
275279
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
276280
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
277281
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
282+
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
283+
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
278284
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
279285
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
280286
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
@@ -335,6 +341,7 @@ golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY=
335341
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=
336342
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
337343
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
344+
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
338345
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
339346
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
340347
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=

internal/provider/resource_issue_alert.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ Please note the following changes since v0.12.0:
137137
"conditions": schema.StringAttribute{
138138
MarkdownDescription: "List of conditions. In JSON string format.",
139139
Required: true,
140-
CustomType: sentrytypes.LossyJsonType{},
140+
CustomType: sentrytypes.LossyJsonType{
141+
IgnoreKeys: []string{"name"},
142+
},
141143
},
142144
"filters": schema.StringAttribute{
143145
MarkdownDescription: "A list of filters that determine if a rule fires after the necessary conditions have been met. In JSON string format.",

internal/provider/resource_issue_alert_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ resource "sentry_issue_alert" "test" {
374374
conditions = <<EOT
375375
[
376376
{
377-
"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition"
377+
"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition",
378+
"name": "ignored"
378379
},
379380
{
380381
"id": "sentry.rules.conditions.regression_event.RegressionEventCondition"

internal/sentrytypes/lossy_json_type.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ var _ basetypes.StringTypable = (*LossyJsonType)(nil)
1616

1717
type LossyJsonType struct {
1818
basetypes.StringType
19+
20+
IgnoreKeys []string
1921
}
2022

2123
func (t LossyJsonType) String() string {
2224
return "sentrytypes.LossyJsonType"
2325
}
2426

2527
func (t LossyJsonType) ValueType(_ context.Context) attr.Value {
26-
return LossyJson{}
28+
return LossyJson{
29+
IgnoreKeys: t.IgnoreKeys,
30+
}
2731
}
2832

2933
func (t LossyJsonType) Equal(o attr.Type) bool {
@@ -88,6 +92,7 @@ func (t LossyJsonType) Validate(ctx context.Context, in tftypes.Value, path path
8892
func (t LossyJsonType) ValueFromString(ctx context.Context, in basetypes.StringValue) (basetypes.StringValuable, diag.Diagnostics) {
8993
return LossyJson{
9094
StringValue: in,
95+
IgnoreKeys: t.IgnoreKeys,
9196
}, nil
9297
}
9398

internal/sentrytypes/lossy_json_value.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"slices"
78
"strings"
89

910
"github.com/hashicorp/terraform-plugin-framework/attr"
@@ -16,6 +17,8 @@ var _ basetypes.StringValuableWithSemanticEquals = (*LossyJson)(nil)
1617

1718
type LossyJson struct {
1819
basetypes.StringValue
20+
21+
IgnoreKeys []string
1922
}
2023

2124
func (v LossyJson) Type(_ context.Context) attr.Type {
@@ -48,7 +51,7 @@ func (v LossyJson) StringSemanticEquals(_ context.Context, newValuable basetypes
4851
return false, diags
4952
}
5053

51-
result, err := lossyJsonEqual(newValue.ValueString(), v.ValueString())
54+
result, err := lossyJsonEqual(newValue.ValueString(), v.ValueString(), v.IgnoreKeys)
5255

5356
if err != nil {
5457
diags.AddError(
@@ -64,7 +67,7 @@ func (v LossyJson) StringSemanticEquals(_ context.Context, newValuable basetypes
6467
return result, diags
6568
}
6669

67-
func lossyJsonEqual(s1, s2 string) (bool, error) {
70+
func lossyJsonEqual(s1, s2 string, ignoreKeys []string) (bool, error) {
6871
v1, err := decodeJson(s1)
6972
if err != nil {
7073
return false, err
@@ -75,7 +78,7 @@ func lossyJsonEqual(s1, s2 string) (bool, error) {
7578
return false, err
7679
}
7780

78-
return deepLossyEqual(v1, v2), nil
81+
return deepLossyEqual(v1, v2, ignoreKeys), nil
7982
}
8083

8184
func decodeJson(s string) (interface{}, error) {
@@ -90,7 +93,7 @@ func decodeJson(s string) (interface{}, error) {
9093
return v, nil
9194
}
9295

93-
func deepLossyEqual(v1, v2 interface{}) bool {
96+
func deepLossyEqual(v1, v2 interface{}, ignoreKeys []string) bool {
9497
switch v1 := v1.(type) {
9598
case bool:
9699
v2, ok := v2.(bool)
@@ -127,7 +130,7 @@ func deepLossyEqual(v1, v2 interface{}) bool {
127130
}
128131

129132
for i := 0; i < len(v1); i++ {
130-
if !deepLossyEqual(v1[i], v2[i]) {
133+
if !deepLossyEqual(v1[i], v2[i], ignoreKeys) {
131134
return false
132135
}
133136
}
@@ -145,12 +148,16 @@ func deepLossyEqual(v1, v2 interface{}) bool {
145148

146149
// Check that all keys in v1 are in v2 but not the other way around (lossy)
147150
for k := range v1 {
151+
if slices.Contains(ignoreKeys, k) {
152+
continue
153+
}
154+
148155
v2Val, ok := v2[k]
149156
if !ok {
150157
return false
151158
}
152159

153-
if !deepLossyEqual(v1[k], v2Val) {
160+
if !deepLossyEqual(v1[k], v2Val, ignoreKeys) {
154161
return false
155162
}
156163
}

0 commit comments

Comments
 (0)