@@ -37,7 +37,38 @@ def get(self, name: str, *, include_credentials: Optional[bool] = False, **kwarg
37
37
:raises ~azure.core.exceptions.HttpResponseError:
38
38
"""
39
39
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
41
72
42
73
return super ()._get (name , ** kwargs )
43
74
@@ -58,7 +89,5 @@ def get_default(
58
89
"""
59
90
connections = super ().list (connection_type = connection_type , default_connection = True , ** kwargs )
60
91
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 )
64
93
raise ValueError (f"No default connection found for type: { connection_type } ." )
0 commit comments