Skip to content

Commit

Permalink
auth: Support Placeholders in Token Command
Browse files Browse the repository at this point in the history
  • Loading branch information
holesch committed Aug 11, 2024
1 parent aeeb43d commit 6abb093
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions not_my_board/_auth/_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import pathlib
import string

import not_my_board._jsonrpc as jsonrpc
import not_my_board._util as util
Expand Down Expand Up @@ -89,12 +90,19 @@ async def get_id_token(self):


class IdTokenFromCmd:
def __init__(self, hub_url, http_client, cmd):
def __init__(self, hub_url, http_client, cmd_template):
self._hub_url = hub_url
self._http = http_client
self._cmd = cmd
self._cmd_template = string.Template(cmd_template)
self._cmd = None

async def get_id_token(self):
if self._cmd is None:
url = f"{self._hub_url}/api/v1/auth-info"
auth_info = await self._http.get_json(url)
context = {k: auth_info[k] for k in ("issuer", "client_id")}
self._cmd = self._cmd_template.safe_substitute(context)

proc = await asyncio.create_subprocess_shell(
self._cmd, stdout=asyncio.subprocess.PIPE
)
Expand Down

0 comments on commit 6abb093

Please sign in to comment.