Skip to content

Commit fffe7c0

Browse files
Eugene FedorenkoEugene Fedorenko
authored andcommitted
fixing auth error on invoking ML pipeline
1 parent 51f7193 commit fffe7c0

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

docs/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Add a command line step **Run Training Pipeline** with the following script:
127127
```bash
128128
docker run -v $(System.DefaultWorkingDirectory)/_ci-build/mlops-pipelines/ml_service/pipelines:/pipelines \
129129
-w=/pipelines -e MODEL_NAME=$MODEL_NAME -e EXPERIMENT_NAME=$EXPERIMENT_NAME \
130-
-e TENANT_ID=$TENANT_ID -e SP_APP_ID=$SP_APP_ID -e SP_APP_SECRET=$SP_APP_SECRET \
130+
-e TENANT_ID=$TENANT_ID -e SP_APP_ID=$SP_APP_ID -e SP_APP_SECRET=$(SP_APP_SECRET) \
131131
mcr.microsoft.com/mlops/python:latest python run_train_pipeline.py
132132
```
133133

environment_setup/Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@ COPY environment_setup/requirements.txt /setup/
1010

1111
RUN apt-get update && apt-get install gcc -y && pip install --upgrade -r /setup/requirements.txt
1212

13-
COPY environment_setup/python.sh /usr/local/sbin/python.sh
14-
RUN rm /usr/local/bin/python && ln -s /usr/local/sbin/python.sh /usr/local/bin/python
15-
16-
1713
CMD ["python"]

ml_service/pipelines/run_train_pipeline.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
import os
33
import json
44
import requests
5-
from azureml.core.authentication import AzureCliAuthentication
5+
from azure.common.credentials import ServicePrincipalCredentials
66

77

8+
tenant_id = os.environ.get("TENANT_ID")
9+
app_id = os.environ.get("SP_APP_ID")
10+
app_secret = os.environ.get("SP_APP_SECRET")
11+
812
try:
913
with open("train_pipeline.json") as f:
1014
train_pipeline_json = json.load(f)
@@ -15,16 +19,24 @@
1519
experiment_name = os.environ.get("EXPERIMENT_NAME")
1620
model_name = os.environ.get("MODEL_NAME")
1721

18-
cli_auth = AzureCliAuthentication()
19-
token = cli_auth.get_authentication_header()
22+
credentials = ServicePrincipalCredentials(
23+
client_id=app_id,
24+
secret=app_secret,
25+
tenant=tenant_id
26+
)
27+
28+
token = credentials.token['access_token']
29+
print("token", token)
30+
auth_header = {"Authorization": "Bearer " + token}
2031

2132
rest_endpoint = train_pipeline_json["rest_endpoint"]
2233

2334
response = requests.post(
24-
rest_endpoint, headers=token,
35+
rest_endpoint, headers=auth_header,
2536
json={"ExperimentName": experiment_name,
2637
"ParameterAssignments": {"model_name": model_name}}
2738
)
2839

2940
run_id = response.json()["Id"]
3041
print("Pipeline run initiated ", run_id)
42+

0 commit comments

Comments
 (0)