From 244fbf958adc50fb4e291832e527fa916f038397 Mon Sep 17 00:00:00 2001 From: Roman Skurikhin Date: Mon, 8 Nov 2021 17:10:21 +0200 Subject: [PATCH] Fix create cluster user --- neuro_admin_client/__init__.py | 36 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/neuro_admin_client/__init__.py b/neuro_admin_client/__init__.py index 74485e4..b976043 100644 --- a/neuro_admin_client/__init__.py +++ b/neuro_admin_client/__init__.py @@ -343,14 +343,15 @@ async def create_cluster_user( payload = { "user_name": user_name, "role": role.value, - "quota": {"total_running_jobs": quota.total_running_jobs}, - "balance": { - "credits": str(balance.credits) if balance.credits else None, - "spent_credits": str(balance.spent_credits) - if balance.spent_credits - else None, - }, + "quota": {}, + "balance": {}, } + if quota.total_running_jobs: + payload["quota"]["total_running_jobs"] = quota.total_running_jobs + if balance.credits: + payload["balance"]["credits"] = str(balance.credits) + if balance.spent_credits: + payload["balance"]["spent_credits"] = str(balance.spent_credits) async with self._request( "POST", @@ -380,16 +381,19 @@ async def update_cluster_user( payload = { "user_name": cluster_user.user_name, "role": cluster_user.role.value, - "quota": {"total_running_jobs": cluster_user.quota.total_running_jobs}, - "balance": { - "credits": str(cluster_user.balance.credits) - if cluster_user.balance.credits - else None, - "spent_credits": str(cluster_user.balance.spent_credits) - if cluster_user.balance.spent_credits - else None, - }, + "quota": {}, + "balance": {}, } + if cluster_user.quota.total_running_jobs: + payload["quota"][ + "total_running_jobs" + ] = cluster_user.quota.total_running_jobs + if cluster_user.balance.credits: + payload["balance"]["credits"] = str(cluster_user.balance.credits) + if cluster_user.balance.spent_credits: + payload["balance"]["spent_credits"] = str( + cluster_user.balance.spent_credits + ) async with self._request( "PUT",