|
| 1 | +"""access_policies interface |
| 2 | +
|
| 3 | + NOT TESTED |
| 4 | +""" |
| 5 | + |
| 6 | +from .constants import ( |
| 7 | + SEP, |
| 8 | + ACCESS_POLICIES_SUBPATH, |
| 9 | + ACCESS_POLICIES_LABEL, |
| 10 | + ASSETS_LABEL, |
| 11 | +) |
| 12 | + |
| 13 | +DEFAULT_PAGE_SIZE=500 |
| 14 | + |
| 15 | + |
| 16 | +class _AccessPoliciesClient: |
| 17 | + """docstring |
| 18 | + """ |
| 19 | + def __init__(self, archivist): |
| 20 | + """docstring |
| 21 | + """ |
| 22 | + self._archivist = archivist |
| 23 | + |
| 24 | + def create(self, request): |
| 25 | + """docstring |
| 26 | + """ |
| 27 | + |
| 28 | + return AccessPolicy(**self._archivist.post( |
| 29 | + f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}", |
| 30 | + request, |
| 31 | + )) |
| 32 | + |
| 33 | + def read(self, identity): |
| 34 | + """docstring |
| 35 | + """ |
| 36 | + return AccessPolicy(**self._archivist.get( |
| 37 | + ACCESS_POLICIES_SUBPATH, |
| 38 | + identity, |
| 39 | + )) |
| 40 | + |
| 41 | + def update(self, identity, request): |
| 42 | + """docstring |
| 43 | + """ |
| 44 | + return AccessPolicy(**self._archivist.patch( |
| 45 | + ACCESS_POLICIES_SUBPATH, |
| 46 | + identity, |
| 47 | + request, |
| 48 | + )) |
| 49 | + |
| 50 | + def delete(self, identity): |
| 51 | + """docstring |
| 52 | + """ |
| 53 | + return self._archivist.delete(ACCESS_POLICIES_SUBPATH, identity) |
| 54 | + |
| 55 | + @staticmethod |
| 56 | + def __query(props): |
| 57 | + """docstring |
| 58 | + """ |
| 59 | + query = props or {} |
| 60 | + return query |
| 61 | + |
| 62 | + def count(self, *, query=None): |
| 63 | + """docstring |
| 64 | + """ |
| 65 | + return self._archivist.count( |
| 66 | + f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}", |
| 67 | + query=self.__query(query) |
| 68 | + ) |
| 69 | + |
| 70 | + def list(self, *, page_size=DEFAULT_PAGE_SIZE, query=None): |
| 71 | + """docstring |
| 72 | + """ |
| 73 | + return ( |
| 74 | + AccessPolicy(**a) for a in self._archivist.list( |
| 75 | + f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}", |
| 76 | + ACCESS_POLICIES_LABEL, |
| 77 | + page_size=page_size, |
| 78 | + query=self.__query(query) |
| 79 | + ) |
| 80 | + ) |
| 81 | + |
| 82 | + # additional queries on different endpoints |
| 83 | + def count_matching_assets(self, access_policy_id, *, query=None): |
| 84 | + """docstring |
| 85 | + """ |
| 86 | + return self._archivist.count( |
| 87 | + SEP.join((ACCESS_POLICIES_SUBPATH, access_policy_id, ASSETS_LABEL)), |
| 88 | + ASSETS_LABEL, |
| 89 | + query=self.__query(query) |
| 90 | + ) |
| 91 | + |
| 92 | + def list_matching_assets(self, access_policy_id, *, page_size=DEFAULT_PAGE_SIZE, query=None): |
| 93 | + """docstring |
| 94 | + """ |
| 95 | + return ( |
| 96 | + AccessPolicy(**a) for a in self._archivist.list( |
| 97 | + SEP.join((ACCESS_POLICIES_SUBPATH, access_policy_id, ASSETS_LABEL)), |
| 98 | + ASSETS_LABEL, |
| 99 | + page_size=page_size, |
| 100 | + query=self.__query(query) |
| 101 | + ) |
| 102 | + ) |
| 103 | + |
| 104 | + def count_matching_access_policies(self, asset_id, *, query=None): |
| 105 | + """docstring |
| 106 | + """ |
| 107 | + return self._archivist.count( |
| 108 | + SEP.join((ACCESS_POLICIES_SUBPATH, asset_id, ACCESS_POLICIES_LABEL)), |
| 109 | + ACCESS_POLICIES_LABEL, |
| 110 | + query=self.__query(query) |
| 111 | + ) |
| 112 | + |
| 113 | + def list_matching_access_policies(self, asset_id, *, page_size=DEFAULT_PAGE_SIZE, query=None): |
| 114 | + """docstring |
| 115 | + """ |
| 116 | + return ( |
| 117 | + AccessPolicy(**a) for a in self._archivist.list( |
| 118 | + SEP.join((ACCESS_POLICIES_SUBPATH, asset_id, ASSETS_LABEL)), |
| 119 | + ACCESS_POLICIES_LABEL, |
| 120 | + page_size=page_size, |
| 121 | + query=self.__query(query) |
| 122 | + ) |
| 123 | + ) |
| 124 | + |
| 125 | + |
| 126 | +class AccessPolicy(dict): |
| 127 | + """AccessPolicy object |
| 128 | + """ |
0 commit comments