add basic CUE definitions of Caddy config structure #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Warning: I'm building this as I'm learning/exploring CUE. It is very likely it's not done with best practices. Review/guidance is very welcome and needed!
This seems to work... to a point. The two sample config files I'm using exhibit 2 behaviors:
1- One seems to work fine and filled with default values for missing fields
2- The other.... causes CUE to panic with stack overflow (I know the change that caused it to start panicking)
Successful
Running
cue eval *.cue -d Config --out json caddy.jsonagainst this config:{ "apps": { "http": { "servers": { "srv0": { "listen": [ ":8080" ], "routes": [ { "match": [ { "host": [ "localhost" ], "path": [ "/my-path" ] } ], "handle": [ { "handler": "static_response", "status_code": "200", "body": "Hello!" } ] }, { "handle": [ { "handler": "reverse_proxy", "transport": { "protocol": "http" }, "circuit_breaker": { "type": "internal" }, "upstreams": [ { "dial": "tcp/10.1.1.1:2020", "max_requests": 5 }, { "dial": "tcp/10.1.1.1:2121", "max_requests": 5 } ] } ] } ] }, "srv1": { "listen": [ ":9090" ], "routes": [ { "handle": [ { "handler": "static_response", "status_code": "200", "body": "Hello!" } ] } ] } } } } }{ "admin": { "disabled": false, "listen": "localhost:2019", "enforce_origin": false, "config": { "persist": true } }, "apps": { "http": { "servers": { "srv0": { "listen": [ ":8080" ], "routes": [ { "match": [ { "path": [ "/my-path" ], "host": [ "localhost" ] } ], "handle": [ { "body": "Hello!", "handler": "static_response", "status_code": "200" } ] }, { "handle": [ { "handler": "reverse_proxy", "transport": { "protocol": "http" }, "circuit_breaker": { "type": "internal", "factor": "latency", "trip_time": "5s" }, "upstreams": [ { "dial": "tcp/10.1.1.1:2020", "max_requests": 5 }, { "dial": "tcp/10.1.1.1:2121", "max_requests": 5 } ], "buffer_requests": false } ] } ] }, "srv1": { "listen": [ ":9090" ], "routes": [ { "handle": [ { "body": "Hello!", "handler": "static_response", "status_code": "200" } ] } ] } } } } }Failed
Running
cue eval *.cue -d Config --out json caddy.jsonagainst this config:{ "admin": { "disabled": false, "enforce_origin": false }, "logging": { "logs": { "log0": { "writer": { "output": "discard" }, "encoder": { "format": "json", "message_key": "some_key" } } } }, "apps": { "http": { "servers": { "srv0": { "listen": [ "80", "443" ], "routes": [ { "handle": [ { "handler": "static_response", "status_code": "200", "body": "Hello!" } ] } ] }, "srv1": { "listen": [ "80", "443" ], "routes": [ { "handle": [ { "handler": "static_response", "status_code": "200", "body": "Hello!" } ] } ] } } } } }Results in this output:
Removing the default indicator
*from*"json"and*KeyedEncoderinlog.cueresolves the stack overflow.