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

Support a password_file option as well as password #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions garmindb/GarminConnectConfig.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"user" : "[email protected]",
"secure_password" : false,
"password" : "yourpassword"
"password_file" : null,
},
"data": {
"weight_start_date" : "12/31/2019",
Expand Down
11 changes: 11 additions & 0 deletions garmindb/garmin_connect_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ def get_secure_password(self):
pass
raise ConfigException(f'Secure password was specified but no "Internet Password" entry was found in the Login Keychain for https://{domain}')

def get_password_from_file(self):
"""Read the Garmin Connect password from a file."""
password_file = self.get_node_value('credentials', 'password_file')
try:
with open(os.path.expanduser(password_file), 'r') as f:
return f.read().strip()
except Exception as e:
raise ConfigException(f'Failed to read password from file {password_file}: {str(e)}')

def get_user(self):
"""Return the Garmin Connect username."""
return self.get_node_value('credentials', 'user')
Expand All @@ -192,6 +201,8 @@ def get_password(self):
"""Return the Garmin Connect password."""
if self.get_node_value_default('credentials', 'secure_password', False):
return self.get_secure_password()
if self.get_node_value('credentials', 'password_file'):
return self.get_password_from_file()
return self.get_node_value('credentials', 'password')

def get_garmin_base_domain(self):
Expand Down