2factorauth / twofactorauth

List of sites with two factor auth support which includes SMS, email, phone calls, hardware, and software.
https://2fa.directory
Other
3.37k stars 1.77k forks source link

Suites Schema #6185

Open ApCoder123 opened 2 years ago

ApCoder123 commented 2 years ago

Relates to #3708, #3707, #4510, https://github.com/2factorauth/twofactorauth/pull/4034#issuecomment-566500921

In the original discussions in the above issues about allowing entries in multiple categories, there was some mention of creating a single file for products that come under a central brand (e.g. Google). I've been playing around with this idea, and I think the schema could be modified to support this without many changes to the existing codebase.

Example JSON file for a suite entry:

{
  "Google": {
    "suite": true,
    "tfa": [
      "sms",
      "call",
      "totp",
      "custom-software",
      "u2f"
    ],
    "documentation": "https://www.google.com/intl/en-US/landing/2step/features.html",
    "sites": [
      {
        "Google Chat": {
          "domain": "chat.google.com",
          "keywords": [
            "communication"
          ]
        }
      },
      {
        "Google Drive": {
          "domain": "drive.google.com",
          "keywords": [
            "backup"
          ]
        }
      }
    ]
  }
}

The join-entries.rb script could then be modified to expand a suite entry's sites into individual entries in the entries array, meaning the current code for the site would receive the data in the same way as it does now. Something like:

Dir.glob('entries/*/*.json') do |file|
  document = JSON.parse(File.read(file))
  suite = document.values[0]
  suite_name = document.keys[0]
  next unless suite.key? 'suite'

  suite['sites'].each do |site|

    suite.each do |k, v|
      next if k.eql?('sites') || k.eql?('suite')
      site.values[0][k] = v unless site.key? k
    end
    site['search'] = [suite_name]

    entries[site.keys[0]] = site.values[0]
  end
end

This would make brands with multiple sites much easier to edit, as only one entry needs to be changed, rather than multiple. Additionally, adding a search key will allow the main brand name (e.g. Google) to be added to the search words in the table (making the connection between products clearer, fixing #4510).

The only other change to the code would be to get the API scripts to use _data/all.json which has the expanded suite sites array instead of iterating the entries directory as they do currently.

Any thoughts?

phallobst commented 2 years ago

Sounds good and addresses quite a number of issues and shortcomings.

The "suite": true, is probably not necessary, since an existing "sites": will already indicate an entry of this kind.