Skip to content

Commit 10f7d29

Browse files
authored
Merge pull request #10 from kbase/dev-client
Add usage and release notes and version
2 parents ff09b0c + fa0bcf4 commit 10f7d29

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,70 @@ TODO INSTALL setup a KBase pypi org and publish there
1212

1313
## Usage
1414

15-
TODO USAGE
15+
Both sync and async versions of the client are provided - `KBaseAuthClient`
16+
and `AsyncKBaseAuthClient`, respectively. Here we demonstrate usage of the async client -
17+
to use the sync client, just switch the client name when creating the client and remove the
18+
`async` and `await` keywords. The examples assume there is a valid KBase token in the
19+
`token` variable.
20+
21+
Note that all methods have internal caches and further caching is not necessary.
22+
23+
Replace the CI environment url with the url of the environment you wish to query.
24+
25+
### Get the version of the auth service
26+
27+
```python
28+
from kbase.auth import AsyncKBaseAuthClient
29+
30+
async with await AsyncKBaseAuthClient.create("https://ci.kbase.us/services/auth") as cli:
31+
print(await cli.service_version())
32+
0.7.2
33+
```
34+
35+
### Get a token
36+
37+
This is the cheapest method to get a KBase username from a token.
38+
39+
```python
40+
from kbase.auth import AsyncKBaseAuthClient
41+
42+
async with await AsyncKBaseAuthClient.create("https://ci.kbase.us/services/auth") as cli:
43+
print(await cli.get_token(token))
44+
Token(id='67797406-c6a3-4ee0-870d-976739dacd61', user='gaprice', created=1755561300704, expires=1763337300704, cachefor=300000)
45+
```
46+
47+
### Get a user
48+
49+
```python
50+
from kbase.auth import AsyncKBaseAuthClient
51+
52+
async with await AsyncKBaseAuthClient.create("https://ci.kbase.us/services/auth") as cli:
53+
print(await cli.get_user(token))
54+
User(user='gaprice', customroles=['KBASE_STAFF', 'goofypants'])
55+
```
56+
57+
### Validate usernames
58+
59+
```python
60+
from kbase.auth import AsyncKBaseAuthClient
61+
62+
async with await AsyncKBaseAuthClient.create("https://ci.kbase.us/services/auth") as cli:
63+
print(await cli.validate_usernames(token, "gaprice", "superfake"))
64+
{'gaprice': True, 'superfake': False}
65+
```
66+
67+
### Without a context manager
68+
69+
The clients can be used without a context manager, in which case the user is responsible for
70+
ensuring they're closed:
71+
72+
```python
73+
from kbase.auth import AsyncKBaseAuthClient
74+
75+
cli = await AsyncKBaseAuthClient.create("https://ci.kbase.us/services/auth")
76+
77+
await cli.close()
78+
```
1679

1780
## Development
1881

@@ -40,6 +103,7 @@ uv run scripts/process_unasync.py
40103
* Releases
41104
* The main branch is the stable branch. Releases are made from the develop branch to the main
42105
branch.
106+
* Update the version in `auth.py`.
43107
* Tag the version in git and github.
44108
* Create a github release.
45109

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0
2+
3+
* Initial release

src/kbase/_auth/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ class User:
3939

4040
VALID_USER_FIELDS: set[str] = {f.name for f in fields(User)}
4141
"""
42-
The field names for the user dataclass.
42+
The field names for the User dataclass.
4343
"""

src/kbase/auth.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
Token, # @UnusedImport
1414
User, # @UnusedImport
1515
)
16+
17+
18+
__version__ = "0.1.0"

test/test_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
KBaseAuthClient,
1313
Token,
1414
User,
15+
__version__ as ver,
1516
)
1617

1718

19+
def test_version():
20+
assert ver == "0.1.0"
21+
22+
1823
async def _create_fail(url: str, expected: Exception, cachesize=1, timer=time.time):
1924
with pytest.raises(type(expected), match=f"^{expected.args[0]}$"):
2025
KBaseAuthClient.create(url, cache_max_size=cachesize, timer=timer)

0 commit comments

Comments
 (0)