LBF38 / obsidian-syncthing-integration

Obsidian plugin for Syncthing integration
MIT License
185 stars 6 forks source link

[FEATURE] Multiple Syncthing configurations/API keys #216

Open Mikle-Bond opened 5 months ago

Mikle-Bond commented 5 months ago

Problem

Obsidian+Syncthing setup almost always implies using both on multiple devices, with Syncthing installed and configured to accept API calls using different API keys. Assuming that plugin's configuration also synchronizes between devices, all plugins instances will use the same URI/API key combination to connect. This means that setting up the plugin on one device correctly leads to HTTP 403 errors on all the other devices.

Mitigations

Same API key

It is possible to configure all ST instances to use same API key.

Pro: this is relatively easy to do via WebUI of ST.

Cons:

Disabling plugin configuration synchronization

My assumption was that Obsidian vault is synchronized as is, with all plugins's config syncing too. This can be disabled via .stignore, and then plugin can be configured on every device individually.

Pros: Still relatively easy to do. Though explaining it in the documentation will require more effort, I think.

Cons:

Solution

Store multiple configurations instances. Pick the one that is used on this device.

For example, https://github.com/soberhacker/obsidian-telegram-sync is a plugin that also distinguishes between devices. It uses node-machine-id package to do so. And we could do the same, or perhaps machine-id2 package for Android support.

I believe this can be done without changing settings UI, or with slight mention of current device id. As for internal config structure - just store config as a dictionary, where keys are machine ids, and values have the same config structure as it is now. Example config structure:

{
  "config-version": 2,
  "instances": {
    "632b60c5-79db-4a5b-ae69-cc2d6de12676": {
      "configuration": {
        "url": {
          "protocol": "http",
          "ip_address": "localhost",
          "port": 8384
        }
      },
      "devMode": false,
      "api_key": "oogaexaiwiujibaeshoaquaghahteisu",
      "gui_username": "mikle_bond",
      "gui_password": "QXl5eSBwYXNzd29yZAo="
    },
    "00b8ad5f-77b0-4f5e-a44a-1e1cb678543f": {
      "configuration": {
        "url": {
          "protocol": "https",
          "ip_address": "localhost",
          "port": 443
        }
      },
      "devMode": true,
      "api_key": "iawPDkvjh9gR5nlPc4YnZuTBjO9iWZYo",
      "gui_username": "user",
      "gui_password": "c2VjdXJlIHBhc3N3b3JkIHRoaXMgdGltZQo="
    }
  }
}