feat: Click CLI wrapper for cantaloupe export
- cantaloupe/ package with click CLI (python -m cantaloupe export) - export command: --output, --headless/--visible, --scheduled, --email, --password - configure command: saves credentials to ~/.cantaloupe.env (600 perms) - cantaloupe/config.py: credential loading from env vars + env file - Updated src/auth.py _get_credentials() to also check ~/.cantaloupe.env - File size, row count (openpyxl), and elapsed time reporting - 39 new CLI/config tests + 4 updated auth tests; 86/86 pass
This commit is contained in:
+25
-2
@@ -57,13 +57,36 @@ class AuthSession:
|
||||
|
||||
|
||||
def _get_credentials() -> tuple[str, str]:
|
||||
"""Read credentials from environment variables."""
|
||||
"""Read credentials from environment variables or ~/.cantaloupe.env."""
|
||||
email = os.environ.get("CANTALOUPE_EMAIL")
|
||||
password = os.environ.get("CANTALOUPE_PASSWORD")
|
||||
|
||||
# If env vars are set, use them
|
||||
if email and password:
|
||||
return email, password
|
||||
|
||||
# Fall back to ~/.cantaloupe.env
|
||||
env_file = os.path.expanduser("~/.cantaloupe.env")
|
||||
if os.path.exists(env_file):
|
||||
for line in open(env_file).read().splitlines():
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
key, _, value = line.partition("=")
|
||||
key = key.strip()
|
||||
value = value.strip().strip('"').strip("'")
|
||||
if key == "CANTALOUPE_EMAIL" and not email:
|
||||
email = value
|
||||
elif key == "CANTALOUPE_PASSWORD" and not password:
|
||||
password = value
|
||||
|
||||
if not email or not password:
|
||||
raise AuthenticationError(
|
||||
"Credentials not found. Set CANTALOUPE_EMAIL and CANTALOUPE_PASSWORD "
|
||||
"environment variables."
|
||||
"environment variables, or create ~/.cantaloupe.env with:\n"
|
||||
" CANTALOUPE_EMAIL=you@example.com\n"
|
||||
" CANTALOUPE_PASSWORD=your_password\n"
|
||||
"Or run: python -m cantaloupe configure"
|
||||
)
|
||||
return email, password
|
||||
|
||||
|
||||
Reference in New Issue
Block a user