Skip to content

Commit

Permalink
fix aml workspace schema types mismatch for show operation (Azure#27269)
Browse files Browse the repository at this point in the history
* Update changelog

* fix workspace.identity.UAI types mismatch for show operation

* revert the change log

* fix pylint issue

Co-authored-by: Diondra Peck <16376603+diondrapeck@users.noreply.github.com>
Co-authored-by: Mingwei He <mingweihe@microsoft.com>
  • Loading branch information
3 people authored Nov 3, 2022
1 parent 502727b commit ed691f3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion sdk/ml/azure-ai-ml/azure/ai/ml/_schema/workspace/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# pylint: disable=unused-argument,no-self-use

from marshmallow import fields
from marshmallow.decorators import post_load
from marshmallow.decorators import post_load, pre_dump

from azure.ai.ml._schema.core.fields import NestedField, StringTransformedEnum
from azure.ai.ml._schema.core.schema_meta import PatchedSchemaMeta
Expand Down Expand Up @@ -40,6 +40,12 @@ class IdentitySchema(metaclass=PatchedSchemaMeta):
keys=fields.Str(required=True), values=NestedField(UserAssignedIdentitySchema, allow_none=True), allow_none=True
)

@pre_dump
def predump(self, data, **kwargs):
if data and isinstance(data, IdentityConfiguration):
data.user_assigned_identities = self.uai_list2dict(data.user_assigned_identities)
return data

@post_load
def make(self, data, **kwargs):
data["user_assigned_identities"] = self.uai_dict2list(data.pop("user_assigned_identities"))
Expand All @@ -55,3 +61,17 @@ def uai_dict2list(self, uai_dict):
p_id = meta.principal_id
res.append(ManagedIdentityConfiguration(resource_id=resource_id, client_id=c_id, principal_id=p_id))
return res

def uai_list2dict(self, uai_list):
res = {}
if uai_list and isinstance(uai_list, list):
for uai in uai_list:
if not isinstance(uai, ManagedIdentityConfiguration):
continue
meta = {}
if uai.client_id:
meta["client_id"] = uai.client_id
if uai.principal_id:
meta["principal_id"] = uai.principal_id
res[uai.resource_id] = meta
return res if res else None

0 comments on commit ed691f3

Please sign in to comment.