snapframework / snap

Top-level package for the official Snap Framework libraries, includes the snaplets API as well as infrastructure for sessions, auth, and templates.
http://snapframework.com/
BSD 3-Clause "New" or "Revised" License
455 stars 68 forks source link

Auth Snaplet users.json format change #214

Open imalsogreg opened 4 years ago

imalsogreg commented 4 years ago

At some point in the last several years, the format for users.json changed, specifically the uidCache field. The one in use by a deployment of https://github.com/imalsogreg/reffit several years old was encoded as:

{ uidCache:
  [
    [ 999,
      {
        "last_ip": null,
        "roles": [],
        "current_ip": "127.0.0.1",
        "activated_at": null,
        "reset_requested_at": null,
        "uid": "999",
         ...
        "login": "Interfacelea",
        "reset_token": null
      }
    ],
    ...
  ],
  ...
}

(id and info tuples were in a list of length-2 lists, not key-value entries in a map)

When I bumped snap to the most recent version, parsing failed because the new format is expected to be key-value pairs in a map:

{ uidCache:
  { "999":
    {
      "last_ip": null,
      "roles": [],
      "current_ip": "127.0.0.1",
      "activated_at": null,
      "reset_requested_at": null,
      "uid": "999",
       ...
      "login": "Interfacelea",
      "reset_token": null
    }
    ...
  },
  ...
}

Apologies for vagueness about the dates - I'd need to do some research to get more details.

If anyone else runs into this, the following jq call can do the migration:

jq '.uidCache = ([.uidCache[] | { "key": .[0], "value": .[1] }] | from_entries)' users.json
imalsogreg commented 4 years ago

We can fix this simply by adding another parser in the json-file auth backend.