Skip to content

Commit 0133d7a

Browse files
Added basic manifest support
1 parent 4ba042c commit 0133d7a

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

symphony/bdk/core/config/model/bdk_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, **config):
3030
self.datafeed = BdkDatafeedConfig(config.get("datafeed"))
3131
self.datahose = BdkDatahoseConfig(config.get("datahose"))
3232
self.retry = BdkRetryConfig(config.get("retry"))
33+
self.manifest = config.get("manifest")
3334

3435
def is_bot_configured(self) -> bool:
3536
"""

symphony/bdk/core/service/user/user_service.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import base64
2+
import json
3+
from pathlib import Path
24
from typing import Union, AsyncGenerator
35

46
from symphony.bdk.core.auth.auth_session import AuthSession
@@ -21,6 +23,7 @@
2123
from symphony.bdk.gen.pod_model.followers_list_response import FollowersListResponse
2224
from symphony.bdk.gen.pod_model.following_list_response import FollowingListResponse
2325
from symphony.bdk.gen.pod_model.role_detail import RoleDetail
26+
from symphony.bdk.gen.pod_model.service_account_manifest import ServiceAccountManifest
2427
from symphony.bdk.gen.pod_model.string_id import StringId
2528
from symphony.bdk.gen.pod_model.user_filter import UserFilter
2629
from symphony.bdk.gen.pod_model.user_id_list import UserIdList
@@ -260,10 +263,12 @@ def __init__(self, user_api: UserApi,
260263
audit_trail_api: AuditTrailApi,
261264
system_api: SystemApi,
262265
auth_session: AuthSession,
263-
retry_config: BdkRetryConfig):
266+
retry_config: BdkRetryConfig,
267+
manifest: str):
264268
super().__init__(user_api, users_api, auth_session, retry_config)
265269
self._audit_trail_api = audit_trail_api
266270
self._system_api = system_api
271+
self._manifest = manifest
267272

268273
@retry
269274
async def get_user_detail(
@@ -898,3 +903,40 @@ async def unsuspend(
898903
}
899904

900905
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)

symphony/bdk/core/service_factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def get_user_service(self) -> UserService:
7474
AuditTrailApi(self._agent_client),
7575
PodSystemApi(self._pod_client),
7676
self._auth_session,
77-
self._config.retry
77+
self._config.retry,
78+
self._config.manifest
7879
)
7980

8081
def get_message_service(self) -> MessageService:

0 commit comments

Comments
 (0)