pawamoy / aria2p

Command-line tool and library to interact with an aria2c daemon process with JSON-RPC.
https://pawamoy.github.io/aria2p
ISC License
493 stars 93 forks source link

conf file for options would be helpful #66

Open netllama opened 4 years ago

netllama commented 4 years ago

Thanks for this project, it looks super useful for integrating into another project that I maintain.

One thing that would help a lot is to support a configuration file that could save options so that they don't need to be provided for every invocation. I'm primarily thinking of the value for the --secret option, but any of them could be handy.

Boost priority

Fund with Polar

pawamoy commented 4 years ago

Oh, I'm pretty sure you can do that with aria2's configuration file, usually located at ~/.config/aria2/aria2.conf. Check out its man pages, everything is explained there.

In your case, you'll want to set the rpc-secretvalue in your configuration file :slightly_smiling_face:

netllama commented 4 years ago

Right, but I already did that, and yet aria2p never uses it. If I invoke aria2c, it finds the value of rpc-secret as expected.

$ aria2p
Traceback (most recent call last):
  File "/usr/local/bin/aria2p", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/aria2p/cli.py", line 74, in main
    api.client.get_version()
  File "/usr/local/lib/python3.7/site-packages/aria2p/client.py", line 1478, in get_version
    return self.call(self.GET_VERSION)
  File "/usr/local/lib/python3.7/site-packages/aria2p/client.py", line 234, in call
    return self.res_or_raise(self.post(self.get_payload(method, params, msg_id=msg_id)))
  File "/usr/local/lib/python3.7/site-packages/aria2p/client.py", line 360, in res_or_raise
    raise Client.response_as_exception(response)
aria2p.client.ClientException: Unauthorized
aria2p -s 'blah'
<no exception>
pawamoy commented 4 years ago

Aaaaah indeed, sorry, I failed to see that. Yes, maybe aria2p could try to read aria2's configuration file when it exists, so it can automatically use the right secret and other options.

snowman commented 3 years ago

Please consider support aria2p configuration.

pawamoy commented 3 years ago

I am considering it, just didn't get the time to work on it, PRs welcome :slightly_smiling_face: !

snowman commented 3 years ago

You can add an alias for aria2p:

alias aria2p="aria2p --secret 343ab16f-cb48-4f15-8f24-e42bf04cb68a"
skull-squadron commented 10 months ago

It should read the secret from -s for a one-of run (infrequent use and testing) and then fallback to ${XDG_CONFIG_HOME}/aria2p/config.toml SECRET if present (preferred). The problem of passing a secret by CLI argument is that it's insecure and annoying. Reading another program's secrets would be fragile, so doing this should be avoided.

pawamoy commented 10 months ago

aria2's own config file format is probably super stable. Why do you say it would be fragile?

In any case, we must support setting the secret in an aria2p config file, because both files (aria2 conf and aria2p conf) could be on different hosts, so you're right.