nk9 / get_dropbox_link

Code to get the URL of a file in the Dropbox folder
MIT License
6 stars 1 forks source link

App key separate from script file: Hassle free updates (=overwrites) and detection of credential file from earlier installs #8

Closed porg closed 11 months ago

porg commented 1 year ago

Precondition

You already had get_dropbox_link.py installed and had ran the initialization:

  1. You created an app key on the Dropbox website and filled int into APP_KEY = in the script file get_dropbox_link.py
  2. As a result the script (or the dropbox python module, I dunno exactly) created ~/.get_dropbox_link_conf.json

Problem

Now when you update a newer get_dropbox_link.py file over your old one, you have 2 problems:

  1. You need to fill APP_KEY again in get_dropbox_link.py or it fails.
  2. Also after you filled the APP_KEY again with a new generated app key, that fails, as the old ~/.get_dropbox_link_conf.json gets not overwritten by the new app key, but instead remains untouched and hence remains the old one and hence there's a mismatch/contradiction.

Proposed Improvements

  1. The app key gets set not in get_dropbox_link.py but elsewhere, e.g.
    • a) sibling file get_dropbox_link_app_key.conf
    • b) passed only once during init via argument like --init-app-key="XXX" and then anyhow is not needed in variable APP_KEY but persisted in ~/.get_dropbox_link_conf.json (I'm speculating, not knowing)
  2. If you had get_dropbox_link.py once on your system, but removed it, and later add it again, but you still have the credentials in get_dropbox_link_app_key.conf, it's clever enough and just uses them.
porg commented 10 months ago

I've also moved the APP_KEY and ACCOUNT_TYPE variables into the config file to simplify upgrading.

👍 Per se great! 👉 But it yet misses documentation. Please amend!

porg commented 10 months ago

Intermediary update:

$ get_dropbox_link.py ~/Dropbox/Public/some-file.png
=>Please provide your app's App Key. This is NOT an OAuth2 token.
Find the App Key in the App Console. See the README.
App Key: ••••••••••••••••••••••••

=> Which kind of Dropbox account is this App Key associated with?
[p]ersonal or [b]usiness? p
https://www.dropbox.com/s/xxxxxxxx/some-file.png?dl=0

After this ~/.get_dropbox_link_conf.json will have changed to this:

{"app_key": "XXX",
"refresh_token": "XXX",
"account_type": "PERSONAL",
"access_token": "XXX", // Note: Changed when script re-configured now.
"access_token_expiration": "YYYY-MM-DDThh:mm:ss.nnnnnn8" // Note: Changed to timestamp of re-configuration.
}