Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework README, prepare for packaging #2

Open
6 tasks
hugorodgerbrown opened this issue Jul 19, 2017 · 14 comments
Open
6 tasks

Rework README, prepare for packaging #2

hugorodgerbrown opened this issue Jul 19, 2017 · 14 comments
Assignees

Comments

@hugorodgerbrown
Copy link
Collaborator

hugorodgerbrown commented Jul 19, 2017

As discussed, I'd like this to stand out as a project for us - it's important that we can demonstrate that we take security seriously, and being able to point people at this is part of that. It needs to be in an 'auditable' state. This means a bunch of fixes:

  • Update README - h/t to the the original project, but this is now different enough
  • Remove support for python2 (no need, it's our project)
  • Remove support for django19 and below
  • Rework the tests to run the same way as all other YJ projects
  • Ensure test coverage is 100%
  • Ensure requirements are correct
@hugorodgerbrown hugorodgerbrown self-assigned this Jul 19, 2017
@hugorodgerbrown
Copy link
Collaborator Author

Need to simplify the project itself.

As I see it right now it consists of two separate, but linked, pieces - the backend that handles the security side - generating S3 authentication data and secure download links; and a Redux app that hooks into the Django endpoint and handles the file selection and upload.

Django:

  1. AJAX view used generate a secure request for the client
  2. Model field that uses a custom upload widget
  3. Custom TextInput widget that handles file selection and upload
  4. Functions for generating secure expiring links to uploaded files

Redux JS:

  1. Components for rendering the file picker and progress bar
  2. Handlers for calling the secure request AJAX view, posting the file to S3

@hugorodgerbrown
Copy link
Collaborator Author

@thealscott @ross - can you both confirm / deny what I've said above - am I understanding this project?

@thealscott
Copy link

@hugorodgerbrown that seems about right to me. Are you suggesting splitting them into two separate projects?

@hugorodgerbrown
Copy link
Collaborator Author

Possibly - depends on how tightly coupled they are. Does the bare field in the admin site require the redux app?

@hugorodgerbrown
Copy link
Collaborator Author

Looking further in to the matrix, I think there are two projects here. The first project is the Django endpoints required to support uploads and downloads to / from secure S3 buckets. This should have the minimal, unstyled, JS required to make it function. This project should be much smaller that it is currently - just the bare bones.

The Redux piece is really a separate project that happens to hook into the backend via the HTML (the CSS selectors have to match) - however, since the template can be overridden this is a very loose coupling. The Redux project should include the JS, CSS and a new template.

Practically speaking the redux piece could be inside the core platform project - it's quite specific to us.

@thealscott
Copy link

@hugorodgerbrown I don't think it is specific to the Platform, the Redux basically replicates the functionality of the old procedural script from before we branched, just using Redux paradigm to shift it to being declarative instead of imperative, and including some event dispatchers which allow external interfacing.

I would say most of it IS the bare minimum. You could strip out some of the rendering logic that deals with hiding/showing/progressbar etc, but the bulk of the Redux is actually dealing with the AJAX bits

@rossmiller
Copy link

rossmiller commented Jul 20, 2017

@hugorodgerbrown I would say you have it about right in your summary (although I'm not sure which bit you're describing with "Custom TextInput widget"). I would also add that the JS provides events for external systems to respond to. That's how platform integrates with and customises the upload functionality (in "feature/6625-update-s3direct-usage-to-reflect-changes-in-yj-s3direct-project").

Personally, I think this is one project - what @thealscott has done is take the very basic JS from the original, bring it up to date and allow external projects to interface with its event system.

The bloat is mostly in the example project, which certainly could be made less clunky if we're willing to spend the time. Also, if we're dropping support for older versions of Django and py2, that will simplify things significantly on the Python side of things.

@hugorodgerbrown
Copy link
Collaborator Author

hugorodgerbrown commented Jul 20, 2017 via email

@thealscott
Copy link

what do you consider "bare minimum" JS?

My interpretation is that the minimal functionality the JS needs to provide is:

  • get S3 upload parameters from the backend
  • get the file input
  • create a request using S3 upload params and file input
  • send the request to the S3 API
  • handle the response and display error/success states

90% of the current JS code is all about achieving those core features. There's maybe 100 lines of code above and beyond that which deals with emitting events for external interface and displaying the progress bar, but that's about it.

You could definitely get rid of the progress bar stuff, but beyond that you could only get more minimal with the JS if we don't do any DOM manipulation, and switch to a totally event driven model which offloads all interface responsibility (including displaying errors and success states) to the end user.

@stevejalim
Copy link

Devil's advocate rephrase of HRB's comment:

Could the upload-to-s3 function work as well with a (less featureful) vanilla-JS or jQuery implementation of what the redux component does?

If so, and if this is a flag-waving project, it'd be nice if we could support the idea of various JS clients for it (ie, someone might contrib/create the jQ version)

@thealscott
Copy link

it could, in which case we would basically need to revert everything in this branch back to the original procedural script and tickle it a little so that it parses the security parameters and dispatches events. You would shave off a few kb from the filesize, (most of the added filesize from the refactor is to do with using "import" module syntax that gets transpiled; Redux itself is actually pretty tiny, minified it's ~5kb, gzipped it's ~2kb) but beyond that, I'm not really sure what the benefit to doing it that way is. Are we concerned that people won't understand it because it's using Redux pattern?

If we want to have contributed JS clients then it doesn't make sense to have any JS included in the core package at all, it should just be an API, and then we can provide a client, and users can roll their own. I'm not sure how that affects the plug-and-playability of the project though. It's a bit of a deviation from the original S3Direct project use-case which was pretty fire and forget, with a little facility for customisation if you want to dig around in the guts.

@rossmiller
Copy link

rossmiller commented Jul 20, 2017

@hugorodgerbrown and @stevejalim the redux version is, as @thealscott says, pretty minimal in terms of its implementation. The redux pattern is now very popular and well understood within the JS community (and for very good reason - it's fantastic). The JS devs within YJ can work with this style of implementation much more easily than a non explicitly state managed implementation. This also goes for most JS devs I know in the wider community. It would feel to me, and I think I am safe in saying to @thealscott as well, like a big step backwards to remove it or change it to a JQuery or vanilla JS based implementation.

@rossmiller
Copy link

@hugorodgerbrown and @stevejalim also, in my view, the current implementation would aid us in our goal of demonstrating that we take security seriously - the use of modern JS practices, with separation of concern and testable distinct units, makes it look like we take the testing and reliability of the front end seriously.

I realise that the JS being in one file (as per the s3direct JS) looks superficially simpler. However, in terms of updates, bug fixing and general maintenance, what @thealscott has done is much simpler to debug and maintain.

@hugorodgerbrown
Copy link
Collaborator Author

Just to clarify - I like the redux implementation, and 👏 all of it.

My comments are about how we package this up for wider distribution. The critical aspects of the project are the generation of the S3 signed-request info and the secure download URL.

For reference - the Heroku demo for this contains 75 lines of python and 50 lines of JS (approx).

Again - nothing either of you have done will not be used in production - this is about its presentation to external users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants