From c4617b05ae4ba8f6b712d018671b56164e71c767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Sat, 23 May 2026 23:50:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=A02.3:=20=D1=84=D0=B8=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=B0=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8?= =?UTF-8?q?=D1=8F=20(TCP/UDP/HTTP/Wireshark/Gitea)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 11 +++-------- api_git_example.py | 6 ++++++ gitea_create_repo.py | 19 +++++++++++++++++++ gitea_read_user.py | 13 +++++++++++++ token.py | 8 -------- 5 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 gitea_create_repo.py create mode 100644 gitea_read_user.py delete mode 100644 token.py diff --git a/.gitignore b/.gitignore index 4699beb..8cbfe3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,9 @@ -# виртуальное окружение venv/ .env/ - -# кеши Python __pycache__/ *.pyc - -# файлы среды разработки .vscode/ .idea/ - -# прочие временные файлы -*.log \ No newline at end of file +*.log +api_git_example.py +token.py \ No newline at end of file diff --git a/api_git_example.py b/api_git_example.py index e69de29..02cd765 100644 --- a/api_git_example.py +++ b/api_git_example.py @@ -0,0 +1,6 @@ +import requests + +TOKEN = "GIT_VYATSU_TOKEN1" +headers = {"Authorization": f"token {TOKEN}"} +response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers) +print(response.json()) \ No newline at end of file diff --git a/gitea_create_repo.py b/gitea_create_repo.py new file mode 100644 index 0000000..6fa1864 --- /dev/null +++ b/gitea_create_repo.py @@ -0,0 +1,19 @@ +import os +import requests + +TOKEN = os.getenv("GITEA_WRITE_TOKEN") +headers = { + "Authorization": f"token {TOKEN}", + "Content-Type": "application/json" +} + +data = { + "name": "lab3-api-repo", + "description": "Репозиторий создан через Gitea API", + "private": False, + "auto_init": True +} + +response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", json=data, headers=headers) +print(response.status_code) +print(response.json()) \ No newline at end of file diff --git a/gitea_read_user.py b/gitea_read_user.py new file mode 100644 index 0000000..361b8cf --- /dev/null +++ b/gitea_read_user.py @@ -0,0 +1,13 @@ +import os +import requests + +TOKEN = os.getenv("GITEA_READ_TOKEN") + +if not TOKEN: + raise RuntimeError("Переменная окружения GITEA_READ_TOKEN не задана") + +headers = {"Authorization": f"token {TOKEN}"} +response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers) + +print(response.status_code) +print(response.text) \ No newline at end of file diff --git a/token.py b/token.py deleted file mode 100644 index 982b134..0000000 --- a/token.py +++ /dev/null @@ -1,8 +0,0 @@ -import os -import requests - -TOKEN = os.getenv("GIT_VYATSU_TOKEN") # токен через переменную окружения -headers = {"Authorization": f"token {TOKEN}"} - -response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers) -print(response.json()) \ No newline at end of file