Skip to content

Commit

Permalink
[promptflow][Test] Sanitize email username in recordings (#1335)
Browse files Browse the repository at this point in the history
# Description

Sanitize email username to `username` in recording.

# All Promptflow Contribution checklist:
- [x] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [x] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [x] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [x] Title of the pull request is clear and informative.
- [x] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [x] Pull request includes test coverage for the included changes.
  • Loading branch information
zhengfeiwang authored Nov 30, 2023
1 parent c7e52a8 commit 54a2fce
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
AzureResourceProcessor,
AzureWorkspaceTriadProcessor,
DropProcessor,
EmailProcessor,
IndexServiceProcessor,
PFSProcessor,
RecordingProcessor,
Expand Down Expand Up @@ -140,6 +141,7 @@ def _get_recording_processors(self) -> List[RecordingProcessor]:
AzureResourceProcessor(),
AzureWorkspaceTriadProcessor(),
DropProcessor(),
EmailProcessor(),
IndexServiceProcessor(),
PFSProcessor(),
StorageProcessor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class SanitizedValues:
# trick: "unknown_user" is the value when client fails to get username
# use this value so that we don't do extra logic when replay
USERNAME = "unknown_user"
# MISC
EMAIL_USERNAME = "username"


class AzureMLResourceTypes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
is_json_payload_request,
is_json_payload_response,
sanitize_azure_workspace_triad,
sanitize_email,
sanitize_experiment_id,
sanitize_pfs_body,
sanitize_upload_hash,
Expand Down Expand Up @@ -245,3 +246,11 @@ def process_response(self, response: Dict) -> Dict:
body.pop("continuationToken", None)
response["body"]["string"] = json.dumps(body)
return response


class EmailProcessor(RecordingProcessor):
"""Sanitize email address in responses."""

def process_response(self, response: Dict) -> Dict:
response["body"]["string"] = sanitize_email(response["body"]["string"])
return response
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ def sanitize_pfs_body(body: str) -> str:
return json.dumps(body_dict)


def sanitize_email(value: str) -> str:
return re.sub(r"([\w\.-]+)@([\w\.-]+)", r"{}@\2".format(SanitizedValues.EMAIL_USERNAME), value)


def _is_json_payload(headers: Dict, key: str) -> bool:
if not headers:
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ interactions:
Connection:
- keep-alive
User-Agent:
- promptflow-sdk/0.0.1 azure-ai-ml/1.10.0 azsdk-python-mgmt-machinelearningservices/0.1.0
Python/3.10.13 (Windows-10-10.0.22621-SP0)
- promptflow-sdk/0.0.1 promptflow/0.0.1 azure-ai-ml/1.12.1 azsdk-python-mgmt-machinelearningservices/0.1.0
Python/3.10.13 (Windows-10-10.0.22631-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/api-version=2023-06-01-preview
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/api-version=2023-08-01-preview
response:
body:
string: '{"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000",
"name": "00000", "type": "Microsoft.MachineLearningServices/workspaces", "location":
"eastus", "tags": {}, "etag": null, "kind": "Default", "sku": {"name": "Basic",
"tier": "Basic"}}'
"tier": "Basic"}, "properties": {"discoveryUrl": "https://eastus.api.azureml.ms/discovery"}}'
headers:
cache-control:
- no-cache
content-length:
- '3519'
- '3630'
content-type:
- application/json; charset=utf-8
expires:
Expand All @@ -39,7 +39,7 @@ interactions:
x-content-type-options:
- nosniff
x-request-time:
- '0.022'
- '0.017'
status:
code: 200
message: OK
Expand All @@ -53,8 +53,8 @@ interactions:
Connection:
- keep-alive
User-Agent:
- promptflow-sdk/0.0.1 azure-ai-ml/1.10.0 azsdk-python-mgmt-machinelearningservices/0.1.0
Python/3.10.13 (Windows-10-10.0.22621-SP0)
- promptflow-sdk/0.0.1 promptflow/0.0.1 azure-ai-ml/1.12.1 azsdk-python-mgmt-machinelearningservices/0.1.0
Python/3.10.13 (Windows-10-10.0.22631-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/datastores?api-version=2023-04-01-preview&count=30&isDefault=true&orderByAsc=false
response:
Expand Down Expand Up @@ -91,7 +91,7 @@ interactions:
x-content-type-options:
- nosniff
x-request-time:
- '0.268'
- '0.070'
status:
code: 200
message: OK
Expand All @@ -114,19 +114,20 @@ interactions:
body:
string: '{"tags": null, "location": null, "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/connections/azure_open_ai_connection",
"name": "azure_open_ai_connection", "type": "Microsoft.MachineLearningServices/workspaces/connections",
"properties": {"authType": "ApiKey", "credentials": {"key": "_"}, "category":
"AzureOpenAI", "expiryTime": null, "target": "_", "createdByWorkspaceArmId":
"properties": {"authType": "ApiKey", "credentials": {"key": "_"}, "group":
"AzureAI", "category": "AzureOpenAI", "expiryTime": null, "target": "_", "createdByWorkspaceArmId":
null, "isSharedToAll": false, "sharedUserList": [], "metadata": {"azureml.flow.connection_type":
"AzureOpenAI", "azureml.flow.module": "promptflow.connections", "ApiType":
"azure", "ApiVersion": "2023-07-01-preview", "ResourceId": null}}, "systemData":
{"createdAt": "2023-08-22T10:15:34.5762053Z", "createdBy": "[email protected]",
"createdByType": "User", "lastModifiedAt": "2023-08-22T10:15:34.5762053Z",
"lastModifiedBy": "[email protected]", "lastModifiedByType": "User"}}'
"azure", "ApiVersion": "2023-07-01-preview", "ResourceId": null, "DeploymentApiVersion":
"2023-10-01-preview"}}, "systemData": {"createdAt": "2023-08-22T10:15:34.5762053Z",
"createdBy": "[email protected]", "createdByType": "User", "lastModifiedAt":
"2023-08-22T10:15:34.5762053Z", "lastModifiedBy": "[email protected]",
"lastModifiedByType": "User"}}'
headers:
cache-control:
- no-cache
content-length:
- '1170'
- '1246'
content-type:
- application/json; charset=utf-8
expires:
Expand All @@ -142,7 +143,7 @@ interactions:
x-content-type-options:
- nosniff
x-request-time:
- '0.197'
- '0.072'
status:
code: 200
message: OK
Expand All @@ -165,18 +166,18 @@ interactions:
body:
string: '{"tags": null, "location": null, "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/connections/custom_connection",
"name": "custom_connection", "type": "Microsoft.MachineLearningServices/workspaces/connections",
"properties": {"authType": "CustomKeys", "credentials": {"keys": {}}, "category":
"CustomKeys", "expiryTime": null, "target": "_", "createdByWorkspaceArmId":
"properties": {"authType": "CustomKeys", "credentials": {"keys": {}}, "group":
"AzureAI", "category": "CustomKeys", "expiryTime": null, "target": "_", "createdByWorkspaceArmId":
null, "isSharedToAll": false, "sharedUserList": [], "metadata": {"azureml.flow.connection_type":
"Custom", "azureml.flow.module": "promptflow.connections"}}, "systemData":
{"createdAt": "2023-06-19T20:56:12.0353964Z", "createdBy": "sejuare@microsoft.com",
{"createdAt": "2023-06-19T20:56:12.0353964Z", "createdBy": "username@microsoft.com",
"createdByType": "User", "lastModifiedAt": "2023-06-19T20:56:12.0353964Z",
"lastModifiedBy": "sejuare@microsoft.com", "lastModifiedByType": "User"}}'
"lastModifiedBy": "username@microsoft.com", "lastModifiedByType": "User"}}'
headers:
cache-control:
- no-cache
content-length:
- '1251'
- '1275'
content-type:
- application/json; charset=utf-8
expires:
Expand All @@ -192,7 +193,7 @@ interactions:
x-content-type-options:
- nosniff
x-request-time:
- '0.259'
- '0.075'
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ interactions:
Connection:
- keep-alive
User-Agent:
- promptflow-sdk/0.0.1 azure-ai-ml/1.10.0 azsdk-python-mgmt-machinelearningservices/0.1.0
Python/3.10.13 (Windows-10-10.0.22621-SP0)
- promptflow-sdk/0.0.1 promptflow/0.0.1 azure-ai-ml/1.12.1 azsdk-python-mgmt-machinelearningservices/0.1.0
Python/3.10.13 (Windows-10-10.0.22631-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/api-version=2023-06-01-preview
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/api-version=2023-08-01-preview
response:
body:
string: '{"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000",
"name": "00000", "type": "Microsoft.MachineLearningServices/workspaces", "location":
"eastus", "tags": {}, "etag": null, "kind": "Default", "sku": {"name": "Basic",
"tier": "Basic"}}'
"tier": "Basic"}, "properties": {"discoveryUrl": "https://eastus.api.azureml.ms/discovery"}}'
headers:
cache-control:
- no-cache
content-length:
- '3519'
- '3630'
content-type:
- application/json; charset=utf-8
expires:
Expand All @@ -39,7 +39,7 @@ interactions:
x-content-type-options:
- nosniff
x-request-time:
- '0.029'
- '0.023'
status:
code: 200
message: OK
Expand All @@ -53,8 +53,8 @@ interactions:
Connection:
- keep-alive
User-Agent:
- promptflow-sdk/0.0.1 azure-ai-ml/1.10.0 azsdk-python-mgmt-machinelearningservices/0.1.0
Python/3.10.13 (Windows-10-10.0.22621-SP0)
- promptflow-sdk/0.0.1 promptflow/0.0.1 azure-ai-ml/1.12.1 azsdk-python-mgmt-machinelearningservices/0.1.0
Python/3.10.13 (Windows-10-10.0.22631-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/datastores?api-version=2023-04-01-preview&count=30&isDefault=true&orderByAsc=false
response:
Expand Down Expand Up @@ -91,7 +91,7 @@ interactions:
x-content-type-options:
- nosniff
x-request-time:
- '0.107'
- '0.058'
status:
code: 200
message: OK
Expand All @@ -105,16 +105,16 @@ interactions:
Connection:
- keep-alive
User-Agent:
- promptflow-sdk/0.0.1 azsdk-python-azuremachinelearningdesignerserviceclient/unknown
Python/3.10.13 (Windows-10-10.0.22621-SP0)
- promptflow-sdk/0.0.1 promptflow/0.0.1 azsdk-python-azuremachinelearningdesignerserviceclient/unknown
Python/3.10.13 (Windows-10-10.0.22631-SP0)
method: GET
uri: https://eastus.api.azureml.ms/flow/api/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/Connections/azure_open_ai_connection
response:
body:
string: '{"connectionName": "azure_open_ai_connection", "connectionType": "AzureOpenAI",
"configs": {"api_base": "https://fake.openai.azure.com", "api_key": null,
"api_type": "azure", "api_version": "2023-07-01-preview", "resource_id": null},
"owner": {"userName": "yigao@microsoft.com"}, "createdDate": "2023-08-22T10:15:34.5762053Z",
"owner": {"userName": "username@microsoft.com"}, "createdDate": "2023-08-22T10:15:34.5762053Z",
"lastModifiedDate": "2023-08-22T10:15:34.5762053Z"}'
headers:
connection:
Expand All @@ -132,7 +132,7 @@ interactions:
x-content-type-options:
- nosniff
x-request-time:
- '0.345'
- '0.382'
status:
code: 200
message: OK
Expand All @@ -146,14 +146,14 @@ interactions:
Connection:
- keep-alive
User-Agent:
- promptflow-sdk/0.0.1 azsdk-python-azuremachinelearningdesignerserviceclient/unknown
Python/3.10.13 (Windows-10-10.0.22621-SP0)
- promptflow-sdk/0.0.1 promptflow/0.0.1 azsdk-python-azuremachinelearningdesignerserviceclient/unknown
Python/3.10.13 (Windows-10-10.0.22631-SP0)
method: GET
uri: https://eastus.api.azureml.ms/flow/api/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/00000/providers/Microsoft.MachineLearningServices/workspaces/00000/Connections/custom_connection
response:
body:
string: '{"connectionName": "custom_connection", "connectionType": "Custom",
"owner": {"userName": "sejuare@microsoft.com"}, "createdDate": "2023-06-19T20:56:12.0353964Z",
"owner": {"userName": "username@microsoft.com"}, "createdDate": "2023-06-19T20:56:12.0353964Z",
"lastModifiedDate": "2023-06-19T20:56:12.0353964Z"}'
headers:
connection:
Expand All @@ -167,7 +167,7 @@ interactions:
x-content-type-options:
- nosniff
x-request-time:
- '0.336'
- '0.367'
status:
code: 200
message: OK
Expand Down

0 comments on commit 54a2fce

Please sign in to comment.