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

Add json kwarg to [Async]Client.post() #89

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

MrCreosote
Copy link
Contributor

Allows using the clients to call the callback endpoint in the Superfacility beta API.

Closes #87

Manual testing:

~/github/mrcreosote/sfapi_client$ ipython
Python 3.11.3 (main, Apr  5 2023, 14:14:40) [GCC 7.5.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.27.0 -- An enhanced Interactive Python. Type '?' for help.

In [3]: from sfapi_client import AsyncClient, Client
f
In [4]: from sfapi_client.compute import Machine

In [5]: beta_url="https://api.nersc.gov/api/beta"

In [6]: async with AsyncClient(client_id=nersc_client_id, secret=nersc_private_k
   ...: ey) as cli:
   ...:     pm = await cli.compute(Machine.perlmutter)
   ...:     ret = await pm.run("ls ~")
   ...:     print(ret)
   ...:
cdm
dots
Downloads
github
mash
minio
tmp

In [7]: with Client(client_id=nersc_client_id, secret=nersc_private_key) as cli:
   ...:
   ...:     pm = cli.compute(Machine.perlmutter)
   ...:     ret = pm.run("ls ~")
   ...:     print(ret)
   ...:
cdm
dots
Downloads
github
mash
minio
tmp

In [8]: async with AsyncClient(api_base_url=beta_url, client_id=nersc_client_id,
   ...:  secret=nersc_private_key) as cli:
   ...:     ret = await cli.post("callback/", json={
   ...:         "timeout": 10,
   ...:         "path_condition": {
   ...:             "path": "~/foo",
   ...:             "machine": "perlmutter",
   ...:         },
   ...:         "url": "https://teletubbiessuperfans.com/signup",
   ...:     })
   ...:     print(ret.json())
   ...:
{'timeout': 10, 'path_condition': {'path': '~/foo', 'machine':
'perlmutter'}, 'url': 'https://teletubbiessuperfans.com/signup'}

In [9]: with Client(api_base_url=beta_url, client_id=nersc_client_id, secret=ner
   ...: sc_private_key) as cli:
   ...:     ret = cli.post("callback/", json={
   ...:         "timeout": 10,
   ...:         "path_condition": {
   ...:             "path": "~/foo",
   ...:             "machine": "perlmutter",
   ...:         },
   ...:         "url": "https://teletubbiessuperfans.com/signup",
   ...:     })
   ...:     print(ret.json())
   ...:
{'timeout': 10, 'path_condition': {'path': '~/foo', 'machine': 
'perlmutter'}, 'url': 'https://teletubbiessuperfans.com/signup'}

Allows using the clients to call the `callback` endpoint in the
Superfacility beta API.

Manual testing:
```
~/github/mrcreosote/sfapi_client$ ipython
Python 3.11.3 (main, Apr  5 2023, 14:14:40) [GCC 7.5.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.27.0 -- An enhanced Interactive Python. Type '?' for help.

In [3]: from sfapi_client import AsyncClient, Client
f
In [4]: from sfapi_client.compute import Machine

In [5]: beta_url="https://api.nersc.gov/api/beta"

In [6]: async with AsyncClient(client_id=nersc_client_id,
secret=nersc_private_k
   ...: ey) as cli:
   ...:     pm = await cli.compute(Machine.perlmutter)
   ...:     ret = await pm.run("ls ~")
   ...:     print(ret)
   ...:
cdm
dots
Downloads
github
mash
minio
tmp

In [7]: with Client(client_id=nersc_client_id, secret=nersc_private_key)
as cli:
   ...:
   ...:     pm = cli.compute(Machine.perlmutter)
   ...:     ret = pm.run("ls ~")
   ...:     print(ret)
   ...:
cdm
dots
Downloads
github
mash
minio
tmp

In [8]: async with AsyncClient(api_base_url=beta_url,
client_id=nersc_client_id,
   ...:  secret=nersc_private_key) as cli:
   ...:     ret = await cli.post("callback/", json={
   ...:         "timeout": 10,
   ...:         "path_condition": {
   ...:             "path": "~/foo",
   ...:             "machine": "perlmutter",
   ...:         },
   ...:         "url": "https://teletubbiessuperfans.com/signup",
   ...:     })
   ...:     print(ret.json())
   ...:
{'timeout': 10, 'path_condition': {'path': '~/foo', 'machine':
'perlmutter'}, 'url': 'https://teletubbiessuperfans.com/signup'}

In [9]: with Client(api_base_url=beta_url, client_id=nersc_client_id,
secret=ner
   ...: sc_private_key) as cli:
   ...:     ret = cli.post("callback/", json={
   ...:         "timeout": 10,
   ...:         "path_condition": {
   ...:             "path": "~/foo",
   ...:             "machine": "perlmutter",
   ...:         },
   ...:         "url": "https://teletubbiessuperfans.com/signup",
   ...:     })
   ...:     print(ret.json())
   ...:
{'timeout': 10, 'path_condition': {'path': '~/foo', 'machine':
'perlmutter'}, 'url': 'https://teletubbiessuperfans.com/signup'}

```
Copy link
Collaborator

@cjh1 cjh1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to push these changes. For future reference the whole _sync directory is actually generate from the _async directory. So you can just make the changes in _async and then run python scripts/run.py unasync ( you may find more missing deps! ) and the _sync dir will be updated.

@cjh1 cjh1 merged commit c0a24bc into NERSC:main Sep 13, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add json= kwarg to [Async]Client.post()
2 participants