Skip to content

Commit

Permalink
Add Client.me() method to get current permissions (#62)
Browse files Browse the repository at this point in the history
* add Client.me() method to get current permissions

* update CHANGELOG

* me is good name

* dump docker logs from tests
  • Loading branch information
atimin authored Dec 22, 2022
1 parent ef7d27b commit e4c3ecb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ jobs:
run: pip3 install .[test]

- name: Run Reduct Storage
run: docker run -p 8383:8383 -v ${PWD}/data:/data --env RS_API_TOKEN=${{matrix.token}} -d ghcr.io/reductstore/reductstore:latest
run: docker run -p 8383:8383 -v ${PWD}/data:/data --env RS_API_TOKEN=${{matrix.token}} --env RS_LOG_LEVEL=DEBUG -d ghcr.io/reductstore/reductstore:latest

- name: Run Tests
run: PYTHONPATH=. RS_API_TOKEN=${{matrix.token}} pytest tests

- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2

pylint:
needs: build
runs-on: ubuntu-latest
Expand Down
4 changes: 0 additions & 4 deletions .pylintrc

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added:

- Client.me() method to get current permissions, [PR-62](https://github.com/reductstore/reduct-py/pull/62)

### Changed:

- Update documentation after rebranding, [PR-59](https://github.com/reductstore/reduct-py/pull/59)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ asyncio_mode = "strict"

[tool.pylint]
max-line-length = 88
extension-pkg-whitelist = "pydantic"
extension-pkg-whitelist = "pydantic"
good-names = "me"
10 changes: 10 additions & 0 deletions reduct/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,13 @@ async def remove_token(self, name: str) -> None:
ReductError: if there is an HTTP error
"""
await self._http.request_all("DELETE", f"/tokens/{name}")

async def me(self) -> FullTokenInfo:
"""
Get information about the current token
Returns:
FullTokenInfo
Raises:
ReductError: if there is an HTTP error
"""
return FullTokenInfo.parse_raw(await self._http.request_all("GET", "/me"))
16 changes: 15 additions & 1 deletion tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
QuotaType,
BucketSettings,
Permissions,
FullTokenInfo,
)
from .conftest import requires_env

Expand Down Expand Up @@ -61,7 +62,7 @@ async def test__info(client):
await sleep(1)

info: ServerInfo = await client.info()
assert info.version >= "0.7.0"
assert info.version >= "1.2.0"
assert info.uptime >= 1
assert info.bucket_count == 2
assert info.usage == 66
Expand Down Expand Up @@ -216,3 +217,16 @@ async def test__remove_token(client, with_token):
ReductError, match="Status 404: Token 'test-token' doesn't exist"
):
await client.get_token(with_token)


@requires_env("RS_API_TOKEN")
@pytest.mark.asyncio
async def test__me(client):
"""Should get user info"""
current_token: FullTokenInfo = await client.me()
assert current_token.name == "init-token"
assert current_token.permissions.dict() == {
"full_access": True,
"read": [],
"write": [],
}

0 comments on commit e4c3ecb

Please sign in to comment.