From 7d82bf13041587cd289d78af3ffc18b8111eba1d Mon Sep 17 00:00:00 2001 From: Harry Date: Sat, 14 Mar 2020 14:20:53 -0700 Subject: [PATCH] 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 --- file/builder.go | 3 +++ file/builder_test.go | 2 ++ 2 files changed, 5 insertions(+) diff --git a/file/builder.go b/file/builder.go index 73f4562c4..2cb6255cc 100644 --- a/file/builder.go +++ b/file/builder.go @@ -83,6 +83,9 @@ func (b *stateBuilder) certificates() { } } utils.MustMergeTags(&c.Certificate, b.selectTags) + if c.Certificate.SNIs == nil { + c.Certificate.SNIs = []*string{} + } b.rawState.Certificates = append(b.rawState.Certificates, &c.Certificate) diff --git a/file/builder_test.go b/file/builder_test.go index 50933d364..17e4738c9 100644 --- a/file/builder_test.go +++ b/file/builder_test.go @@ -1175,6 +1175,7 @@ func Test_stateBuilder_certificates(t *testing.T) { ID: kong.String("538c7f96-b164-4f1b-97bb-9f4bb472e89f"), Cert: kong.String("foo"), Key: kong.String("bar"), + SNIs: []*string{}, }, }, }, @@ -1200,6 +1201,7 @@ func Test_stateBuilder_certificates(t *testing.T) { ID: kong.String("4bfcb11f-c962-4817-83e5-9433cf20b663"), Cert: kong.String("foo"), Key: kong.String("bar"), + SNIs: []*string{}, }, }, },