gws-cli 1.7.0__tar.gz → 1.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gws_cli-1.7.0 → gws_cli-1.8.0}/CLAUDE.md +2 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/PKG-INFO +2 -1
- {gws_cli-1.7.0 → gws_cli-1.8.0}/README.md +1 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/SKILL.md +1 -1
- {gws_cli-1.7.0 → gws_cli-1.8.0}/pyproject.toml +1 -1
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/__init__.py +1 -1
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/auth/oauth.py +14 -1
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/auth.py +12 -1
- gws_cli-1.8.0/tests/test_account_client_secret.py +103 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/.gitignore +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/LICENSE +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/LIVE_TESTING.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/SKILL-advanced.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/SKILL-typesetting.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/TESTING.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/reference/calendar.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/reference/contacts.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/reference/docs.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/reference/drive.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/reference/gmail.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/reference/sheets.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/reference/slides.md +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/__main__.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/auth/__init__.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/auth/provider.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/auth/scopes.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/auth/server.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/cli.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/__init__.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/_account.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/account.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/calendar.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/config.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/contacts.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/convert.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/docs.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/drive.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/gmail.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/sheets.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/commands/slides.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/config.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/context.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/crypto.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/exceptions.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/output.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/__init__.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/base.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/calendar.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/contacts.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/convert.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/docs.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/drive.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/gmail.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/sheets.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/services/slides.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/utils/__init__.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/utils/colors.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/utils/diagrams.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/utils/retry.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/src/gws/utils/security.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/__init__.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/conftest.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_account_commands.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_account_enforcement.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_auth_accounts.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_auth_commands.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_auth_provider.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_config_accounts.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_config_runtime_state.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_crypto.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_docs.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_download_screening.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_drive_feedback.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_font_size.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_force_reauth.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_gmail_mime.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_gmail_reply_draft.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_headless_auth.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_headless_env.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_implicit_login.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_output.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_server_auth.py +0 -0
- {gws_cli-1.7.0 → gws_cli-1.8.0}/tests/test_sheets_batch_write.py +0 -0
|
@@ -126,6 +126,7 @@ Secret files (tokens, credentials) are encrypted using Fernet symmetric encrypti
|
|
|
126
126
|
|
|
127
127
|
CLI commands for managing encrypted credentials:
|
|
128
128
|
- `gws-cli auth import-credentials <path>` - Import and encrypt `client_secret.json` from Google Cloud Console
|
|
129
|
+
- `gws-cli auth import-credentials <path> --account <name>` - Same, for one account only (`accounts/<name>/client_secret.json`, preferred over the shared client at login)
|
|
129
130
|
|
|
130
131
|
### Multi-Account Storage
|
|
131
132
|
|
|
@@ -138,6 +139,7 @@ When multi-account mode is active, per-account data is stored under `accounts/`:
|
|
|
138
139
|
├── gws_config.json # Global config + accounts registry
|
|
139
140
|
└── accounts/
|
|
140
141
|
├── work/
|
|
142
|
+
│ ├── client_secret.json # Account-only OAuth client (optional, overrides shared)
|
|
141
143
|
│ ├── token.json # Account-specific token
|
|
142
144
|
│ └── config.json # Per-account overrides (optional)
|
|
143
145
|
└── personal/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: gws-cli
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8.0
|
|
4
4
|
Summary: Google Workspace CLI - Unified management for Docs, Sheets, Slides, Drive, Gmail, Calendar, and Contacts
|
|
5
5
|
Project-URL: Homepage, https://github.com/andmarios/google-workspace-skill
|
|
6
6
|
Project-URL: Repository, https://github.com/andmarios/google-workspace-skill
|
|
@@ -257,6 +257,7 @@ All credentials and configuration are stored in `~/.config/gws-cli/`:
|
|
|
257
257
|
| File | Purpose |
|
|
258
258
|
|------|---------|
|
|
259
259
|
| `client_secret.json` | OAuth client credentials (you provide, shared across accounts) |
|
|
260
|
+
| `accounts/<name>/client_secret.json` | Client for one account only, overrides the shared one (optional; `auth import-credentials <path> --account <name>`) |
|
|
260
261
|
| `token.json` | Access token (legacy single-account mode) |
|
|
261
262
|
| `gws_config.json` | Service, security settings, and accounts registry |
|
|
262
263
|
| `accounts/<name>/token.json` | Per-account access token |
|
|
@@ -217,6 +217,7 @@ All credentials and configuration are stored in `~/.config/gws-cli/`:
|
|
|
217
217
|
| File | Purpose |
|
|
218
218
|
|------|---------|
|
|
219
219
|
| `client_secret.json` | OAuth client credentials (you provide, shared across accounts) |
|
|
220
|
+
| `accounts/<name>/client_secret.json` | Client for one account only, overrides the shared one (optional; `auth import-credentials <path> --account <name>`) |
|
|
220
221
|
| `token.json` | Access token (legacy single-account mode) |
|
|
221
222
|
| `gws_config.json` | Service, security settings, and accounts registry |
|
|
222
223
|
| `accounts/<name>/token.json` | Per-account access token |
|
|
@@ -348,7 +348,7 @@ Credentials stored in `~/.config/gws-cli/` (`client_secret.json`, `token.json`,
|
|
|
348
348
|
|
|
349
349
|
`gws-cli auth` (with no subcommand) logs in using the configured **mode**:
|
|
350
350
|
|
|
351
|
-
- **local** (default) — direct OAuth with your own `client_secret.json` via a browser loopback flow.
|
|
351
|
+
- **local** (default) — direct OAuth with your own `client_secret.json` via a browser loopback flow. One client is shared by all accounts; an account that needs its own (e.g. a Gmail account next to Workspace accounts on an Internal client) gets one with `uvx gws-cli auth import-credentials <path> --account <name>`.
|
|
352
352
|
- **server** — delegates auth to an `oauth-token-relay` server (no local OAuth client needed).
|
|
353
353
|
|
|
354
354
|
`auth status` reports the active mode, and `account list` shows the mode per account. Switch with:
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "gws-cli"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.8.0"
|
|
8
8
|
description = "Google Workspace CLI - Unified management for Docs, Sheets, Slides, Drive, Gmail, Calendar, and Contacts"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -212,7 +212,20 @@ class LocalAuthProvider:
|
|
|
212
212
|
import sys
|
|
213
213
|
|
|
214
214
|
key = self.config.get_encryption_key()
|
|
215
|
-
|
|
215
|
+
# An account's own client (from import-credentials --account) wins over the shared one.
|
|
216
|
+
name = self._account_name
|
|
217
|
+
own = self.config.get_account_dir(name) / "client_secret.json" if name else None
|
|
218
|
+
if own and (own.exists() or own.with_name(own.name + ".enc").exists()):
|
|
219
|
+
client_config = load_encrypted(own, key)
|
|
220
|
+
# No fallback to the shared client: a Personal-mode account would fail vaguely.
|
|
221
|
+
if not client_config:
|
|
222
|
+
raise AuthError(
|
|
223
|
+
f"Cannot read the OAuth client of account '{name}'",
|
|
224
|
+
"Re-import it with: gws-cli auth import-credentials <path> "
|
|
225
|
+
f"--account {name}",
|
|
226
|
+
)
|
|
227
|
+
else:
|
|
228
|
+
client_config = load_encrypted(self.CREDENTIALS_PATH, key)
|
|
216
229
|
if not client_config:
|
|
217
230
|
raise AuthError(
|
|
218
231
|
"Credentials file not found",
|
|
@@ -341,7 +341,18 @@ def auth_import_credentials(
|
|
|
341
341
|
|
|
342
342
|
config = Config.load()
|
|
343
343
|
key = config.get_encryption_key()
|
|
344
|
-
|
|
344
|
+
if account:
|
|
345
|
+
# Per-account client, e.g. a Personal-audience one that only its creator can use.
|
|
346
|
+
if not config.accounts or account not in config.accounts.entries:
|
|
347
|
+
output_error(
|
|
348
|
+
error_code="NOT_FOUND",
|
|
349
|
+
operation="auth.import-credentials",
|
|
350
|
+
message=f"Account '{account}' not found.",
|
|
351
|
+
)
|
|
352
|
+
raise typer.Exit(ExitCode.NOT_FOUND)
|
|
353
|
+
dest = config._make_account_dir(account) / "client_secret.json"
|
|
354
|
+
else:
|
|
355
|
+
dest = LocalAuthProvider.CREDENTIALS_PATH
|
|
345
356
|
save_encrypted(dest, client_config, key)
|
|
346
357
|
|
|
347
358
|
output_success(
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""`auth import-credentials --account` stores an OAuth client for one account.
|
|
2
|
+
|
|
3
|
+
That account's login uses it; every other account keeps the shared client.
|
|
4
|
+
Needed when accounts cannot share a client, e.g. a Workspace account on an
|
|
5
|
+
Internal client next to a Gmail account on a Personal one.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
from unittest.mock import MagicMock, patch
|
|
10
|
+
|
|
11
|
+
import pytest
|
|
12
|
+
from typer.testing import CliRunner
|
|
13
|
+
|
|
14
|
+
from gws.auth.oauth import LocalAuthProvider
|
|
15
|
+
from gws.cli import app
|
|
16
|
+
from gws.config import Config
|
|
17
|
+
from gws.crypto import load_encrypted
|
|
18
|
+
from gws.exceptions import AuthError, ExitCode
|
|
19
|
+
|
|
20
|
+
runner = CliRunner()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _client(name: str) -> dict:
|
|
24
|
+
return {
|
|
25
|
+
"installed": {
|
|
26
|
+
"client_id": f"{name}.apps.googleusercontent.com",
|
|
27
|
+
"client_secret": "test-secret",
|
|
28
|
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
|
29
|
+
"token_uri": "https://oauth2.googleapis.com/token",
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
SHARED, OWN = _client("shared"), _client("own")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.fixture(autouse=True)
|
|
38
|
+
def isolated_config(tmp_path, monkeypatch):
|
|
39
|
+
"""Keep tests away from the real ~/.config/gws-cli; register two accounts."""
|
|
40
|
+
monkeypatch.setattr(Config, "BASE_DIR", tmp_path)
|
|
41
|
+
monkeypatch.setattr(Config, "CONFIG_PATH", tmp_path / "gws_config.json")
|
|
42
|
+
monkeypatch.setattr(Config, "_LEGACY_BASE_DIR", tmp_path / "legacy")
|
|
43
|
+
monkeypatch.setattr(LocalAuthProvider, "_LEGACY_TOKEN_PATH", tmp_path / "token.json")
|
|
44
|
+
monkeypatch.setattr(LocalAuthProvider, "CREDENTIALS_PATH", tmp_path / "client_secret.json")
|
|
45
|
+
for var in ("GWS_ACCOUNT", "GWS_ENCRYPTION", "GWS_HEADLESS"):
|
|
46
|
+
monkeypatch.delenv(var, raising=False)
|
|
47
|
+
config = Config.load()
|
|
48
|
+
config.add_account("work")
|
|
49
|
+
config.add_account("personal")
|
|
50
|
+
for name, client in (("shared", SHARED), ("own", OWN)):
|
|
51
|
+
(tmp_path / f"{name}.json").write_text(json.dumps(client))
|
|
52
|
+
return tmp_path
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _import(tmp_path, name: str, *account_args: str):
|
|
56
|
+
return runner.invoke(
|
|
57
|
+
app, ["auth", "import-credentials", str(tmp_path / f"{name}.json"), *account_args]
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _client_id_used_by(account: str) -> str:
|
|
62
|
+
"""Run the browser login for *account* and return the client id it used."""
|
|
63
|
+
provider = LocalAuthProvider(account=account)
|
|
64
|
+
flow = MagicMock()
|
|
65
|
+
flow.run_local_server.return_value = MagicMock(valid=True)
|
|
66
|
+
with (
|
|
67
|
+
patch("gws.auth.oauth.InstalledAppFlow.from_client_config", return_value=flow) as build,
|
|
68
|
+
patch.object(provider, "_find_available_port", return_value=8080),
|
|
69
|
+
patch.object(provider, "_save_credentials"),
|
|
70
|
+
):
|
|
71
|
+
provider._run_auth_flow(scopes=["openid"])
|
|
72
|
+
return build.call_args.args[0]["installed"]["client_id"]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_account_client_is_used_only_by_that_account(isolated_config) -> None:
|
|
76
|
+
assert _import(isolated_config, "shared").exit_code == 0
|
|
77
|
+
result = _import(isolated_config, "own", "--account", "personal")
|
|
78
|
+
assert result.exit_code == 0, result.output
|
|
79
|
+
|
|
80
|
+
key = Config.load().get_encryption_key()
|
|
81
|
+
assert load_encrypted(LocalAuthProvider.CREDENTIALS_PATH, key) == SHARED
|
|
82
|
+
assert _client_id_used_by("personal") == "own.apps.googleusercontent.com"
|
|
83
|
+
assert _client_id_used_by("work") == "shared.apps.googleusercontent.com"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_unknown_account_is_rejected_and_shared_client_kept(isolated_config) -> None:
|
|
87
|
+
assert _import(isolated_config, "shared").exit_code == 0
|
|
88
|
+
result = _import(isolated_config, "own", "--account", "nobody")
|
|
89
|
+
|
|
90
|
+
assert result.exit_code == ExitCode.NOT_FOUND
|
|
91
|
+
key = Config.load().get_encryption_key()
|
|
92
|
+
assert load_encrypted(LocalAuthProvider.CREDENTIALS_PATH, key) == SHARED
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_unreadable_account_client_fails_instead_of_using_shared(isolated_config) -> None:
|
|
96
|
+
"""Falling back to the shared client would fail later with a vague Google error."""
|
|
97
|
+
assert _import(isolated_config, "shared").exit_code == 0
|
|
98
|
+
assert _import(isolated_config, "own", "--account", "personal").exit_code == 0
|
|
99
|
+
own = isolated_config / "accounts" / "personal" / "client_secret.json.enc"
|
|
100
|
+
own.write_bytes(b"not fernet")
|
|
101
|
+
|
|
102
|
+
with pytest.raises(AuthError, match="personal"):
|
|
103
|
+
_client_id_used_by("personal")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|