|
1 | 1 | import base64 |
| 2 | +import json |
| 3 | +from pathlib import Path |
2 | 4 | from typing import Union, AsyncGenerator |
3 | 5 |
|
4 | 6 | from symphony.bdk.core.auth.auth_session import AuthSession |
|
21 | 23 | from symphony.bdk.gen.pod_model.followers_list_response import FollowersListResponse |
22 | 24 | from symphony.bdk.gen.pod_model.following_list_response import FollowingListResponse |
23 | 25 | from symphony.bdk.gen.pod_model.role_detail import RoleDetail |
| 26 | +from symphony.bdk.gen.pod_model.service_account_manifest import ServiceAccountManifest |
24 | 27 | from symphony.bdk.gen.pod_model.string_id import StringId |
25 | 28 | from symphony.bdk.gen.pod_model.user_filter import UserFilter |
26 | 29 | from symphony.bdk.gen.pod_model.user_id_list import UserIdList |
@@ -260,10 +263,12 @@ def __init__(self, user_api: UserApi, |
260 | 263 | audit_trail_api: AuditTrailApi, |
261 | 264 | system_api: SystemApi, |
262 | 265 | auth_session: AuthSession, |
263 | | - retry_config: BdkRetryConfig): |
| 266 | + retry_config: BdkRetryConfig, |
| 267 | + manifest: str): |
264 | 268 | super().__init__(user_api, users_api, auth_session, retry_config) |
265 | 269 | self._audit_trail_api = audit_trail_api |
266 | 270 | self._system_api = system_api |
| 271 | + self._manifest = manifest |
267 | 272 |
|
268 | 273 | @retry |
269 | 274 | async def get_user_detail( |
@@ -898,3 +903,40 @@ async def unsuspend( |
898 | 903 | } |
899 | 904 |
|
900 | 905 | await self._user_api.v1_admin_user_user_id_suspension_update_put(**params) |
| 906 | + |
| 907 | + @retry |
| 908 | + async def update_manifest_from_json(self, manifest_data: str) -> None: |
| 909 | + """ |
| 910 | + Updates the user manifest from a JSON string. |
| 911 | +
|
| 912 | + :param manifest_data: A JSON string. |
| 913 | + :raises json.JSONDecodeError: If the string is not valid JSON. |
| 914 | + """ |
| 915 | + await self._user_api.v1_user_manifest_own_post( |
| 916 | + session_token=await self._auth_session.session_token, |
| 917 | + manifest=ServiceAccountManifest(manifest_data) |
| 918 | + ) |
| 919 | + |
| 920 | + async def update_manifest_from_file(self) -> None: |
| 921 | + """ |
| 922 | + Updates the user manifest using the file mentioned in config.yaml under 'manifest'. |
| 923 | +
|
| 924 | + :raises FileNotFoundError: If the file does not exist. |
| 925 | + :raises json.JSONDecodeError: If the file content is not valid JSON. |
| 926 | + :raises IOError: If the file can't be read. |
| 927 | + """ |
| 928 | + file_path = Path(self._manifest) |
| 929 | + |
| 930 | + with file_path.open('r', encoding='utf-8') as f: |
| 931 | + content = json.load(f) |
| 932 | + manifest_text = json.dumps(content) |
| 933 | + |
| 934 | + await self._user_api.v1_user_manifest_own_post( |
| 935 | + session_token=await self._auth_session.session_token, |
| 936 | + manifest=ServiceAccountManifest(manifest_text) |
| 937 | + ) |
| 938 | + |
| 939 | + @retry |
| 940 | + async def get_manifest(self) -> ServiceAccountManifest: |
| 941 | + """Retrieves own user manifest""" |
| 942 | + return await self._user_api.v1_user_manifest_own_get(session_token=await self._auth_session.session_token) |
0 commit comments