Load configuration from file and keyring. Returns: True if configuration exists, False otherwise
(self)
| 86 | # Restrict file permissions (owner read/write only) |
| 87 | try: |
| 88 | CREDENTIALS_FILE.chmod(0o600) |
| 89 | except OSError: |
| 90 | pass |
| 91 | |
| 92 | def load(self) -> bool: |
| 93 | """ |
| 94 | Load configuration from file and keyring. |
| 95 | |
| 96 | Returns: |
| 97 | True if configuration exists, False otherwise |
| 98 | """ |
| 99 | # Load from JSON file |
| 100 | if not CONFIG_FILE.exists(): |
| 101 | return False |
| 102 | |
| 103 | try: |
| 104 | content = safe_read(CONFIG_FILE) |
| 105 | data = json.loads(content) |
| 106 | |
| 107 | # Validate version |
| 108 | if data.get("version") != CONFIG_VERSION: |
| 109 | # Could implement migration here |
| 110 | pass |
| 111 | |
| 112 | self._config = Configuration.from_dict(data) |
| 113 | |
| 114 | # Load API key from keyring, falling back to file |
| 115 | if self._keyring_available: |
| 116 | try: |
| 117 | self._api_key = keyring.get_password(KEYRING_SERVICE, KEYRING_API_KEY_ACCOUNT) |
| 118 | except (KeyringError, Exception): |
| 119 | pass |
| 120 | if self._api_key is None: |
| 121 | self._api_key = self._load_api_key_from_file() |
| 122 | |
| 123 | return True |
| 124 | except (json.JSONDecodeError, FileSystemError) as e: |
no test coverage detected