Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#431)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.5.7 → v0.6.1](astral-sh/ruff-pre-commit@v0.5.7...v0.6.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Aug 20, 2024
1 parent 72c5e84 commit a4f1cbc
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
rev: v0.6.1
hooks:
- id: ruff
args: ["--fix"]
290 changes: 162 additions & 128 deletions notebooks/admin_users.ipynb
Original file line number Diff line number Diff line change
@@ -1,131 +1,165 @@
{
"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.11.3"
}
"cells": [
{
"cell_type": "markdown",
"id": "aada09ce-8738-4253-ab06-b0b040d69845",
"metadata": {},
"source": "# User administration\n\nThis notebook allows managing users using [fps-auth](https://github.com/jupyter-server/jupyverse/tree/9d5e516803cef3f540df1292e3e807f91a7cf859/plugins/auth) in `auth.mode=user`.\n\nThis notebook can be executed with Jupyverse using another authentication method (`fps-auth` in `auth.mode=noauth` or `auth.mode=token`, or [fps-noauth](https://github.com/jupyter-server/jupyverse/tree/9d5e516803cef3f540df1292e3e807f91a7cf859/plugins/noauth)), or JupyterLab."
},
"nbformat_minor": 5,
"nbformat": 4,
"cells": [
{
"id": "aada09ce-8738-4253-ab06-b0b040d69845",
"cell_type": "markdown",
"source": "# User administration\n\nThis notebook allows managing users using [fps-auth](https://github.com/jupyter-server/jupyverse/tree/9d5e516803cef3f540df1292e3e807f91a7cf859/plugins/auth) in `auth.mode=user`.\n\nThis notebook can be executed with Jupyverse using another authentication method (`fps-auth` in `auth.mode=noauth` or `auth.mode=token`, or [fps-noauth](https://github.com/jupyter-server/jupyverse/tree/9d5e516803cef3f540df1292e3e807f91a7cf859/plugins/noauth)), or JupyterLab.",
"metadata": {}
},
{
"id": "00bf24ed-b9e7-49a5-9185-d72e0278b01a",
"cell_type": "code",
"source": "from admin_users import (\n UserUpdate,\n create_user,\n delete_user,\n get_users,\n get_user_by_email,\n show_users,\n update_user\n)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "fd644b84-8bd5-4ec1-8743-791f19f78553",
"cell_type": "markdown",
"source": "# Show users",
"metadata": {
"trusted": false
}
},
{
"id": "79400eb8-7f00-4e5a-adb1-c468642b1c42",
"cell_type": "code",
"source": "users = await get_users()\nshow_users(users, include_attrs=[\"username\", \"email\", \"permissions\", \"anonymous\"])",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "2a50596e-956a-4e73-a70d-1a03470a662c",
"cell_type": "markdown",
"source": "# Create new user",
"metadata": {
"trusted": false
}
},
{
"id": "e6e42e04-1463-43d0-a1f1-ba023c527875",
"cell_type": "code",
"source": "permissions = dict(\n contents=[\"read\", \"write\"],\n kernels=[\"read\", \"write\", \"execute\"],\n kernelspecs=[\"read\"],\n sessions=[\"read\", \"write\"],\n terminals=[\"read\", \"write\", \"execute\"],\n)\nuser = await create_user(\"king\", \"king.arthur@camelot.bt\", \"guinevere\", permissions=permissions)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "26e7ad14-ce6d-4a92-b4f1-d854d4605816",
"cell_type": "markdown",
"source": "# Update user",
"metadata": {
"trusted": false
}
},
{
"id": "0d74cdb6-c5a7-4fb4-92f7-e588d1e3f9ba",
"cell_type": "code",
"source": "user_update = UserUpdate(\n username=\"queen\",\n permissions=user.permissions,\n)\nuser = await update_user(user_update, user)\nuser.username",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "66a97369-4ec5-4f86-8bb9-30b47df059b3",
"cell_type": "markdown",
"source": "# Get user",
"metadata": {
"trusted": false
}
},
{
"id": "fa87c62b-b5e7-48d8-8724-0f6687d252c5",
"cell_type": "code",
"source": "user = await get_user_by_email(\"king.arthur@camelot.bt\")\nuser.username",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
},
{
"id": "f54aaf55-a622-4af9-8b82-b46d7ef2abc2",
"cell_type": "markdown",
"source": "# Delete user",
"metadata": {
"trusted": false
}
},
{
"id": "0e3d21f2-c442-4b86-b047-be38140e5193",
"cell_type": "code",
"source": "await delete_user(user)",
"metadata": {
"trusted": true
},
"outputs": [],
"execution_count": null
}
]
{
"cell_type": "code",
"execution_count": null,
"id": "00bf24ed-b9e7-49a5-9185-d72e0278b01a",
"metadata": {
"trusted": true
},
"outputs": [],
"source": [
"from admin_users import (\n",
" UserUpdate,\n",
" create_user,\n",
" delete_user,\n",
" get_user_by_email,\n",
" get_users,\n",
" show_users,\n",
" update_user,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "fd644b84-8bd5-4ec1-8743-791f19f78553",
"metadata": {
"trusted": false
},
"source": "# Show users"
},
{
"cell_type": "code",
"execution_count": null,
"id": "79400eb8-7f00-4e5a-adb1-c468642b1c42",
"metadata": {
"trusted": true
},
"outputs": [],
"source": [
"users = await get_users()\n",
"show_users(users, include_attrs=[\"username\", \"email\", \"permissions\", \"anonymous\"])"
]
},
{
"cell_type": "markdown",
"id": "2a50596e-956a-4e73-a70d-1a03470a662c",
"metadata": {
"trusted": false
},
"source": "# Create new user"
},
{
"cell_type": "code",
"execution_count": null,
"id": "e6e42e04-1463-43d0-a1f1-ba023c527875",
"metadata": {
"trusted": true
},
"outputs": [],
"source": [
"permissions = dict(\n",
" contents=[\"read\", \"write\"],\n",
" kernels=[\"read\", \"write\", \"execute\"],\n",
" kernelspecs=[\"read\"],\n",
" sessions=[\"read\", \"write\"],\n",
" terminals=[\"read\", \"write\", \"execute\"],\n",
")\n",
"user = await create_user(\"king\", \"king.arthur@camelot.bt\", \"guinevere\", permissions=permissions)"
]
},
{
"cell_type": "markdown",
"id": "26e7ad14-ce6d-4a92-b4f1-d854d4605816",
"metadata": {
"trusted": false
},
"source": "# Update user"
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d74cdb6-c5a7-4fb4-92f7-e588d1e3f9ba",
"metadata": {
"trusted": true
},
"outputs": [],
"source": [
"user_update = UserUpdate(\n",
" username=\"queen\",\n",
" permissions=user.permissions,\n",
")\n",
"user = await update_user(user_update, user)\n",
"user.username"
]
},
{
"cell_type": "markdown",
"id": "66a97369-4ec5-4f86-8bb9-30b47df059b3",
"metadata": {
"trusted": false
},
"source": "# Get user"
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa87c62b-b5e7-48d8-8724-0f6687d252c5",
"metadata": {
"trusted": true
},
"outputs": [],
"source": [
"user = await get_user_by_email(\"king.arthur@camelot.bt\")\n",
"user.username"
]
},
{
"cell_type": "markdown",
"id": "f54aaf55-a622-4af9-8b82-b46d7ef2abc2",
"metadata": {
"trusted": false
},
"source": "# Delete user"
},
{
"cell_type": "code",
"execution_count": null,
"id": "0e3d21f2-c442-4b86-b047-be38140e5193",
"metadata": {
"trusted": true
},
"outputs": [],
"source": [
"await delete_user(user)"
]
}
],
"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.11.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit a4f1cbc

Please sign in to comment.