@@ -37,7 +37,38 @@ def get(self, name: str, *, include_credentials: Optional[bool] = False, **kwarg
3737 :raises ~azure.core.exceptions.HttpResponseError:
3838 """
3939 if include_credentials :
40- return super ()._get_with_credentials (name , ** kwargs )
40+ connection = super ()._get_with_credentials (name , ** kwargs )
41+ if connection .type == ConnectionType .CUSTOM :
42+ # Fix for GitHub issue https://github.com/Azure/azure-sdk-for-net/issues/52355
43+ # Although the issue was filed on C# Projects SDK, the same problem exists in Python SDK.
44+ # Assume your Foundry project has a connection of type `Custom`, named "test_custom_connection",
45+ # and you defined two public and two secrete (private) keys. When you get the connection, the response
46+ # payload will look something like this:
47+ # {
48+ # "name": "test_custom_connection",
49+ # "id": "/subscriptions/.../connections/test_custom_connection",
50+ # "type": "CustomKeys",
51+ # "target": "_",
52+ # "isDefault": true,
53+ # "credentials": {
54+ # "nameofprivatekey1": "PrivateKey1",
55+ # "nameofprivatekey2": "PrivateKey2",
56+ # "type": "CustomKeys"
57+ # },
58+ # "metadata": {
59+ # "NameOfPublicKey1": "PublicKey1",
60+ # "NameOfPublicKey2": "PublicKey2"
61+ # }
62+ # }
63+ # We would like to add a new Dict property on the Python `credentials` object, named `credential_keys`,
64+ # to hold all the secret keys. This is done by the line below.
65+ setattr (
66+ connection .credentials ,
67+ "credential_keys" ,
68+ {k : v for k , v in connection .credentials .as_dict ().items () if k != "type" },
69+ )
70+
71+ return connection
4172
4273 return super ()._get (name , ** kwargs )
4374
@@ -58,7 +89,5 @@ def get_default(
5889 """
5990 connections = super ().list (connection_type = connection_type , default_connection = True , ** kwargs )
6091 for connection in connections :
61- if include_credentials :
62- connection = super ()._get_with_credentials (connection .name , ** kwargs )
63- return connection
92+ return self .get (connection .name , include_credentials = include_credentials , ** kwargs )
6493 raise ValueError (f"No default connection found for type: { connection_type } ." )
0 commit comments