Skip to content

Commit a90c68c

Browse files
committed
Revert "move cli-specific auth to CliSession, add tests for CliSession"
This reverts commit 8881453.
1 parent 8881453 commit a90c68c

File tree

5 files changed

+22
-114
lines changed

5 files changed

+22
-114
lines changed

planet/cli/data.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737

3838
@asynccontextmanager
3939
async def data_client(ctx):
40-
async with CliSession() as sess:
41-
cl = DataClient(sess, base_url=ctx.obj['BASE_URL'])
40+
auth = ctx.obj['AUTH']
41+
base_url = ctx.obj['BASE_URL']
42+
async with CliSession(auth=auth) as sess:
43+
cl = DataClient(sess, base_url=base_url)
4244
yield cl
4345

4446

@@ -50,6 +52,7 @@ async def data_client(ctx):
5052
help='Assign custom base Orders API URL.')
5153
def data(ctx, base_url):
5254
'''Commands for interacting with the Data API'''
55+
ctx.obj['AUTH'] = None
5356
ctx.obj['BASE_URL'] = base_url
5457

5558

planet/cli/orders.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131

3232
@asynccontextmanager
3333
async def orders_client(ctx):
34+
auth = ctx.obj['AUTH']
3435
base_url = ctx.obj['BASE_URL']
35-
async with CliSession() as sess:
36+
async with CliSession(auth=auth) as sess:
3637
cl = OrdersClient(sess, base_url=base_url)
3738
yield cl
3839

@@ -45,6 +46,7 @@ async def orders_client(ctx):
4546
help='Assign custom base Orders API URL.')
4647
def orders(ctx, base_url):
4748
'''Commands for interacting with the Orders API'''
49+
ctx.obj['AUTH'] = None
4850
ctx.obj['BASE_URL'] = base_url
4951

5052

planet/cli/session.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""CLI HTTP/auth sessions."""
22

3-
from planet.auth import Auth
3+
from planet.auth import AuthType
44
from planet.http import Session
5+
from typing import Optional
56

67

78
class CliSession(Session):
8-
"""Session with CLI-specific auth and identifying header"""
9-
def __init__(self):
10-
super().__init__(Auth.from_file())
9+
10+
def __init__(self, auth: Optional[AuthType] = None):
11+
super().__init__(auth)
1112
self._client.headers.update({'X-Planet-App': 'python-cli'})

planet/cli/subscriptions.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
@click.pass_context
1515
def subscriptions(ctx):
1616
'''Commands for interacting with the Subscriptions API'''
17-
pass
17+
# None means that order of precedence is 1) environment variable,
18+
# 2) secret file.
19+
ctx.obj['AUTH'] = None
1820

1921

2022
# We want our command to be known as "list" on the command line but
@@ -38,7 +40,7 @@ def subscriptions(ctx):
3840
@coro
3941
async def list_subscriptions_cmd(ctx, status, limit, pretty):
4042
"""Prints a sequence of JSON-encoded Subscription descriptions."""
41-
async with CliSession() as session:
43+
async with CliSession(auth=ctx.obj['AUTH']) as session:
4244
client = SubscriptionsClient(session)
4345
subs_aiter = client.list_subscriptions_aiter(status=status,
4446
limit=limit)
@@ -75,7 +77,7 @@ def parse_request(ctx, param, value: str) -> dict:
7577
@coro
7678
async def create_subscription_cmd(ctx, request, pretty):
7779
"""Submits a subscription request and prints the API response."""
78-
async with CliSession() as session:
80+
async with CliSession(auth=ctx.obj['AUTH']) as session:
7981
client = SubscriptionsClient(session)
8082
sub = await client.create_subscription(request)
8183
echo_json(sub, pretty)
@@ -89,7 +91,7 @@ async def create_subscription_cmd(ctx, request, pretty):
8991
@coro
9092
async def cancel_subscription_cmd(ctx, subscription_id, pretty):
9193
"""Cancels a subscription and prints the API response."""
92-
async with CliSession() as session:
94+
async with CliSession(auth=ctx.obj['AUTH']) as session:
9395
client = SubscriptionsClient(session)
9496
sub = await client.cancel_subscription(subscription_id)
9597
echo_json(sub, pretty)
@@ -104,7 +106,7 @@ async def cancel_subscription_cmd(ctx, subscription_id, pretty):
104106
@coro
105107
async def update_subscription_cmd(ctx, subscription_id, request, pretty):
106108
"""Updates a subscription and prints the API response."""
107-
async with CliSession() as session:
109+
async with CliSession(auth=ctx.obj['AUTH']) as session:
108110
client = SubscriptionsClient(session)
109111
sub = await client.update_subscription(subscription_id, request)
110112
echo_json(sub, pretty)
@@ -118,7 +120,7 @@ async def update_subscription_cmd(ctx, subscription_id, request, pretty):
118120
@coro
119121
async def describe_subscription_cmd(ctx, subscription_id, pretty):
120122
"""Gets the description of a subscription and prints the API response."""
121-
async with CliSession() as session:
123+
async with CliSession(auth=ctx.obj['AUTH']) as session:
122124
client = SubscriptionsClient(session)
123125
sub = await client.get_subscription(subscription_id)
124126
echo_json(sub, pretty)
@@ -154,7 +156,7 @@ async def list_subscription_results_cmd(ctx,
154156
status,
155157
limit):
156158
"""Gets results of a subscription and prints the API response."""
157-
async with CliSession() as session:
159+
async with CliSession(auth=ctx.obj['AUTH']) as session:
158160
client = SubscriptionsClient(session)
159161
results_aiter = client.get_results_aiter(subscription_id,
160162
status=status,

tests/unit/test_cli_session.py

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)