|
28 | 28 | "\n", |
29 | 29 | "**Note:** \n", |
30 | 30 | "\n", |
31 | | - "- Replace all placeholders (e.g., `<GIT_USERNAME>`, `<GIT_PAT>`, `<AIDP_WORKSPACE_PATH>`, `<GIT_REPO_NAME>`, `<GIT_BRANCH>` etc.) with values specific to your environment before running the notebook. \n", |
| 31 | + "- Replace all placeholders (e.g., `<GIT_USERNAME>`, `<GIT_PAT>`, `<AIDP_WORKSPACE_PATH>`, `<GIT_REPO_NAME>`, `<GIT_BRANCH>`, `<IS_PRIVATE_REPO>` etc.) with values specific to your environment before running the notebook. \n", |
| 32 | + "- GIT_PAT is mandatory only for private repository.\n", |
32 | 33 | "- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n", |
33 | 34 | "- This notebook should be executed from AIDP.\n", |
34 | 35 | "- Hardcoding Git token into the notebook leaves credentials vulnerable. It is strongly advised to manage the token securely by loading it dynamically from an environment variable, a secure configuration file, or a OCI Vault." |
|
49 | 50 | "source": [ |
50 | 51 | "# Username of Github\n", |
51 | 52 | "git_username = \"<GIT_USERNAME>\"\n", |
52 | | - "# Access Token of Github\n", |
| 53 | + "# Access Token of Github, needed for Private Repository.\n", |
53 | 54 | "git_pat = \"<GIT_PAT>\"\n", |
54 | 55 | "# AIDP Workspace path to download repository\n", |
55 | 56 | "aidp_path = \"<AIDP_WORKSPACE_PATH>\"\n", |
56 | 57 | "# Github Repository Name\n", |
57 | 58 | "git_repo_name = \"<GIT_REPO_NAME>\"\n", |
58 | 59 | "# Github Branch Name\n", |
59 | | - "git_branch = \"<GIT_BRANCH>\"" |
| 60 | + "git_branch = \"<GIT_BRANCH>\"\n", |
| 61 | + "# Field 'is_private_repo' should be provided as a boolean (True/False).\n", |
| 62 | + "is_private_repo = \"<IS_PRIVATE_REPO>\"" |
60 | 63 | ] |
61 | 64 | }, |
62 | 65 | { |
|
76 | 79 | "import zipfile\n", |
77 | 80 | "import io\n", |
78 | 81 | "\n", |
79 | | - "if not git_pat:\n", |
80 | | - " raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n", |
81 | | - "\n", |
82 | 82 | "zip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n", |
83 | 83 | "\n", |
84 | 84 | "try:\n", |
85 | | - " # Headers for PAT authentication\n", |
86 | 85 | " headers = {\n", |
87 | | - " \"Authorization\": f\"token {git_pat}\",\n", |
88 | 86 | " \"Accept\": \"application/vnd.github.v3+json\"\n", |
89 | 87 | " }\n", |
90 | 88 | "\n", |
| 89 | + " #Authorization requires only for Private Repo.\n", |
| 90 | + " if is_private_repo:\n", |
| 91 | + " if not git_pat:\n", |
| 92 | + " raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n", |
| 93 | + " headers[\"Authorization\"] = f\"token {git_pat}\"\n", |
| 94 | + " \n", |
91 | 95 | " print(f\"Downloading ZIP from {zip_url}...\")\n", |
92 | 96 | " response = requests.get(zip_url, headers=headers, stream=True)\n", |
93 | 97 | " response.raise_for_status()\n", |
|
105 | 109 | "except zipfile.BadZipFile:\n", |
106 | 110 | " print(\"Downloaded file is not a valid ZIP file.\")\n", |
107 | 111 | "except Exception as e:\n", |
108 | | - " print(f\"An unexpected error occurred: {e}\")\n" |
| 112 | + " print(f\"An unexpected error occurred: {e}\")" |
109 | 113 | ] |
110 | 114 | } |
111 | 115 | ], |
|
0 commit comments