Skip to content

Commit 6afaa2d

Browse files
Merge pull request #1560 from Blackmist/usernamepassword-note
updates per PM
2 parents 40e0aeb + 7211998 commit 6afaa2d

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

articles/machine-learning/how-to-connection.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.topic: how-to
99
ms.author: franksolomon
1010
author: fbsolo-ms1
1111
ms.reviewer: ambadal
12-
ms.date: 07/24/2024
12+
ms.date: 11/19/2024
1313
ms.custom: data4ml, devx-track-azurecli
1414
# 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.
1515
---
@@ -124,13 +124,18 @@ from azure.ai.ml import MLClient
124124
from azure.ai.ml.entities import WorkspaceConnection
125125
from azure.ai.ml.entities import UsernamePasswordConfiguration
126126

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+
127132
target= "jdbc:snowflake://<myaccount>.snowflakecomputing.com/?db=<mydb>&warehouse=<mywarehouse>&role=<myrole>"
128133
# add the Snowflake account, database, warehouse name and role name here. If no role name provided it will default to PUBLIC
129134
name= <my_snowflake_connection> # name of the connection
130135
wps_connection = WorkspaceConnection(name= name,
131136
type="snowflake",
132137
target= target,
133-
credentials= UsernamePasswordConfiguration(username="<username>", password="<password>")
138+
credentials= UsernamePasswordConfiguration(username=username, password=password)
134139
)
135140

136141
ml_client.connections.create_or_update(workspace_connection=wps_connection)
@@ -301,14 +306,19 @@ from azure.ai.ml import MLClient
301306
from azure.ai.ml.entities import WorkspaceConnection
302307
from azure.ai.ml.entities import UsernamePasswordConfiguration
303308

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+
304314
target= "Server=tcp:<myservername>,<port>;Database=<mydatabase>;Trusted_Connection=False;Encrypt=True;Connection Timeout=30"
305315
# add the sql servername, port address and database
306316

307317
name= <my_sql_connection> # name of the connection
308318
wps_connection = WorkspaceConnection(name= name,
309319
type="azure_sql_db",
310320
target= target,
311-
credentials= UsernamePasswordConfiguration(username="<username>", password="<password>")
321+
credentials= UsernamePasswordConfiguration(username=username, password=password)
312322
)
313323

314324
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
532542
from azure.ai.ml.entities import WorkspaceConnection
533543
from azure.ai.ml.entities import UsernamePasswordConfiguration, PatTokenConfiguration
534544

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+
535550

536551
name = "my_pfeed_conn"
537552

@@ -541,7 +556,7 @@ wps_connection = WorkspaceConnection(
541556
name=name,
542557
type="python_feed",
543558
target=target,
544-
#credentials=UsernamePasswordConfiguration(username="<username>", password="<password>"),
559+
#credentials=UsernamePasswordConfiguration(username=username, password=password),
545560
credentials=PatTokenConfiguration(pat="<PatTokenConfiguration>"),
546561

547562
#credentials=None
@@ -587,6 +602,10 @@ The following example creates an Azure Container Registry connection. A managed
587602
from azure.ai.ml.entities import WorkspaceConnection
588603
from azure.ai.ml.entities import UsernamePasswordConfiguration
589604

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="")
590609

591610
name = "my_acr_conn"
592611

@@ -596,7 +615,7 @@ wps_connection = WorkspaceConnection(
596615
name=name,
597616
type="container_registry",
598617
target=target,
599-
credentials=UsernamePasswordConfiguration(username="<username>", password="<password>"),
618+
credentials=UsernamePasswordConfiguration(username=username, password=password),
600619
)
601620
ml_client.connections.create_or_update(workspace_connection=wps_connection)
602621
```
@@ -710,16 +729,18 @@ from azure.ai.ml.entities import UsernamePasswordConfiguration
710729
from azureml.core.conda_dependencies import CondaDependencies
711730
from azure.ai.ml import command
712731

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+
713737
# Enter details of AML workspace
714738
subscription_id = "<SUBSCRIPTION_ID>"
715739
resource_group = "<RESOURCE_GROUP>"
716740
workspace = "<AML_WORKSPACE_NAME>"
717741

718742
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)
723744

724745
# Create GenericContainerRegistry workspace connection for a generic registry
725746
ws_connection = WorkspaceConnection(name="<name>", target="<target>", type="GenericContainerRegistry", credentials=credentials)

0 commit comments

Comments
 (0)