Skip to content

Commit 8552dd2

Browse files
hbagdiTravis Raines
authored and
Travis Raines
committed
fix: populate empty SNIs with an empty array
Kong returns back an empty JSON array instead of a `null` when the SNI array is empty: ``` { "data": [ { "cert": "-truncated-", "created_at": 1584219121, "id": "3e83146b-7139-4306-aa0c-f95ba3a9e315", "key": "-truncated-", "snis": [], "tags": null } ], "next": null } ``` Kong deviates from it's regular behavior of returning a `null`. This causes decK to detect a diff an existing and desired certificate because the two certificates have different empty SNIs, one has an empty array ([]*string{}) while the other is `nil`. This commit populates a nil SNIs field with an empty array. This bug only shows up when there are no SNIs associates with a certificate in Kong. Fix #131 From #132
1 parent 66f0478 commit 8552dd2

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

file/builder.go

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ func (b *stateBuilder) certificates() {
8383
}
8484
}
8585
utils.MustMergeTags(&c.Certificate, b.selectTags)
86+
if c.Certificate.SNIs == nil {
87+
c.Certificate.SNIs = []*string{}
88+
}
8689

8790
b.rawState.Certificates = append(b.rawState.Certificates,
8891
&c.Certificate)

file/builder_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ func Test_stateBuilder_certificates(t *testing.T) {
11751175
ID: kong.String("538c7f96-b164-4f1b-97bb-9f4bb472e89f"),
11761176
Cert: kong.String("foo"),
11771177
Key: kong.String("bar"),
1178+
SNIs: []*string{},
11781179
},
11791180
},
11801181
},
@@ -1200,6 +1201,7 @@ func Test_stateBuilder_certificates(t *testing.T) {
12001201
ID: kong.String("4bfcb11f-c962-4817-83e5-9433cf20b663"),
12011202
Cert: kong.String("foo"),
12021203
Key: kong.String("bar"),
1204+
SNIs: []*string{},
12031205
},
12041206
},
12051207
},

0 commit comments

Comments
 (0)