Skip to content

Commit 0ed2fe8

Browse files
committed
Add url option to login and logout
1 parent 5c39463 commit 0ed2fe8

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

src/blueapi/cli/cli.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,24 @@ def start_application(ctx: click.Context, config: Path | None | tuple[Path, ...]
180180

181181

182182
@main.command(name="login")
183+
@click.option(
184+
"--url",
185+
type=str,
186+
help="URL for the blueapi server to connect to.",
187+
default=None,
188+
)
183189
@click.pass_obj
184190
@check_connection
185-
def login(obj: dict) -> None:
191+
def login(
192+
obj: dict,
193+
url: str | None,
194+
) -> None:
186195
"""
187196
Authenticate with the blueapi using the OIDC (OpenID Connect) flow.
188197
"""
189-
config: ApplicationConfig = obj["config"]
198+
config: ApplicationConfig = ConfigLoader(ApplicationConfig).load()
199+
if url is not None:
200+
config.api.url = HttpUrl(url)
190201
try:
191202
auth: SessionManager = SessionManager.from_cache(config.auth_token_path)
192203
access_token = auth.get_valid_access_token()
@@ -205,12 +216,23 @@ def login(obj: dict) -> None:
205216

206217

207218
@main.command(name="logout")
219+
@click.option(
220+
"--url",
221+
type=str,
222+
help="URL for the blueapi server to connect to.",
223+
default=None,
224+
)
208225
@click.pass_obj
209-
def logout(obj: dict) -> None:
226+
def logout(
227+
obj: dict,
228+
url: str | None,
229+
) -> None:
210230
"""
211231
Logs out from the OIDC provider and removes the cached access token.
212232
"""
213-
config: ApplicationConfig = obj["config"]
233+
config: ApplicationConfig = ConfigLoader(ApplicationConfig).load()
234+
if url is not None:
235+
config.api.url = HttpUrl(url)
214236
try:
215237
auth: SessionManager = SessionManager.from_cache(config.auth_token_path)
216238
auth.logout()

0 commit comments

Comments
 (0)