Skip to content

Commit

Permalink
Add permissions endpoint (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
pederhan authored Jun 17, 2024
1 parent b3328dd commit 1c98e11
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ While the project is still on major version 0, breaking changes may be introduce

<!-- changelog follows -->

<!-- ## Unreleased -->
## Unreleased

### Added

- Permissions method:
- `HarborAsyncClient.get_permissions()`: Get system and project permissions for a user.


## [0.24.2](https://github.com/unioslo/harborapi/tree/harborapi-v0.24.2) - 2024-06-15

Expand Down
6 changes: 6 additions & 0 deletions docs/endpoints/permissions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Permissions

::: harborapi.client.HarborAsyncClient
options:
members:
- get_permissions
19 changes: 19 additions & 0 deletions harborapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from pydantic import ValidationError
from typing_extensions import deprecated

from harborapi.models.models import Permissions

from ._types import JSONType
from ._types import QueryParamMapping
from .auth import load_harbor_auth_file
Expand Down Expand Up @@ -4853,6 +4855,23 @@ async def get_audit_logs(
resp = await self.get("/audit-logs", params=params, limit=limit)
return self.construct_model(AuditLog, resp, is_list=True)

# CATEGORY: permissions
# GET /permissions
async def get_permissions(self) -> Permissions:
"""Get system and project level permissions.
!!! attention
Requires admin privileges or a privileged Robot account.
Returns
-------
Permissions
The system and project level permissions.
"""
resp = await self.get("/permissions")
return self.construct_model(Permissions, resp)

def _get_headers(self, headers: Optional[Dict[str, Any]] = None) -> Dict[str, str]:
headers = headers or {}
base_headers = {
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ nav:
- endpoints/labels.md
- endpoints/ldap.md
- endpoints/oidc.md
- endpoints/permissions.md
- endpoints/ping.md
- endpoints/projects.md
- endpoints/projectmetadata.md
Expand Down
32 changes: 32 additions & 0 deletions tests/endpoints/test_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

import pytest
from hypothesis import HealthCheck
from hypothesis import given
from hypothesis import settings
from hypothesis import strategies as st
from pytest_httpserver import HTTPServer

from harborapi.client import HarborAsyncClient
from harborapi.models.models import Permissions


@pytest.mark.asyncio
@given(st.builds(Permissions))
@settings(suppress_health_check=[HealthCheck.function_scoped_fixture])
async def test_get_permissions(
async_client: HarborAsyncClient,
httpserver: HTTPServer,
permissions: Permissions,
):
httpserver.expect_oneshot_request(
"/api/v2.0/permissions",
method="GET",
).respond_with_json(
permissions.model_dump(mode="json"),
headers={"Content-Type": "application/json"},
)
async_client.url = httpserver.url_for("/api/v2.0")

resp = await async_client.get_permissions()
assert resp == permissions

0 comments on commit 1c98e11

Please sign in to comment.