def github_auto_provision(config, owner, repo): try: github.get_repository(owner, repo) except requests.exceptions.HTTPError: # repo not found github.create_repository( owner, repo, description=f'QHub {config["project_name"]}-{config["provider"]}', homepage='https://jupyter.{config["domain"]}', ) # Secrets if config["provider"] == "do": for name in { "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "SPACES_ACCESS_KEY_ID", "SPACES_SECRET_ACCESS_KEY", "DIGITALOCEAN_TOKEN", }: github.update_secret(owner, repo, name, os.environ[name]) elif config["provider"] == "aws": for name in { "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_DEFAULT_REGION", }: github.update_secret(owner, repo, name, os.environ[name]) elif config["provider"] == "gcp": github.update_secret(owner, repo, "PROJECT_ID", os.environ["PROJECT_ID"]) with open(os.environ["GOOGLE_CREDENTIALS"]) as f: github.update_secret(owner, repo, "GOOGLE_CREDENTIALS", f.read()) github.update_secret(owner, repo, "REPOSITORY_ACCESS_TOKEN", os.environ["GITHUB_TOKEN"]) return f"[email protected]:{owner}/{repo}.git"
def github_auto_provision(config, owner, repo): check_cloud_credentials( config ) # We may need env vars such as AWS_ACCESS_KEY_ID depending on provider already_exists = True try: github.get_repository(owner, repo) except requests.exceptions.HTTPError: # repo not found already_exists = False if not already_exists: try: github.create_repository( owner, repo, description= f'QHub {config["project_name"]}-{config["provider"]}', homepage=f'https://{config["domain"]}', ) except requests.exceptions.HTTPError as he: raise ValueError( f"Unable to create GitHub repo https://github.com/{owner}/{repo} - error message from GitHub is: {he}" ) else: logger.warn( f"GitHub repo https://github.com/{owner}/{repo} already exists") try: # Secrets if config["provider"] == "do": for name in { "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "SPACES_ACCESS_KEY_ID", "SPACES_SECRET_ACCESS_KEY", "DIGITALOCEAN_TOKEN", }: github.update_secret(owner, repo, name, os.environ[name]) elif config["provider"] == "aws": for name in { "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", }: github.update_secret(owner, repo, name, os.environ[name]) elif config["provider"] == "gcp": github.update_secret(owner, repo, "PROJECT_ID", os.environ["PROJECT_ID"]) with open(os.environ["GOOGLE_CREDENTIALS"]) as f: github.update_secret(owner, repo, "GOOGLE_CREDENTIALS", f.read()) elif config["provider"] == "azure": for name in { "ARM_CLIENT_ID", "ARM_CLIENT_SECRET", "ARM_SUBSCRIPTION_ID", "ARM_TENANT_ID", }: github.update_secret(owner, repo, name, os.environ[name]) github.update_secret(owner, repo, "REPOSITORY_ACCESS_TOKEN", os.environ["GITHUB_TOKEN"]) except requests.exceptions.HTTPError as he: raise ValueError( f"Unable to set Secrets on GitHub repo https://github.com/{owner}/{repo} - error message from GitHub is: {he}" ) return f"[email protected]:{owner}/{repo}.git"