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

RS-176: Add license field to ServerInfo #105

Merged
merged 11 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 11 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ jobs:
strategy:
max-parallel: 5
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
python: ["3.8"]
reductstore_version: ["latest", "main"]
token: ["", "ACCESS_TOKEN"]
license: ["", "/workdir/lic.key"]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@master
Expand All @@ -88,11 +89,18 @@ jobs:
- name: Install dependencies
run: pip3 install .[test]

- name: Generate license
run: echo '${{secrets.LICENSE_KEY}}' > lic.key

- name: Run ReductStore
run: docker run -p 8383:8383 -v ${PWD}/data:/data --env RS_API_TOKEN=${{matrix.token}} --env RS_LOG_LEVEL=DEBUG -d reduct/store:main
run: docker run -p 8383:8383 -v ${PWD}:/workdir
--env RS_API_TOKEN=${{matrix.token}}
--env RS_LOG_LEVEL=DEBUG
--env RS_LICENSE_PATH=${{matrix.license}}
-d reduct/store:main

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

- name: Dump docker logs on failure
if: failure()
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added:

- RS-182: Add flag verify_ssl to Client, [PR-102](https://github.com/reductstore/reduct-py/pull/102)
- RS-176: Add license field to ServerInfo, [PR-105](https://github.com/reductstore/reduct-py/pull/105)

## [1.8.1] - 2023-01-31

Expand Down
28 changes: 28 additions & 0 deletions reduct/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ class Defaults(BaseModel):
"""settings for a new bucket"""


class LicenseInfo(BaseModel):
"""License information"""

licensee: str
"""Licensee usually is the company name"""

invoice: str
"""Invoice number"""

expiry_date: datetime
"""Expiry date of the license in ISO 8601 format (UTC)"""

plan: str
"""Plan name"""

device_number: int
"""Number of devices (0 for unlimited)"""

disk_quota: int
"""Disk quota in TB (0 for unlimited)"""

fingerprint: str
"""License fingerprint"""


class ServerInfo(BaseModel):
"""Server stats"""

Expand All @@ -38,6 +63,9 @@ class ServerInfo(BaseModel):
latest_record: int
"""UNIX timestamp of the latest record in microseconds"""

license: Optional[LicenseInfo] = None
"""license information"""

defaults: Defaults
"""Default server settings"""

Expand Down
28 changes: 24 additions & 4 deletions tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Permissions,
FullTokenInfo,
)
from .conftest import requires_env
from .conftest import requires_env, requires_api


@pytest_asyncio.fixture(name="with_token")
Expand Down Expand Up @@ -66,13 +66,33 @@ async def test__info(client):
assert info.oldest_record == 1_000_000
assert info.latest_record == 6_000_000

defaults = info.defaults.bucket.dict()
defaults = info.defaults.bucket.model_dump()
assert defaults["max_block_size"] == 64000000
assert defaults["max_block_records"] >= 256 # defaults are different in 1.6.0
assert defaults["quota_size"] == 0
assert defaults["quota_type"] == QuotaType.NONE


@pytest.mark.asyncio
@pytest.mark.usefixtures("bucket_1", "bucket_2")
@requires_env("RS_LICENSE_PATH")
@requires_api("1.9")
async def test__info_with_license(client):
"""Should get information about storage with license"""
info: ServerInfo = await client.info()
assert info.license is not None
assert info.license.device_number == 1
assert info.license.disk_quota == 0
assert info.license.expiry_date.isoformat() == "2035-01-01T00:00:00+00:00"
assert (
info.license.fingerprint
== "df92c95a7c9b56c2af99b290c39d8471c3e6cbf9dc33dc9bdb4116b98d465cc9"
)
assert info.license.invoice == "xxxxxx"
assert info.license.licensee == "ReductStore,LLC"
assert info.license.plan == "UNLIMITED"


@pytest.mark.asyncio
async def test__list(client, bucket_1, bucket_2):
"""Should browse buckets"""
Expand All @@ -87,7 +107,7 @@ async def test__list(client, bucket_1, bucket_2):
async def test__create_bucket_default_settings(client, bucket_1):
"""Should create a bucket with default settings"""
settings = await bucket_1.get_settings()
assert settings.dict() == (await client.info()).defaults.bucket.dict()
assert settings.model_dump() == (await client.info()).defaults.bucket.dict()


@pytest.mark.asyncio
Expand Down Expand Up @@ -219,7 +239,7 @@ 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() == {
assert current_token.permissions.model_dump() == {
"full_access": True,
"read": [],
"write": [],
Expand Down
Loading