-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into eelco/generic-linkedobj
- Loading branch information
Showing
74 changed files
with
2,238 additions
and
2,526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
253 changes: 253 additions & 0 deletions
253
notebooks/scenarios/bigquery/sync/000-start-and-configure-server-and-admins.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,253 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# stdlib\n", | ||
"from os import environ as env\n", | ||
"\n", | ||
"# syft absolute\n", | ||
"import syft as sy\n", | ||
"from syft.util.test_helpers.email_helpers import get_email_server" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# stdlib\n", | ||
"environment = env.get(\"ORCHESTRA_DEPLOYMENT_TYPE\", \"python\")\n", | ||
"high_port = env.get(\"CLUSTER_HTTP_PORT_HIGH\", \"9081\")\n", | ||
"low_port = env.get(\"CLUSTER_HTTP_PORT_LOW\", \"9083\")\n", | ||
"print(environment, high_port, low_port)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# when in k8s these are the default values\n", | ||
"ROOT_EMAIL = \"[email protected]\"\n", | ||
"ROOT_PASSWORD = \"bqpw\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# in case we are not in k8s we set them here for orchestra to use\n", | ||
"env[\"DEFAULT_ROOT_EMAIL\"] = ROOT_EMAIL\n", | ||
"env[\"DEFAULT_ROOT_PASSWORD\"] = ROOT_PASSWORD" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"server_low = sy.orchestra.launch(\n", | ||
" name=\"bigquery-low\",\n", | ||
" server_side_type=\"low\",\n", | ||
" dev_mode=True,\n", | ||
" reset=True,\n", | ||
" n_consumers=1,\n", | ||
" create_producer=True,\n", | ||
" port=low_port,\n", | ||
")\n", | ||
"\n", | ||
"server_high = sy.orchestra.launch(\n", | ||
" name=\"bigquery-high\",\n", | ||
" server_side_type=\"high\",\n", | ||
" dev_mode=True,\n", | ||
" reset=True,\n", | ||
" n_consumers=1,\n", | ||
" create_producer=True,\n", | ||
" port=high_port,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"email_server, smtp_server = get_email_server(reset=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"root_client_low = sy.login(\n", | ||
" url=f\"http://localhost:{low_port}\", email=ROOT_EMAIL, password=ROOT_PASSWORD\n", | ||
")\n", | ||
"root_client_high = sy.login(\n", | ||
" url=f\"http://localhost:{high_port}\", email=ROOT_EMAIL, password=ROOT_PASSWORD\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Create new admin client" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ADMIN_EMAIL, ADMIN_PW = \"[email protected]\", \"bqpw2\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# create admin account on low side\n", | ||
"root_client_low.register(\n", | ||
" name=\"second admin\", email=ADMIN_EMAIL, password=ADMIN_PW, password_verify=ADMIN_PW\n", | ||
")\n", | ||
"# update role\n", | ||
"new_user_id = root_client_low.users.search(email=ADMIN_EMAIL)[0].id\n", | ||
"root_client_low.users.update(uid=new_user_id, role=\"admin\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# create admin account on high side\n", | ||
"root_client_high.register(\n", | ||
" name=\"second admin\", email=ADMIN_EMAIL, password=ADMIN_PW, password_verify=ADMIN_PW\n", | ||
")\n", | ||
"# update role\n", | ||
"new_user_id = root_client_high.users.search(email=ADMIN_EMAIL)[0].id\n", | ||
"root_client_high.users.update(uid=new_user_id, role=\"admin\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# We cannot delete the root client" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"low_client = sy.login(\n", | ||
" url=f\"http://localhost:{low_port}\", email=ADMIN_EMAIL, password=ADMIN_PW\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"root_admin_id = low_client.users.search(email=ROOT_EMAIL)[0].id" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"with sy.raises(sy.SyftException):\n", | ||
" low_client.users.delete(root_admin_id)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Create ephemeral admin and delete it" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# register 2nd new admin (to delete)\n", | ||
"user_email, user_pw = \"[email protected]\", \"bqpw3\"\n", | ||
"## create\n", | ||
"root_client_low.register(\n", | ||
" name=\"x\", email=user_email, password=user_pw, password_verify=user_pw\n", | ||
")\n", | ||
"## update role\n", | ||
"new_user_id2 = root_client_low.users.search(email=user_email)[0].id\n", | ||
"root_client_low.users.update(uid=new_user_id2, role=\"admin\")\n", | ||
"\n", | ||
"# delete\n", | ||
"root_client_low.users.delete(new_user_id2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Cleanup" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"if environment != \"remote\":\n", | ||
" server_high.land()\n", | ||
" server_low.land()\n", | ||
"smtp_server.stop()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.