Server(url, oauth, basic) => Server(env)

Bug #837944 reported by Jason Gerard DeRose
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Microfiber
Fix Released
High
Jason Gerard DeRose

Bug Description

The tricky thing about desktopcouch is that things like the port and oauth tokens are different each session. And the trickier thing about the Novacut components is that they need to run against both desktopcouch and system wide CouchDB without knowing the difference.

I've spent a lot of time trying to find the right abstractions to allow this to work nicely. First I tried API abstractions, but after much thought, I think the correct abstraction is a simple, extensible data structure, the `env` dictionary I've been using all over the place.

The idea is that this `env` can describe both the system-wide CouchDB environment and the desktopcouch environment, and is extensible so we can add things we haven't thought of yet. Importantly, we want to be able add things to the `env` and have all the intermediary code still just blindly pass around this single `env` variable. Only two places need to know the details, the entry point that starts the process, and where the rubber meets the CouchDB road: Microfiber!

For example, the `env` for system-wide CouchDB looks like this:

{
    "url": "http://localhost:5984/"
}

And the `env` for desktopcouch/dc3 would look something like this:

{
    "basic": {
        "password": "5GF2HP7SRPVB6HY2",
        "username": "QOZ525Z5RXP7AO4C"
    },
    "oauth": {
        "consumer_key": "P24WX2CXY53TOC4J",
        "consumer_secret": "4BCN54VO47AYTPV3",
        "token": "6745HGQJLNHUQG2E",
        "token_secret": "ZKFGZMWMCFELSNTQ"
    },
    "url": "http://localhost:40658/"
}

So I think Microfiber should use the same extensible convention. Currently Microfiber supports oauth and basic auth (with keyword arguments for each), but what if we need to add support for oauth2? So I'm proposing we change the __init__() signatures from:

Server(url, oauth, basic)
Database(name, url, oauth, basic)

To:

Server(env)
Database(name, env)

That way the code in, say, dmedia, can just blindly pass microfiber the env and be completely hidden from the details. This is a good abstraction and will reduce the code and complexity needed in the middle.

Related branches

Changed in microfiber:
status: In Progress → Fix Committed
Changed in microfiber:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.