jaroslawhartman / withings-sync

Synchronisation of Withings weight
MIT License
455 stars 89 forks source link

Storing session data in `./garmin_session` breaks for non-root K8s deployments #145

Closed ethanbergstrom closed 1 year ago

ethanbergstrom commented 1 year ago

The K8s examples explicitly do not run as root, but the current implementation of Garth post-v4 upgrade puts ./garmin_session in /, which is a location a non-root user wouldn't normally be able to write to.

2023-10-08 15:04:41,638 - urllib3.connectionpool - DEBUG - https://connectapi.garmin.com:443 "POST /oauth-service/oauth/exchange/user/2.0 HTTP/1.1" 200 None
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/withings_sync-4.1.0-py3.10.egg/withings_sync/garmin.py", line 41, in login
    self.client.dump('./garmin_session')
  File "/usr/local/lib/python3.10/site-packages/garth-0.4.38-py3.10.egg/garth/http.py", line 183, in dump
    os.makedirs(dir_path, exist_ok=True)
  File "/usr/local/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: './garmin_session'

Looks like this should be fixed in #144 in that it now derives its path from $HOME the same way Withings session data is stored, but wanted to call this out as a separate but related issue.

Working around it for now by specifying workingDir in my K8s job to match the same directory as $HOME.

ethanbergstrom commented 1 year ago

Fixed with v4.2.0

Tumetsu commented 1 year ago

Any idea of when this fix will be released in PyPi? I'm configuring this syncer for my home server where I'd like to run this as a non-root user and it looks like this prevents me from running the script:

Traceback (most recent call last):
  File "/home/syncer/.local/lib/python3.9/site-packages/withings_sync/garmin.py", line 38, in get_session
    garth.save('./garmin_session')
  File "/usr/local/lib/python3.9/dist-packages/garth/http.py", line 183, in dump
    os.makedirs(dir_path, exist_ok=True)
  File "/usr/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: './garmin_session'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/syncer/.local/bin/withings-sync", line 8, in <module>
    sys.exit(main())
  File "/home/syncer/.local/lib/python3.9/site-packages/withings_sync/sync.py", line 512, in main
    sync()
  File "/home/syncer/.local/lib/python3.9/site-packages/withings_sync/sync.py", line 473, in sync
    gar_wg_state = sync_garmin(fit_data_weight)
  File "/home/syncer/.local/lib/python3.9/site-packages/withings_sync/sync.py", line 168, in sync_garmin
    garmin.login(ARGS.garmin_username, ARGS.garmin_password)
  File "/home/syncer/.local/lib/python3.9/site-packages/withings_sync/garmin.py", line 46, in login
    return GarminConnect.get_session(email=username, password=password)
  File "/home/syncer/.local/lib/python3.9/site-packages/withings_sync/garmin.py", line 40, in get_session
    raise APIException("Authentication failure: {}. Did you enter correct credentials?".format(ex))
withings_sync.garmin.APIException: Authentication failure: [Errno 13] Permission denied: './garmin_session'. Did you enter correct credentials?