Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding oauthn #655

Merged
merged 56 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ac5e582
Added prototype for authentication
ZohebShaikh Oct 2, 2024
a7ec5d0
added authentication token to headers of requests in Blueapi RestClient
ZohebShaikh Oct 2, 2024
6378958
Refactor authentication in Blueapi RestClient and service
ZohebShaikh Oct 4, 2024
c76a823
Refactor authentication in Blueapi RestClient and service
ZohebShaikh Oct 4, 2024
643ea64
Refactor authentication in Blueapi RestClient and service
ZohebShaikh Oct 8, 2024
3b6b80f
checkpoint for working code
ZohebShaikh Oct 9, 2024
b5c82a7
Refactor authentication in Blueapi RestClient and service
ZohebShaikh Oct 14, 2024
58f1217
made main.py use application config
ZohebShaikh Oct 14, 2024
e0da926
Refactor OauthConfig to use None for checking
ZohebShaikh Oct 14, 2024
d028bc6
removed typo
ZohebShaikh Oct 14, 2024
2210f84
Refactored code
ZohebShaikh Oct 14, 2024
d2be3ed
middleware not working attempt #2
ZohebShaikh Oct 14, 2024
2e23514
Refactor BlueapiClient to use application config for creating Blueapi…
ZohebShaikh Oct 15, 2024
bdadfcd
Add valid_auth_config.yaml for stomp and oauth configurations
ZohebShaikh Oct 15, 2024
fa2589f
unit test changes
ZohebShaikh Oct 15, 2024
2154fc3
Update dependencies in dev-requirements.txt and pyproject.toml
ZohebShaikh Oct 16, 2024
be57f97
added code review changes
ZohebShaikh Oct 16, 2024
de402fe
added tests for config
ZohebShaikh Oct 16, 2024
8adf065
refactored code for rest.py
ZohebShaikh Oct 16, 2024
bc56e2c
added tests for cli
ZohebShaikh Oct 16, 2024
4c40274
added test for cli
ZohebShaikh Oct 16, 2024
73e4030
Refactor openapi.yaml to remove unused security schemes and security …
ZohebShaikh Oct 16, 2024
be76510
added test for rest_client
ZohebShaikh Oct 16, 2024
5d470f8
delete a test
ZohebShaikh Oct 16, 2024
d4f54be
deleted swaggerAuthConfig as not required
ZohebShaikh Oct 16, 2024
79c548d
added new test client
ZohebShaikh Oct 16, 2024
a187a51
changed order for un authorized test client
ZohebShaikh Oct 16, 2024
b2a45fd
added env variable to test client
ZohebShaikh Oct 16, 2024
57b1231
delete tests
ZohebShaikh Oct 16, 2024
ddb98c6
Refactor authentication.py for improved readability and maintainability
ZohebShaikh Oct 16, 2024
e4918cc
raising exception to check why ci is not showing in coverage
ZohebShaikh Oct 16, 2024
e1a450f
added type checking and other changes
ZohebShaikh Oct 16, 2024
58d8049
deleted not used field
ZohebShaikh Oct 17, 2024
10bbb80
updated rest tests
ZohebShaikh Oct 17, 2024
697e7c9
added test for early exit
ZohebShaikh Oct 17, 2024
8ad8d9b
changed to have only one rest fixture
ZohebShaikh Oct 17, 2024
35453d8
reverted formating changes
ZohebShaikh Oct 17, 2024
1326164
Refactored code
ZohebShaikh Oct 17, 2024
79cdff9
made session Manager return None from config
ZohebShaikh Oct 17, 2024
3dd8838
type checking fixes
ZohebShaikh Oct 17, 2024
64aa9e7
removed unused matplotlib
ZohebShaikh Oct 17, 2024
d1b41b8
added test to check device code failure
ZohebShaikh Oct 17, 2024
6456982
delete not used config file
ZohebShaikh Oct 17, 2024
86c6e94
changed name for clitoken manager
ZohebShaikh Oct 17, 2024
fba96e6
reducing repeating of variables
ZohebShaikh Oct 17, 2024
d03b1ec
added minor changes
ZohebShaikh Oct 17, 2024
7576392
deleted default value
ZohebShaikh Oct 17, 2024
d747a89
added more checks in the code
ZohebShaikh Oct 17, 2024
50e8ff0
added 3 tests for auth in main.py
ZohebShaikh Oct 18, 2024
0ec2c77
modified authencticator and added test for blueapi main serve
ZohebShaikh Oct 19, 2024
178e784
split rest client into with auth and without aut
ZohebShaikh Oct 21, 2024
1a7615b
updated system tests to use oauth
ZohebShaikh Oct 22, 2024
5409b27
made system test cleaner
ZohebShaikh Oct 22, 2024
83374ee
added code review changes
ZohebShaikh Oct 23, 2024
59cf009
deleted dead code
ZohebShaikh Oct 23, 2024
5cff5ae
added new rabbit mq
ZohebShaikh Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading