amazon-sp-cli 0.3.2__tar.gz → 0.3.3__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.
- {amazon_sp_cli-0.3.2/amazon_sp_cli.egg-info → amazon_sp_cli-0.3.3}/PKG-INFO +1 -1
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/__init__.py +1 -1
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/auth.py +3 -2
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/cli.py +4 -2
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3/amazon_sp_cli.egg-info}/PKG-INFO +1 -1
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/tests/test_auth.py +18 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/LICENSE +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/MANIFEST.in +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/README.md +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/__main__.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/client.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/commands/__init__.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/commands/a_plus.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/commands/auth.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/commands/listings.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/commands/pricing.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/commands/update.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/main.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/models/__init__.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli/models/a_plus.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli.egg-info/SOURCES.txt +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli.egg-info/dependency_links.txt +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli.egg-info/entry_points.txt +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli.egg-info/requires.txt +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/amazon_sp_cli.egg-info/top_level.txt +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/pyproject.toml +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/setup.cfg +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/setup.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/tests/__init__.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/tests/test_a_plus.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/tests/test_client.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/tests/test_listings.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/tests/test_pricing.py +0 -0
- {amazon_sp_cli-0.3.2 → amazon_sp_cli-0.3.3}/tests/test_update.py +0 -0
|
@@ -17,7 +17,8 @@ class SPAPIAuth:
|
|
|
17
17
|
CACHE_FILE = Path.home() / ".config" / "amazon-sp-cli" / "token-cache.json"
|
|
18
18
|
BUFFER_SECONDS = 60
|
|
19
19
|
|
|
20
|
-
def __init__(self, credentials_path: str = None):
|
|
20
|
+
def __init__(self, credentials_path: str = None, profile: str = "default"):
|
|
21
|
+
self.profile = profile
|
|
21
22
|
self.credentials = self._load_credentials(credentials_path)
|
|
22
23
|
self._ensure_cache_dir()
|
|
23
24
|
|
|
@@ -32,7 +33,7 @@ class SPAPIAuth:
|
|
|
32
33
|
with open(path, "r") as f:
|
|
33
34
|
config = yaml.safe_load(f)
|
|
34
35
|
|
|
35
|
-
return config.get(
|
|
36
|
+
return config.get(self.profile, config)
|
|
36
37
|
|
|
37
38
|
def _ensure_cache_dir(self):
|
|
38
39
|
"""Ensure cache directory exists."""
|
|
@@ -58,7 +58,7 @@ def _check_path():
|
|
|
58
58
|
def _ensure_auth_client(ctx):
|
|
59
59
|
"""Lazily create auth and client if not already present."""
|
|
60
60
|
if "client" not in ctx.obj:
|
|
61
|
-
auth = SPAPIAuth(ctx.obj.get("credentials_path"))
|
|
61
|
+
auth = SPAPIAuth(ctx.obj.get("credentials_path"), ctx.obj.get("profile", "default"))
|
|
62
62
|
if auth.credentials is None:
|
|
63
63
|
click.echo("Error: No credentials found. Run 'amz-sp auth setup' first.", err=True)
|
|
64
64
|
raise click.Abort()
|
|
@@ -86,9 +86,11 @@ def handle_errors(f):
|
|
|
86
86
|
@click.version_option(version=__version__, prog_name="amz-sp")
|
|
87
87
|
@click.group()
|
|
88
88
|
@click.option("--credentials", "-c", help="Path to credentials YAML file")
|
|
89
|
+
@click.option("--profile", "-p", default="default", help="Credentials profile to use")
|
|
89
90
|
@click.pass_context
|
|
90
|
-
def cli(ctx, credentials):
|
|
91
|
+
def cli(ctx, credentials, profile):
|
|
91
92
|
"""Amazon SP-API CLI - Manage listings, pricing, inventory, and more."""
|
|
92
93
|
_check_path()
|
|
93
94
|
ctx.ensure_object(dict)
|
|
94
95
|
ctx.obj["credentials_path"] = credentials
|
|
96
|
+
ctx.obj["profile"] = profile
|
|
@@ -23,6 +23,10 @@ default:
|
|
|
23
23
|
refresh_token: "test-refresh-token"
|
|
24
24
|
client_id: "test-client-id"
|
|
25
25
|
client_secret: "test-client-secret"
|
|
26
|
+
prod:
|
|
27
|
+
refresh_token: "prod-refresh-token"
|
|
28
|
+
client_id: "prod-client-id"
|
|
29
|
+
client_secret: "prod-client-secret"
|
|
26
30
|
"""
|
|
27
31
|
)
|
|
28
32
|
path = f.name
|
|
@@ -44,6 +48,20 @@ default:
|
|
|
44
48
|
assert auth.credentials["client_id"] == "test-client-id"
|
|
45
49
|
assert auth.credentials["client_secret"] == "test-client-secret"
|
|
46
50
|
|
|
51
|
+
def test_load_credentials_profile(self, temp_credentials):
|
|
52
|
+
"""Test credentials loading with a specific profile."""
|
|
53
|
+
auth = SPAPIAuth(temp_credentials, profile="prod")
|
|
54
|
+
assert auth.credentials["refresh_token"] == "prod-refresh-token"
|
|
55
|
+
assert auth.credentials["client_id"] == "prod-client-id"
|
|
56
|
+
assert auth.credentials["client_secret"] == "prod-client-secret"
|
|
57
|
+
|
|
58
|
+
def test_load_credentials_missing_profile_fallback(self, temp_credentials):
|
|
59
|
+
"""Test fallback when profile is missing."""
|
|
60
|
+
auth = SPAPIAuth(temp_credentials, profile="nonexistent")
|
|
61
|
+
# Falls back to the whole config dict
|
|
62
|
+
assert "default" in auth.credentials
|
|
63
|
+
assert "prod" in auth.credentials
|
|
64
|
+
|
|
47
65
|
def test_token_valid(self, temp_credentials, temp_cache_dir):
|
|
48
66
|
"""Test token validation."""
|
|
49
67
|
auth = SPAPIAuth(temp_credentials)
|
|
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
|