syncthing-map icon indicating copy to clipboard operation
syncthing-map copied to clipboard

Consume config as JSON alternatively

Open acolomb opened this issue 2 years ago • 4 comments

This is an idea, you could optionally fill the data structures from a JSON representation of the config file. That's what the GUI uses to manage configuration, and could easily be downloaded as a file from a running instance, or even piped to syncthing-map directly.

That would give an easier / more standardized way of retrieving the config from remote devices.

Look at https://docs.syncthing.net/rest/system-config-get.html for what the JSON looks like. It is serialized from the same Go structures as the XML format (actually with a common protobuf definition), so you can definitely parse it with your existing structures as well with maybe some JSON-specific annotations.

acolomb avatar Jan 08 '23 22:01 acolomb

(...) and could easily be downloaded as a file from a running instance, or even piped to syncthing-map directly.

That would give an easier / more standardized way of retrieving the config from remote devices.

I had a look at the API, I wanted to use it initially instead of the XML. The problem I have is that this is an endpoint local to the network (at best) so reaching it from outside that network is difficult (port forwarding, ...) or impossible (Android).

This is the reason I went for parsing config.xml directly (after having retrieved it one way or another) but I would be glad to be corrected if my understanding is incorrect.

I also contemplated running syncting-map locally, retrieving config.xml, parsing it, and then sending it to a centralized syncthing-map instance and automatically generating an updated map. This is not going to be easy on Android.

Ultimately, I also considered (and still consider) sharing config.xml via the normal sharing features and processing the changes automatically. This requires extra sharing, though.

Anyway, I am really open to suggestions.

wsw70 avatar Jan 09 '23 13:01 wsw70

Well my thought was that having access to config.xml OR the API is a thing the user will need to take care of one way or another. I personally would probably favor tunneling the API port through SSH and accessing the config from there, piped directly to a local syncthing-map read --json process. I find that more appealing than copying XML files around through the same SSH setup. If the API ports are accessible from remote directly, it gets even easier.

I wouldn't actually consider syncing the config files permanently (since they all have the same name for example), and running the mapper is a not a continuous process either.

Anyway, I think the additional flexibility outweighs the relatively simple implementation of adding a command line switch and annotating the structs with JSON attributes. I might have a stab at doing a PR for this when time allows and you don't beat me to it :wink:

acolomb avatar Jan 09 '23 15:01 acolomb

I personally would probably favor tunneling the API port through SSH and accessing the config from there, piped directly to a local syncthing-map read --json process.

Yes, this is a solution, but it will be limited to devices that offer an ssh endpoint - which mostly means Linux. Windows 10 would be possible by starting the services, and Android is really difficult because of sandboxing. I do not know about iOS but it will probably be even worse.

This ssh endpoint also needs to be available on the Internet (possibly from networks one does not control), or connected via something like Tailscale.

This is to say that yes, why not, but the useage may be somehow limited for the normal population.

wsw70 avatar Jan 09 '23 16:01 wsw70

You may want to try the new ~~experimental~~ feature server

Binaries are available in the ~~development~~ stable release

wsw70 avatar Jan 10 '23 19:01 wsw70