From ccee9d70beb94e6d89e5383b2bf1b99404fff28e Mon Sep 17 00:00:00 2001 From: Vadim Troshchinskiy Date: Tue, 29 Oct 2024 12:19:30 +0100 Subject: [PATCH] Add organization API call --- installer/opengnsys_git_installer.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/installer/opengnsys_git_installer.py b/installer/opengnsys_git_installer.py index 5ab6d27..ffe6811 100755 --- a/installer/opengnsys_git_installer.py +++ b/installer/opengnsys_git_installer.py @@ -613,6 +613,26 @@ class OpengnsysGitInstaller: self.__logger.info("Request status was %i", r.status_code) + def add_forgejo_organization(self, pubkey, description = ""): + token = "" + with open(os.path.join(self.base_path, "etc", "ogGitApiToken.cfg"), "r", encoding='utf-8') as token_file: + token = token_file.read().strip() + + self.__logger.info("Adding SSH key to Forgejo: %s", pubkey) + + r = requests.post( + f"http://localhost:{self.forgejo_port}/api/v1/user/keys", + json={ + "key" : pubkey, + "read_only" : False, + "title" : description + }, headers={ + 'Authorization' : f"token {token}" + }, + timeout = 60 + ) + + self.__logger.info("Request status was %i", r.status_code)