From 343ef469193cc3b93a9fdac133e4037e91cea544 Mon Sep 17 00:00:00 2001 From: newererer <2915467924@qq.com> Date: Sun, 21 Aug 2022 12:15:57 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=B0=81=E8=A3=85API=20https://docs.github?= =?UTF-8?q?.com/en/rest/users/keys#list-public-ssh-keys-for-the-authentica?= =?UTF-8?q?ted-user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/apps/apps.py | 2 ++ api/apps/permission.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 api/apps/permission.py diff --git a/api/apps/apps.py b/api/apps/apps.py index da3a787..c757f5a 100644 --- a/api/apps/apps.py +++ b/api/apps/apps.py @@ -1,11 +1,13 @@ from core.rest_client import RestClient from api.apps.installactions import Installation +from api.apps.permission import Permission class Apps(RestClient): def __init__(self, api_root_url, **kwargs): super(Apps, self).__init__(api_root_url, **kwargs) self.installaction = Installation(self.api_root_url, **kwargs) + self.permission = Permission(self.api_root_url, **kwargs) def create_gitHub_app_from_a_manifest(self, code, **kwargs): """ diff --git a/api/apps/permission.py b/api/apps/permission.py new file mode 100644 index 0000000..99ffe80 --- /dev/null +++ b/api/apps/permission.py @@ -0,0 +1,12 @@ +from core.rest_client import RestClient + + +class Permission(RestClient): + def list_ssh_for_current_user(self, **kwargs): + """ + https://docs.github.com/en/rest/users/keys#list-public-ssh-keys-for-the-authenticated-user + :param kwargs: + :return: + """ + headers = {'Accept': 'application/vnd.github+json'} + return self.get("/user/keys", headers=headers, **kwargs) From 4568233f1c2b9f91f9bd75e43737e7ce27b09955 Mon Sep 17 00:00:00 2001 From: newererer <2915467924@qq.com> Date: Sun, 28 Aug 2022 07:45:28 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgithub=E4=B8=ADmain?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/interactions/orgs.py | 3 ++- api/interactions/repos.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/api/interactions/orgs.py b/api/interactions/orgs.py index 912f709..2ee1171 100644 --- a/api/interactions/orgs.py +++ b/api/interactions/orgs.py @@ -2,7 +2,8 @@ class Orgs(RestClient): - def __init__(self): + def __init__(self, api_root_url, **kwargs): + super(Orgs, self).__init__(api_root_url, **kwargs) self.headers = {'Accept': 'application/vnd.github.sombra-preview'} def get_interactions_limits_for_org(self, org, **kwargs): diff --git a/api/interactions/repos.py b/api/interactions/repos.py index c4fc7c0..d728a21 100644 --- a/api/interactions/repos.py +++ b/api/interactions/repos.py @@ -2,7 +2,8 @@ class Repos(RestClient): - def __init__(self): + def __init__(self, api_root_url, **kwargs): + super(Repos, self).__init__(api_root_url, **kwargs) self.headers = {'Accept': 'application/vnd.github.sombra-preview'} def get_interaction_restrictions_for_repo(self, owner, **kwargs): From b5235d34de541a07ef7b718dfdce872c6a7b18d1 Mon Sep 17 00:00:00 2001 From: newererer <2915467924@qq.com> Date: Sun, 28 Aug 2022 07:45:57 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=B0=81=E8=A3=85API=20https://docs.github?= =?UTF-8?q?.com/en/rest/users/keys#create-a-public-ssh-key-for-the-authent?= =?UTF-8?q?icated-user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/apps/permission.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/apps/permission.py b/api/apps/permission.py index 99ffe80..06e6a33 100644 --- a/api/apps/permission.py +++ b/api/apps/permission.py @@ -10,3 +10,12 @@ def list_ssh_for_current_user(self, **kwargs): """ headers = {'Accept': 'application/vnd.github+json'} return self.get("/user/keys", headers=headers, **kwargs) + + def create_ssh_for_current_user(self, **kwargs): + """ + https://docs.github.com/en/rest/users/keys#create-a-public-ssh-key-for-the-authenticated-user + :param kwargs: + :return: + """ + headers = {'Accept': 'application/vnd.github+json'} + return self.post("/user/keys", headers=headers, **kwargs) From c92bd2534188a36445bea64bcb708c5e6b720ac4 Mon Sep 17 00:00:00 2001 From: newererer <2915467924@qq.com> Date: Sun, 28 Aug 2022 08:00:33 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=B0=81=E8=A3=85API=20https://docs.github?= =?UTF-8?q?.com/en/rest/users/keys#get-a-public-ssh-key-for-the-authentica?= =?UTF-8?q?ted-user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/apps/permission.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/apps/permission.py b/api/apps/permission.py index 06e6a33..4f0d07e 100644 --- a/api/apps/permission.py +++ b/api/apps/permission.py @@ -19,3 +19,13 @@ def create_ssh_for_current_user(self, **kwargs): """ headers = {'Accept': 'application/vnd.github+json'} return self.post("/user/keys", headers=headers, **kwargs) + + def get_a_ssh_for_current_user(self, key_id, **kwargs): + """ + https://docs.github.com/en/rest/users/keys#get-a-public-ssh-key-for-the-authenticated-user + :param key_id: SSH key id + :param kwargs: + :return: + """ + headers = {'Accept': 'application/vnd.github+json'} + return self.get("/user/keys/{}".format(key_id), headers=headers, **kwargs) From 4bd1bf0a988dd484a44a3869620135d1df16835d Mon Sep 17 00:00:00 2001 From: newererer <2915467924@qq.com> Date: Sun, 28 Aug 2022 08:05:16 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=B0=81=E8=A3=85API=20https://docs.github?= =?UTF-8?q?.com/en/rest/users/keys#delete-a-public-ssh-key-for-the-authent?= =?UTF-8?q?icated-user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/apps/permission.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/apps/permission.py b/api/apps/permission.py index 4f0d07e..f6d14ff 100644 --- a/api/apps/permission.py +++ b/api/apps/permission.py @@ -29,3 +29,13 @@ def get_a_ssh_for_current_user(self, key_id, **kwargs): """ headers = {'Accept': 'application/vnd.github+json'} return self.get("/user/keys/{}".format(key_id), headers=headers, **kwargs) + + def delete_a_ssh_for_current_user(self, key_id, **kwargs): + """ + https://docs.github.com/en/rest/users/keys#delete-a-public-ssh-key-for-the-authenticated-user + :param key_id: SSH key id + :param kwargs: + :return: + """ + headers = {'Accept': 'application/vnd.github+json'} + return self.delete("/user/keys/{}".format(key_id), headers=headers, **kwargs)