Skip to content

Commit

Permalink
Feature/simple app user access (#55)
Browse files Browse the repository at this point in the history
* Add function to get current user.

* Add function to get current user.

* Fixed typo.

* Work in progress.

* Added documentation for class Availability.

* Added support for current user API.

* Fixed limiting.

* Finalized current user support.

* Linting fixes.

* Removed obsolete imports.

* Code cleanup.

* Testing code tweaks; Adding support for TFA Settings at user level.

* Added function to logout all users.

---------

Co-authored-by: Christoph Souris <christoph.souris@gmail.com>
  • Loading branch information
chsou and chisou authored Jul 2, 2024
1 parent 62a8dc1 commit da3471c
Show file tree
Hide file tree
Showing 13 changed files with 598 additions and 118 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea*
.vscode*
.pytest*
__pycache__
dist*
build*
Expand Down
1 change: 1 addition & 0 deletions c8y_api/_base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CumulocityRestApi:

ACCEPT_MANAGED_OBJECT = 'application/vnd.com.nsn.cumulocity.managedobject+json'
ACCEPT_USER = 'application/vnd.com.nsn.cumulocity.user+json'
ACCEPT_CURRENT_USER = 'application/vnd.com.nsn.cumulocity.currentuser+json'
ACCEPT_GLOBAL_ROLE = 'application/vnd.com.nsn.cumulocity.group+json'
CONTENT_AUDIT_RECORD = 'application/vnd.com.nsn.cumulocity.auditrecord+json'
CONTENT_MANAGED_OBJECT = 'application/vnd.com.nsn.cumulocity.managedobject+json'
Expand Down
1 change: 1 addition & 0 deletions c8y_api/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'Fragment',
'NamedObject',
'User',
'CurrentUser',
'GlobalRole',
'Permission',
'ReadPermission',
Expand Down
2 changes: 1 addition & 1 deletion c8y_api/model/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ def _iterate(self, base_query: str, page_number: int | None, limit: int, parse_f
break
for result in results:
result.c8y = self.c8y # inject c8y connection into instance
yield result
if limit and num_results >= limit:
break
yield result
num_results = num_results + 1
# when a specific page was specified we don't read more pages
if page_number:
Expand Down
6 changes: 4 additions & 2 deletions c8y_api/model/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class SimpleObjectParser(object):
a simple field mapping dictionary.
"""

def __init__(self, mapping):
self._obj_to_json = {**mapping, 'id': 'id'}
def __init__(self, mapping: dict = None, **kwargs):
if mapping is None:
mapping = {}
self._obj_to_json = {**mapping, 'id': 'id', **kwargs}
self._json_to_object = {v: k for k, v in self._obj_to_json.items()}

def from_json(self, obj_json, new_obj, skip=None):
Expand Down
Loading

0 comments on commit da3471c

Please sign in to comment.