Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #42 from m-ynk/expose_audited_perms
Browse files Browse the repository at this point in the history
expose permission's audit value
  • Loading branch information
rohansharma authored Nov 20, 2020
2 parents 521335c + 4c5d9c3 commit e88e12a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
13 changes: 8 additions & 5 deletions groupy/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,28 @@ class ServiceAccount(User):


class Permission(object):
def __init__(self, groups):
# type: (Dict[str, Dict[str, Any]]) -> None
def __init__(self, groups, audited):
# type: (Dict[str, Dict[str, Any]], bool) -> None
self.groups = {
groupname: Group.from_payload({"data": groups[groupname]}) for groupname in groups
}
self.audited = audited

@classmethod
def from_payload(cls, payload):
# type: (Dict[str, Any]) -> Permission
return cls(payload["data"]["groups"])
return cls(payload["data"]["groups"], payload["data"]["audited"])


class MappedPermission(object):
def __init__(self, permission, argument, granted_on, distance, path):
# type: (str, str, float, Optional[int], Optional[List[str]]) -> None
def __init__(self, permission, argument, granted_on, distance, path, audited):
# type: (str, str, float, Optional[int], Optional[List[str]], Optional[bool]) -> None
self.permission = permission
self.argument = argument
self.granted_on = granted_on
self.distance = distance
self.path = path
self.audited = audited

@classmethod
def from_payload(cls, payload):
Expand All @@ -134,6 +136,7 @@ def from_payload(cls, payload):
payload["granted_on"],
payload.get("distance"),
payload.get("path"),
payload.get("audited"),
)


Expand Down
2 changes: 1 addition & 1 deletion groupy/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.2"
__version__ = "0.5.3"
16 changes: 16 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ def service_account_response(request):
}


@pytest.fixture
def permission_response(request):
# type: (str) -> Dict[Text, Any]
return {
u"checkpoint": 3,
u"checkpoint_time": 1605842894,
u"data": {
u"permission": {u"name": "grouper.audit.security"},
u"groups": {},
u"service_accounts": {},
u"audited": False,
},
u"status": u"ok",
}


@pytest.fixture
def user_response(request):
# type: (str) -> Dict[Text, Any]
Expand Down
15 changes: 15 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from mock import Mock, patch

from groupy.client import Groupy, HTTPClient
from tests.fixtures import permission_response # noqa: F401
from tests.fixtures import service_account_response # noqa: F401

if TYPE_CHECKING:
Expand Down Expand Up @@ -32,3 +33,17 @@ def test_service_account(service_account_response): # noqa: F811

expected = service_account_response["data"]["user"]["service_account"]
assert service.service_account == expected


def test_permission(permission_response): # noqa: F811
# type: (Dict[Text, Any]) -> None
res = Mock()
res.body = json.dumps(permission_response)
mock_fetch = Mock()
mock_fetch.side_effect = [res]
with patch.object(HTTPClient, "fetch", mock_fetch):
client = Groupy(["localhost:8000"])
permission = client.permissions.get("grouper.audit.security")
assert permission.groups == {}
assert isinstance(permission.audited, bool)
assert permission.audited is False

0 comments on commit e88e12a

Please sign in to comment.