hujson icon indicating copy to clipboard operation
hujson copied to clipboard

Patching with comments

Open jspc opened this issue 3 weeks ago • 0 comments

Hey all- we're updating our tailnet config to have a posture/ grant per production device on our network, since we have a load of devices, and we don't want to manage this by hand, and because we want to use time-based/ device-based access.

It's working very nicely (loving the Value.Patch() function).

Is there anyway of patching in comments, too, outside of the patched in object? We still want people to be able to hand read/ review the policy, and being able to add comments would help that a lot.

If I set my patch like:

	err = v.Patch([]byte(`[
{"op": "add", "path": "/grants/0", "value":{
"src": ["autogroup:member"],
// My super duper device
"dst": ["ipset:super_duper_device"],
"srcPosture": ["posture:super_duper_device_TemporaryFullAccess"]}}
]`))
	if err != nil {
		panic(err)
	}

Then sure enough, I see:

        "grants": [                                                                                                                                                                           
                {                                                                                                                                                                             
                        "src": ["autogroup:member"],                                                                                                                                          
                        // My super duper device                                                                                                                                                   
                        "dst":        ["ipset:super_duper_device"],                                
                        "srcPosture": ["posture:super_duper_device_TemporaryFullAccess"],                                                                                                         
                },                                                                        

But if I move the comment outside of the block as per:

	err = v.Patch([]byte(`[
{"op": "add", "path": "/grants/0", "value":
// My super duper device
{
"src": ["autogroup:member"],
"dst": ["ipset:super_duper_device"],
"srcPosture": ["posture:super_duper_device_TemporaryFullAccess"]}}
]`))
	if err != nil {
		panic(err)
	}

Then the comment isn't persisted:

        "grants": [                                                                                                                                                                           
                {                                                                                                                                                                             
                        "src":        ["autogroup:member"],                                                                                                                                          
                        "dst":        ["ipset:super_duper_device"],                                
                        "srcPosture": ["posture:super_duper_device_TemporaryFullAccess"],                                                                                                         
                },                                                                        

jspc avatar Nov 27 '25 14:11 jspc