def get_repository_api_instance_user_cred( username: str, password: str) -> giteapy.RepositoryApi: configuration = giteapy.Configuration() configuration.username = username configuration.password = password configuration.host = 'https://git.curiosityworks.org/api/v1' return giteapy.RepositoryApi(giteapy.ApiClient(configuration))
def __init__(self, dcs_domain=None, api_version=API_LATEST_VERSION, catalog_version=CATALOG_NEXT_LATEST_VERSION, debug=False): self.dcs_domain = dcs_domain if dcs_domain: self.cs_domain = dcs_domain elif debug: self.dcs_domain = QA_DCS_DOMAIN else: self.dcs_domain = PRODUCTION_DCS_DOMAIN self.api_base_url = f"{dcs_domain}/api/v{api_version}" self.catalog_url = f"{dcs_domain}/api/catalog/v{catalog_version}" self.api_config = giteapy.Configuration() self.api_config.host = self.api_base_url self.gitea_api = giteapy.ApiClient(configuration=self.api_config) self.repo_api = giteapy.RepositoryApi(api_client=self.gitea_api)
def backup_gitea(gitea_url: str, gitea_token: str, gitea_backup_dir: str): configuration = giteapy.Configuration() configuration.host = gitea_url + "/api/v1" configuration.api_key['access_token'] = gitea_token api_instance = giteapy.UserApi(giteapy.ApiClient(configuration)) api_response = api_instance.user_current_list_repos() print(f"{api_response}") for project in api_response: print('----------------------') print("id: %d " % project.id) print("url: " + project.html_url) print("ssh: " + project.ssh_url) print("name: " + project.name) print("path with namespace: " + project.full_name) local_git_path = gitea_backup_dir + '/' + project.full_name + ".git" local_namespace_path = gitea_backup_dir + '/' + project.name if not os.path.exists(local_namespace_path): os.makedirs(local_namespace_path) backup_git_project(local_git_path, project.html_url, project.ssh_url) pass
def gitea_create_exercise(admin, exercise, course, students): instance = giteapy.RepositoryApi(giteapy.ApiClient(configuration)) def _replace(line): return line \ .replace("%NAME%", exercise.name) \ .replace("%POINTS%", _format_num(exercise.max_points) if exercise.max_points != 0 else "??") def _gitea_create_exercise(exercise, username, retry=0): try: # Create a file in a repository instance.repo_create_file( course.gitea_user, username, exercise.name + "/README.md", giteapy.CreateFileOptions( author=giteapy.Identity(name=admin['username'], email=admin['email']), committer=giteapy.Identity(name=admin['username'], email=admin['email']), message="publish " + exercise.name, content=base64.b64encode('\n'.join([ _replace(line) for line in CONFIG['MARKDOWN_TEMPLATE'] ]).encode("utf-8")).decode("utf-8"))) return True except ApiException: traceback.print_exc() if retry > 5: return None return _gitea_create_exercise(exercise, username, retry + 1) _gitea_create_exercise(exercise, course.gitea_user + "-template") for student in students: if not _gitea_create_exercise(exercise, student.username): return "Could not create file in repo of Student " + student.username + ". You need to check whats wrong " \ "fast and publish the exercise " \ "again! This will cause existing " \ "files to be overridden. *grr* " return True
def _configure_connection(connection_params, api): configuration = giteapy.Configuration() configuration.host = connection_params.get('host') configuration.username = connection_params.get('username') configuration.password = connection_params.get('password') if api == "admin": api_instance = giteapy.AdminApi(giteapy.ApiClient(configuration)) elif api == "issue": api_instance = giteapy.IssueApi(giteapy.ApiClient(configuration)) elif api == "misc": api_instance = giteapy.MiscellaneousApi( giteapy.ApiClient(configuration)) elif api == "org": api_instance = giteapy.OrganizationApi( giteapy.ApiClient(configuration)) elif api == "repo": api_instance = giteapy.RepositoryApi(giteapy.ApiClient(configuration)) elif api == "user": api_instance = giteapy.UserApi(giteapy.ApiClient(configuration)) else: raise BaseException("no valid api") return api_instance
def get_repository_api_instance() -> giteapy.RepositoryApi: configuration = giteapy.Configuration() configuration.api_key['access_token'] = get_gitea_access_token() configuration.host = 'https://git.curiosityworks.org/api/v1' return giteapy.RepositoryApi(giteapy.ApiClient(configuration))
import random import string def get_random_string(length): # choose from all lowercase letter letters = string.ascii_lowercase result_str = ''.join(random.choice(letters) for i in range(length)) return result_str # Gitea connection configuration = giteapy.Configuration() configuration.api_key['access_token'] = 'superSecret' configuration.host = 'https://gitea.example.com/api/v1' admin_api_instance = giteapy.AdminApi(giteapy.ApiClient(configuration)) user_api_instance = giteapy.UserApi(giteapy.ApiClient(configuration)) org_api_instance = giteapy.OrganizationApi(giteapy.ApiClient(configuration)) # GitLab connection gl = gitlab.Gitlab('https://gitlab.example.com', private_token='superSecret') # inspect GitLab dict_gl_users = dict() # get Gitea users gt_users = admin_api_instance.admin_get_all_users() #pprint(api_response) lg_gt_map = dict() # copy users for gt_user in gt_users: pprint(gt_user)
KEYCLOAK_URL = os.environ.get('KEYCLOAK_URL') KEYCLOAK_REALM = os.environ.get('KEYCLOAK_REALM') KEYCLOAK_CLIENT_SECRET = os.environ.get('KEYCLOAK_CLIENT_SECRET') GITEA_URL = os.environ.get('GITEA_URL') GITEA_API_KEY = os.environ.get('GITEA_API_KEY') keycloak_admin = None # Configure API key authorization: AccessToken configuration = giteapy.Configuration() configuration.host = GITEA_URL configuration.api_key['access_token'] = GITEA_API_KEY # create an instance of the API class gitea_admin = giteapy.AdminApi(giteapy.ApiClient(configuration)) gitea_org = giteapy.OrganizationApi(giteapy.ApiClient(configuration)) def get_random_string(length): letters = string.ascii_lowercase result_str = ''.join(random.choice(letters) for i in range(length)) return result_str def get_keycloak_users(): retval = [] users = keycloak_admin.get_users({}) for user in users: user_groups = keycloak_admin.get_user_groups(user_id=user['id'])
import glob import git import time import giteapy from giteapy.rest import ApiException from pprint import pprint fp = open('accesstoken', 'r') line = fp.readline() # Configure API key authorization: AccessToken configuration = giteapy.Configuration() configuration.api_key['access_token'] = line # create an instance of the API class configuration.host = "https://gitbox.org/api/v1" username = '******' # str | username of the user that will own the created organization org = 'BOSI' # str | name of organization api_instance = giteapy.OrganizationApi(giteapy.ApiClient(configuration)) for subdir, dirs, files in os.walk(".\Files"): cnt = 0 for dir in dirs: x = os.path.join(subdir, dir) #print("Line {}: {}".format(cnt, x)) file = dir + '.html' try: body = giteapy.CreateRepoOption( name=dir) # CreateRepoOption | (optional) api_response = api_instance.create_org_repo(org, body=body) except ApiException as e: print("Exception when calling AdminApi->admin_create_org: %s\n" % e) cnt += 1