@@ -9,7 +9,7 @@ ms.topic: how-to
9
9
ms.author : franksolomon
10
10
author : fbsolo-ms1
11
11
ms.reviewer : ambadal
12
- ms.date : 07/24 /2024
12
+ ms.date : 11/19 /2024
13
13
ms.custom : data4ml, devx-track-azurecli
14
14
# Customer intent: As an experienced data scientist with Python skills, I have data located in external sources outside of Azure. I need to make that data available to the Azure Machine Learning platform, to train my machine learning models.
15
15
---
@@ -124,13 +124,18 @@ from azure.ai.ml import MLClient
124
124
from azure.ai.ml.entities import WorkspaceConnection
125
125
from azure.ai.ml.entities import UsernamePasswordConfiguration
126
126
127
+ # If using username/password, the name/password values should be url-encoded
128
+ import urllib.parse
129
+ username = urllib.parse.quote(os.environ[" SNOWFLAKEDB_USERNAME" ], safe = " " )
130
+ password = urllib.parse.quote(os.environ[" SNOWFLAKEDB_PASSWORD" ], safe = " " )
131
+
127
132
target= " jdbc:snowflake://<myaccount>.snowflakecomputing.com/?db=<mydb>&warehouse=<mywarehouse>&role=<myrole>"
128
133
# add the Snowflake account, database, warehouse name and role name here. If no role name provided it will default to PUBLIC
129
134
name= < my_snowflake_connection> # name of the connection
130
135
wps_connection = WorkspaceConnection(name = name,
131
136
type = " snowflake" ,
132
137
target = target,
133
- credentials = UsernamePasswordConfiguration(username = " < username> " , password = " < password> " )
138
+ credentials = UsernamePasswordConfiguration(username = username, password = password)
134
139
)
135
140
136
141
ml_client.connections.create_or_update(workspace_connection = wps_connection)
@@ -301,14 +306,19 @@ from azure.ai.ml import MLClient
301
306
from azure.ai.ml.entities import WorkspaceConnection
302
307
from azure.ai.ml.entities import UsernamePasswordConfiguration
303
308
309
+ # If using username/password, the name/password values should be url-encoded
310
+ import urllib.parse
311
+ username = urllib.parse.quote(os.environ[" MYSQL_USERNAME" ], safe = " " )
312
+ password = urllib.parse.quote(os.environ[" MYSQL_PASSWORD" ], safe = " " )
313
+
304
314
target= " Server=tcp:<myservername>,<port>;Database=<mydatabase>;Trusted_Connection=False;Encrypt=True;Connection Timeout=30"
305
315
# add the sql servername, port address and database
306
316
307
317
name= < my_sql_connection> # name of the connection
308
318
wps_connection = WorkspaceConnection(name = name,
309
319
type = " azure_sql_db" ,
310
320
target = target,
311
- credentials = UsernamePasswordConfiguration(username = " < username> " , password = " < password> " )
321
+ credentials = UsernamePasswordConfiguration(username = username, password = password)
312
322
)
313
323
314
324
ml_client.connections.create_or_update(workspace_connection = wps_connection)
@@ -532,6 +542,11 @@ The following example creates a Python feed connection. A Personal Access Token
532
542
from azure.ai.ml.entities import WorkspaceConnection
533
543
from azure.ai.ml.entities import UsernamePasswordConfiguration, PatTokenConfiguration
534
544
545
+ # If using username/password, the name/password values should be url-encoded
546
+ # import urllib.parse
547
+ # username = urllib.parse.quote(os.environ["FEED_USERNAME"], safe="")
548
+ # password = urllib.parse.quote(os.environ["FEED_PASSWORD"], safe="")
549
+
535
550
536
551
name = " my_pfeed_conn"
537
552
@@ -541,7 +556,7 @@ wps_connection = WorkspaceConnection(
541
556
name = name,
542
557
type = " python_feed" ,
543
558
target = target,
544
- # credentials=UsernamePasswordConfiguration(username="< username>" , password="< password>" ),
559
+ # credentials=UsernamePasswordConfiguration(username=username, password=password),
545
560
credentials = PatTokenConfiguration(pat = " <PatTokenConfiguration>" ),
546
561
547
562
# credentials=None
@@ -587,6 +602,10 @@ The following example creates an Azure Container Registry connection. A managed
587
602
from azure.ai.ml.entities import WorkspaceConnection
588
603
from azure.ai.ml.entities import UsernamePasswordConfiguration
589
604
605
+ # If using username/password, the name/password values should be url-encoded
606
+ import urllib.parse
607
+ username = urllib.parse.quote(os.environ[" REGISTRY_USERNAME" ], safe = " " )
608
+ password = urllib.parse.quote(os.environ[" REGISTRY_PASSWORD" ], safe = " " )
590
609
591
610
name = " my_acr_conn"
592
611
@@ -596,7 +615,7 @@ wps_connection = WorkspaceConnection(
596
615
name = name,
597
616
type = " container_registry" ,
598
617
target = target,
599
- credentials = UsernamePasswordConfiguration(username = " < username> " , password = " < password> " ),
618
+ credentials = UsernamePasswordConfiguration(username = username, password = password),
600
619
)
601
620
ml_client.connections.create_or_update(workspace_connection = wps_connection)
602
621
```
@@ -710,16 +729,18 @@ from azure.ai.ml.entities import UsernamePasswordConfiguration
710
729
from azureml.core.conda_dependencies import CondaDependencies
711
730
from azure.ai.ml import command
712
731
732
+ # If using username/password, the name/password values should be url-encoded
733
+ import urllib.parse
734
+ username = urllib.parse.quote(os.environ[" REGISTRY_USERNAME" ], safe = " " )
735
+ password = urllib.parse.quote(os.environ[" REGISTRY_PASSWORD" ], safe = " " )
736
+
713
737
# Enter details of AML workspace
714
738
subscription_id = " <SUBSCRIPTION_ID>"
715
739
resource_group = " <RESOURCE_GROUP>"
716
740
workspace = " <AML_WORKSPACE_NAME>"
717
741
718
742
ml_client = MLClient( DefaultAzureCredential(), subscription_id, resource_group, workspace)
719
- # Fetching secrets from env var to secure access, these secrets can be set outside or source code
720
- registry_username = os.environ[" REGISTRY_USERNAME" ]
721
- registry_password = os.environ[" REGISTRY_PASSWORD" ]
722
- credentials = UsernamePasswordConfiguration(username = registry_username, password = registry_password)
743
+ credentials = UsernamePasswordConfiguration(username = username, password = password)
723
744
724
745
# Create GenericContainerRegistry workspace connection for a generic registry
725
746
ws_connection = WorkspaceConnection(name = " <name>" , target = " <target>" , type = " GenericContainerRegistry" , credentials = credentials)
0 commit comments