When using the China Network Enterprise feature and creating a custom SSL Certificate the Geo Key Manager feature is not supported.
Expected behavior
According to the API documentation the geo_restrictions property on the custom_certificates endpoint should be optional when creating a certificate via a POST request. I would expect that the below code has the output also shown below;
var opts cloudflare.ZoneCustomSSLOptions
opts.Certificate = "<certificate>"
opts.PrivateKey = "<private key>"
res, _ := json.Marshal(&opts)
log.Print(string(res))
// {
// "certificate": "<certificate>",
// "private_key": "<private key>",
// }
Current behavior
When not providing the geo_restrictions property the output of the object marshal includes it as shown below;
var opts cloudflare.ZoneCustomSSLOptions
opts.Certificate = "<certificate>"
opts.PrivateKey = "<private key>"
res, _ := json.Marshal(&opts)
log.Print(string(res))
// {
// "certificate": "<certificate>",
// "private_key": "<private key>",
// "geo_restrictions": { "label": ""}
// }
This happens because the ZoneCustomSSLGeoRestrictions property of the ZoneCustomSSLOptions struct is itself a struct and therefore never actually empty, causing the omitempty flag in the marshaler to never act as intended.
Possible solution
I believe there are two solutions to this issue, however the more correct solution is a breaking change so I'm going to propose (and also submit PRs for) both.
- change the
ZoneCustomSSLGeoRestrictions to be a pointer within the ZoneCustomSSLOptions struct. This would cause a breaking change, however is the much cleaner and more forwards compatible way to implement the fix.
- implement a custom marshaler for the
ZoneCustomSSLOptions struct to handle omiting the ZoneCustomSSLGeoRestrictions property if it's not set. This would be a non-breaking change but also require the maintenance of this custom marshaler if the properties of ZoneCustomSSLGeoRestrictions change.
Steps to reproduce (for bugs)
- Setup a Cloudflare Zone with the China Network enabled.
- Fill in the placeholders and run the below code snippet;
func main() {
apiKey := "<api key>"
apiEmail := "<api email>"
api, err := cloudflare.New(apiKey, apiEmail)
if err != nil {
log.Fatal(err)
}
var opts cloudflare.ZoneCustomSSLOptions
opts.Certificate = "<certificate>"
opts.PrivateKey = "<private key>"
api.CreateSSL("<zone id>", opts)
}
- you will receive the below error;
error from makeRequest: HTTP status 400: content "{\"success\":false,\"errors\":[{\"code\":1232,\"message\":\"Geo Key Manager is not supported while using the China network\"}],\"messages\":[],\"result\":null}"
Context
As an enterprise customer this is preventing us from managing our Cloudflare infrastructure via Terraform as this library is used within the Cloudflare Terraform Provider.
Your Environment
- v0.11.7 - still present on master
When using the China Network Enterprise feature and creating a custom SSL Certificate the Geo Key Manager feature is not supported.
Expected behavior
According to the API documentation the
geo_restrictionsproperty on the custom_certificates endpoint should be optional when creating a certificate via a POST request. I would expect that the below code has the output also shown below;Current behavior
When not providing the
geo_restrictionsproperty the output of the object marshal includes it as shown below;This happens because the
ZoneCustomSSLGeoRestrictionsproperty of theZoneCustomSSLOptionsstruct is itself a struct and therefore never actually empty, causing theomitemptyflag in the marshaler to never act as intended.Possible solution
I believe there are two solutions to this issue, however the more correct solution is a breaking change so I'm going to propose (and also submit PRs for) both.
ZoneCustomSSLGeoRestrictionsto be a pointer within theZoneCustomSSLOptionsstruct. This would cause a breaking change, however is the much cleaner and more forwards compatible way to implement the fix.ZoneCustomSSLOptionsstruct to handle omiting theZoneCustomSSLGeoRestrictionsproperty if it's not set. This would be a non-breaking change but also require the maintenance of this custom marshaler if the properties ofZoneCustomSSLGeoRestrictionschange.Steps to reproduce (for bugs)
error from makeRequest: HTTP status 400: content "{\"success\":false,\"errors\":[{\"code\":1232,\"message\":\"Geo Key Manager is not supported while using the China network\"}],\"messages\":[],\"result\":null}"Context
As an enterprise customer this is preventing us from managing our Cloudflare infrastructure via Terraform as this library is used within the Cloudflare Terraform Provider.
Your Environment