Skip to content

Commit

Permalink
Adding oauthn (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh authored Oct 25, 2024
1 parent ac0fee8 commit d553095
Show file tree
Hide file tree
Showing 19 changed files with 1,127 additions and 223 deletions.
146 changes: 69 additions & 77 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,107 +1,102 @@
accessible-pygments==0.0.5
aioca==1.7
aioca==1.8
aiofiles==24.1.0
aiohappyeyeballs==2.4.0
aiohttp==3.10.5
aiohappyeyeballs==2.4.3
aiohttp==3.10.10
aiosignal==1.3.1
alabaster==1.0.0
annotated-types==0.7.0
anyio==4.4.0
anyio==4.6.2.post1
appdirs==1.4.4
asciitree==0.3.3
asttokens==2.4.1
async-timeout==4.0.3
attrs==24.2.0
babel==2.16.0
beautifulsoup4==4.12.3
bidict==0.23.1
bluesky==1.13.0a4
bluesky==1.13
bluesky-kafka==0.10.0
bluesky-live==0.0.8
bluesky-stomp==0.1.2
boltons==24.0.0
bump-pydantic==0.8.0
cachetools==5.5.0
caproto==1.1.1
certifi==2024.8.30
cffi==1.17.1
cfgv==3.4.0
charset-normalizer==3.3.2
charset-normalizer==3.4.0
click==8.1.7
cloudpickle==3.0.0
cloudpickle==3.1.0
colorama==0.4.6
colorlog==6.8.2
comm==0.2.2
compress-pickle==2.1.0
confluent-kafka==2.5.3
confluent-kafka==2.6.0
contourpy==1.3.0
copier==9.3.1
coverage==7.6.1
copier==9.4.0
coverage==7.6.3
cryptography==43.0.1
cycler==0.12.1
dask==2024.9.0
dask==2024.9.1
databroker==1.2.5
dataclasses-json==0.6.7
decorator==5.1.1
deepdiff==8.0.1
deepmerge==2.0
distlib==0.3.8
Deprecated==1.2.14
distlib==0.3.9
dls-bluesky-core==0.0.4
dls-dodal==1.31.1
dnspython==2.6.1
dls-dodal==1.33.0
dnspython==2.7.0
docopt==0.6.2
doct==1.1.0
docutils==0.21.2
dunamai==1.22.0
email_validator==2.2.0
entrypoints==0.4
epicscorelibs==7.0.7.99.0.2
epicscorelibs==7.0.7.99.1.1
event-model==1.21.0
exceptiongroup==1.2.2
executing==2.1.0
fastapi==0.114.2
fastapi-cli==0.0.5
fastapi==0.115.2
fasteners==0.19
filelock==3.16.0
filelock==3.16.1
flexcache==0.3
flexparser==0.3.1
fonttools==4.53.1
fonttools==4.54.1
frozenlist==1.4.1
fsspec==2024.9.0
funcy==2.0
gitdb==4.0.11
GitPython==3.1.43
graypy==2.1.0
h11==0.14.0
h5py==3.11.0
h5py==3.12.1
HeapDict==1.0.1
historydict==1.2.6
httpcore==1.0.5
httptools==0.6.1
httpcore==1.0.6
httpx==0.27.2
humanize==4.10.0
humanize==4.11.0
identify==2.6.1
idna==3.10
imageio==2.35.1
imageio==2.36.0
imagesize==1.4.1
importlib_metadata==8.5.0
importlib_metadata==8.4.0
importlib_resources==6.4.5
iniconfig==2.0.0
intake==0.6.4
ipython==8.18.0
ipywidgets==8.1.5
itsdangerous==2.2.0
jedi==0.19.1
Jinja2==3.1.4
jinja2-ansible-filters==1.3.2
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
jsonschema-specifications==2024.10.1
jupyterlab_widgets==3.0.13
kiwisolver==1.4.7
ldap3==2.9.1
libcst==1.4.0
livereload==2.7.0
locket==1.0.0
lz4==4.3.3
markdown-it-py==3.0.0
MarkupSafe==2.1.5
MarkupSafe==3.0.1
marshmallow==3.22.0
matplotlib==3.9.2
matplotlib-inline==0.1.7
Expand All @@ -113,90 +108,91 @@ mongoquery==1.4.2
msgpack==1.1.0
msgpack-numpy==0.4.8
multidict==6.1.0
mypy==1.11.2
mypy==1.12.0
mypy-extensions==1.0.0
myst-parser==4.0.0
networkx==3.3
networkx==3.4.1
nodeenv==1.9.1
nose2==0.15.1
nslsii==0.10.3
numcodecs==0.13.0
nslsii==0.10.5
numcodecs==0.13.1
numpy==1.26.4
opencv-python-headless==4.10.0.84
opentelemetry-api==1.27.0
ophyd==1.9.0
ophyd-async==0.5.2
ophyd-async==0.6.0
orderly-set==5.2.2
orjson==3.10.7
p4p==4.1.12
p4p==4.2.0
packaging==24.1
pandas==2.2.2
pandas==2.2.3
parso==0.8.4
partd==1.4.2
pathlib2==2.3.7.post1
pathspec==0.12.1
pexpect==4.9.0
picobox==4.0.0
pika==1.3.2
pillow==10.4.0
pillow==11.0.0
PIMS==0.7
Pint==0.24.3
pipdeptree==2.23.3
platformdirs==4.3.3
pipdeptree==2.23.4
platformdirs==4.3.6
pluggy==1.5.0
plumbum==1.8.3
plumbum==1.9.0
ply==3.11
pre-commit==3.8.0
pre_commit==4.0.1
prettytable==3.11.0
prompt-toolkit==3.0.36
propcache==0.2.0
psutil==6.0.0
ptyprocess==0.7.0
pure_eval==0.2.3
pvxslibs==1.3.1
pvxslibs==1.3.2
py==1.11.0
pyasn1==0.6.1
pycryptodome==3.20.0
pydantic==2.9.1
pydantic-extra-types==2.9.0
pycparser==2.22
pycryptodome==3.21.0
pydantic==2.9.2
pydantic-settings==2.5.2
pydantic_core==2.23.3
pydantic_core==2.23.4
pydantic_numpy==5.0.2
pydata-sphinx-theme==0.15.4
pyepics==3.5.7
Pygments==2.18.0
pymongo==4.8.0
PyJWT==2.9.0
pymongo==4.10.1
pyOlog==4.5.0
pyparsing==3.1.4
pyparsing==3.2.0
pytest==8.3.3
pytest-asyncio==0.24.0
pytest-cov==5.0.0
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-multipart==0.0.9
python-multipart==0.0.12
pytz==2024.2
PyYAML==6.0.2
pyyaml-include==2.1
questionary==2.0.1
redis==5.0.8
redis-json-dict==0.2.0
redis==5.1.1
redis-json-dict==0.2.1
referencing==0.35.1
requests==2.32.3
responses==0.25.3
rich==13.7.1
rpds-py==0.20.0
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.8
ruff==0.6.5
ruff==0.6.9
scanspec==0.7.2
semver==3.0.2
setuptools-dso==2.11
shellingham==1.5.4
six==1.16.0
slicerator==1.1.0
smmap==5.0.1
sniffio==1.3.1
snowballstemmer==2.2.0
soupsieve==2.6
Sphinx==8.0.2
sphinx-autobuild==2024.9.3
Sphinx==8.1.3
sphinx-autobuild==2024.10.3
sphinx-click==6.0.0
sphinx-copybutton==0.5.2
sphinx_design==0.6.1
Expand All @@ -210,43 +206,39 @@ sphinxcontrib-openapi==0.8.4
sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
stack-data==0.6.3
starlette==0.38.5
starlette==0.40.0
stomp-py==8.1.2
suitcase-mongo==0.6.0
suitcase-msgpack==0.3.0
suitcase-utils==0.5.4
super-state-machine==2.0.2
tifffile==2024.8.30
tomli==2.0.1
toolz==0.12.1
tornado==6.4.1
tifffile==2024.9.20
toolz==1.0.0
tox==3.28.0
tox-direct==0.4
tqdm==4.66.5
traitlets==5.14.3
typer==0.12.4
types-mock==5.1.0.20240425
types-PyYAML==6.0.12.20240917
types-requests==2.32.0.20240914
types-requests==2.32.0.20241016
types-urllib3==1.26.25.14
typing-inspect==0.9.0
typing_extensions==4.12.2
tzdata==2024.1
tzdata==2024.2
tzlocal==5.2
ujson==5.10.0
urllib3==2.2.3
uvicorn==0.30.6
uvloop==0.19.0
virtualenv==20.26.4
uvicorn==0.32.0
virtualenv==20.26.6
watchfiles==0.24.0
wcwidth==0.2.13
websocket-client==1.8.0
websockets==13.0.1
websockets==13.1
widgetsnbextension==4.0.13
workflows==2.27
wrapt==1.16.0
xarray==2024.9.0
yarl==1.11.1
yarl==1.15.3
zarr==2.18.3
zict==2.2.0
zipp==3.20.2
zocalo==1.1.0
zocalo==1.1.1
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ dependencies = [
"super-state-machine", # See GH issue 553
"GitPython",
"bluesky-stomp>=0.1.2",
"pyjwt",
"python-multipart",
"cryptography"
]
dynamic = ["version"]
license.file = "LICENSE"
Expand Down
40 changes: 38 additions & 2 deletions src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
from blueapi.client.client import BlueapiClient
from blueapi.client.event_bus import AnyEvent, BlueskyStreamingError, EventBusClient
from blueapi.client.rest import BlueskyRemoteControlError
from blueapi.config import ApplicationConfig, ConfigLoader
from blueapi.config import (
ApplicationConfig,
CLIClientConfig,
ConfigLoader,
)
from blueapi.core import DataEvent
from blueapi.service.authentication import CliTokenManager, SessionManager
from blueapi.service.main import start
from blueapi.service.openapi import (
DOCS_SCHEMA_LOCATION,
Expand Down Expand Up @@ -253,7 +258,6 @@ def pause(obj: dict, defer: bool = False) -> None:
@click.pass_obj
def resume(obj: dict) -> None:
"""Resume the execution of the current task"""

client: BlueapiClient = obj["client"]
pprint(client.resume())

Expand Down Expand Up @@ -329,3 +333,35 @@ def scratch(obj: dict) -> None:
setup_scratch(config.scratch)
else:
raise KeyError("No scratch config supplied")


@main.command(name="login")
@click.pass_obj
def login(obj: dict) -> None:
config: ApplicationConfig = obj["config"]
if isinstance(config.oauth_client, CLIClientConfig) and config.oauth_server:
print("Logging in")
auth: SessionManager = SessionManager(
server_config=config.oauth_server,
client_config=config.oauth_client,
token_manager=CliTokenManager(Path(config.oauth_client.token_file_path)),
)
auth.start_device_flow()
else:
print("Please provide configuration to login!")


@main.command(name="logout")
@click.pass_obj
def logout(obj: dict) -> None:
config: ApplicationConfig = obj["config"]
if isinstance(config.oauth_client, CLIClientConfig) and config.oauth_server:
auth: SessionManager = SessionManager(
server_config=config.oauth_server,
client_config=config.oauth_client,
token_manager=CliTokenManager(Path(config.oauth_client.token_file_path)),
)
auth.logout()
print("Logged out")
else:
print("Please provide configuration to logout!")
Loading

0 comments on commit d553095

Please sign in to comment.