Skip to content

Commit

Permalink
fix: populate empty SNIs with an empty array
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hbagdi authored Mar 14, 2020
1 parent 86f2849 commit 0da5af9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions file/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
},
},
},
Expand All @@ -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{},
},
},
},
Expand Down

0 comments on commit 0da5af9

Please sign in to comment.