jku / pip

pip fork to experiment with PEP-458 implementation https://www.python.org/dev/peps/pep-0458/: See branch tuf-v2 (and tuf-mvp and tuf-mvp-vendored for earlier work)
https://pip.pypa.io/
MIT License
1 stars 0 forks source link

snapshot of tuf integration branch (not a real PR) #10

Closed jku closed 4 years ago

jku commented 4 years ago

Foreword

This branch is very much a work in progress (full 10% of the lines are "TODO"): please don't review details, I'm just hoping to validate (or even just communicate) the high level ideas and maybe get some new insights at that level.

My current work is a little ahead of this branch but I think this is more useful for the purposes of discussion and this branch actually works (for pip install at least)...

I don't expect you to do this but if you do want to test:

Normal flow of the tuf-related code in "pip install sampleproject"

  1. A dictionary of updater objects is built during initialization (currently in SessionCommandMixin).
  2. When the dependency calculation needs an index file it ends up in LinkCollector._get_html_page(), this looks up an updater object based on the index url (currently quite unsafely), downloads the index file with tuf and returns the contents
  3. When distribution needs to be downloaded prepare.py:get_http_url() is called. This looks up an updater object based on "comes_from" field (which is the url of the index file this distribution url was found in), and downloads the target this url refers to

Open questions on the flow

Data storage

Cache is in ~/.cache/pip/. It's used as the tuf download location so contains everything ever downloaded with tuf

TUF metadata is in ~/.local/share/pip/.

Open questions on data storage

TUF updater abstraction in pip code

This is code in src/pip/_internal/network/tuf.py. The code badly needs better naming ('Updater' and 'tuf' names are used very confusingly) -- ideas are welcome.

But the basic design is simple:

So a user will first lookup the correct updater using the index_url of the repository, then call the download functions on that updater.

Open questions:

MVrachev commented 4 years ago

TUF updater abstraction in pip code

This is code in src/pip/_internal/network/tuf.py. The code badly needs better naming ('Updater' and 'tuf' names are used very confusingly) -- ideas are welcome.

Not perfect, but UpdaterHandler? I am using the same pattern when I manage the server processes in the tests in TUF server_handler as a variable name. Or maybe TufUpdater?

sechkova commented 4 years ago

For dummies (I tried the mock deployment in a new virtualenv):

but it worked like a charm (I think)

p.s. I know about it and I was still scared by the red text:

ERROR: Could not download URL: 'http://localhost:8000/tuf/3.root.json'
Traceback (most recent call last):
...
tuf.exceptions.NoWorkingMirrorError: No working mirror was found:
  'localhost:8000': HTTPError('404 Client Error: File not found for url: http://localhost:8000/tuf/3.root.json')