Add command to register a custom URI handler
This is a proof of concept, nothing more.
In https://github.com/exercism/v3/discussions/2164#discussioncomment-49086 I suggested it would be nice to have a button that automatically downloads a solution or exercise instead of having to copy the command into the terminal; similar to a spotify:track:2pnZVpeKqLrEto2X9vYF6s URI opening the Spotify app.
This PR contains a proof of concept that adds such a handler on Windows, based on the protocol outlined on MSDN (note that the docs refer to Internet Explorer, but these handlers are system-wide). The primary purpose is to demonstrate that this is easily possible without modifying the CLI itself.
What would be required to actually add this feature?
- Support for it in the UI (v3)
- to be clear: I don't think this should replace the copy buttons, it should be an addition. Maybe with a dropdown button or a user setting to configure the default.
- Figure out how to test this properly. Since it modifies the registry, we need to be careful to not destroy anything.
- Figure out macOS support (https://superuser.com/questions/548119/how-do-i-configure-custom-url-handlers-on-os-x as a starting point)
- People who use Linux are proficient enough to figure this out on their own if they want to use it ¯\_(ツ)_/¯
- Ideally add a command that adds the cli to PATH. Otherwise allow people to specify which path it is in.
- Add unregister command.
- Instead of launching
exercism download --uuid=..., we should define a commandexercism uri-handler-entrypoint %1that parses the custom URI and then executes the commands. This would allow us to run different commands, e.g. we could haveexercism:download:mentor:<uuid>that runsexercism download --uuid=<uuid>andexercism:download:julia:leapthat runsexercism download --exercise=leap --track=julia. Everything that right now requires copying a command could be run through this. - MSDN lists security precautions. I don't really see any attack vectors through the CLI, but it's something that needs to be considered.
Alternatively, but I like this option far less, we could wrap the CLI in a standard installer which can probably set this up quite easily.
@ErikSchierboom Do you know how to help with the windows API side of this? Primarily, how should one test changes to the registry etc?
@SaschaMann Thank you for both the detailed issue and the POC 🙂
to be clear: I don't think this should replace the copy buttons, it should be an addition. Maybe with a dropdown button or a user setting to configure the default.
Could you maybe outline where the advantage is to having this URI over the command to paste?
- Would it be clickable in the UI to trigger the download via this URL?
- If not, is the advantage that you can paste it into the window you're in (e.g. firefox, rather than having to switch to a terminal etc)?
Thanks! :)
Would it be clickable in the UI to trigger the download via this URL?
Yes. You'd click on a button and it would launch the exercism cli and run the command for you. You don't have to copy and paste anything into your terminal. I can share a screen recording of the PoC later this week.
If not, is the advantage that you can paste it into the window you're in (e.g. firefox, rather than having to switch to a terminal etc)?
You could do that, but I don't think it's a big advantage.
Yes. You'd click on a button and it would launch the exercism cli and run the command for you.
Excellent. Thanks for clarifying :)
This seems like a great idea to me.
Short comment on the review requests: No point in reviewing the actual code yet, I know it's trash, but I'd appreciate some input on the general idea and the points I outlined above.
I really like this idea. It is also something that Slack does for example, and it is really helpful.
Support for it in the UI (v3) to be clear: I don't think this should replace the copy buttons, it should be an addition. Maybe with a dropdown button or a user setting to configure the default.
Yep, this would be nice.
Figure out how to test this properly. Since it modifies the registry, we need to be careful to not destroy anything.
Yes, this is always problematic with the registry, although usually the problematic bit is doing the correct cleanup when removing an application. A proper integration test would involve modifying the registry, although we might be able to get away with just unit-testing the custom entry point at first.
Figure out macOS support (https://superuser.com/questions/548119/how-do-i-configure-custom-url-handlers-on-os-x as a starting point) People who use Linux are proficient enough to figure this out on their own if they want to use it ¯_(ツ)_/¯
Agreed
Ideally add a command that adds the cli to PATH. Otherwise allow people to specify which path it is in.
Do you mean something like exercism register that would add it to the path?
Add unregister command.
See comment on testing with registry
Instead of launching exercism download --uuid=..., we should define a command exercism uri-handler-entrypoint %1 that parses the custom URI and then executes the commands. This would allow us to run different commands, e.g. we could have exercism:download:mentor:
that runs exercism download --uuid= and exercism:download:julia:leap that runs exercism download --exercise=leap --track=julia. Everything that right now requires copying a command could be run through this.
This sounds good. Clearly we'd have to be careful to only handle valid input, but this is totally doable of course.
MSDN lists security precautions. I don't really see any attack vectors through the CLI, but it's something that needs to be considered.
Did they list any particular attack vectors? As the CLI is based on the API, a lot of the security stuff is automatically handled. It would also help if we would only do read actions through this (as in only downloading things, not uploading things).
Alternatively, but I like this option far less, we could wrap the CLI in a standard installer which can probably set this up quite easily.
What in particular do you dislike about this?
Do you mean something like exercism register that would add it to the path?
Yes.
What in particular do you dislike about this?
Just seems like overkill to wrap a standalone binary in an installer.
Did they list any particular attack vectors?
Primarily malicious inputs:
Security Warning: Applications that handle URI schemes must consider how to respond to malicious data. Because handler applications can receive data from untrusted sources, the URI and other parameter values passed to the application may contain malicious data that attempts to exploit the handling application.
Just seems like overkill to wrap a standalone binary in an installer.
Right. I can understand that :)
Having given this some thought, I think that for now we won't be proceeding with this PR. We might reconsider later on.