|
5 | 5 | import time |
6 | 6 | import argparse |
7 | 7 | import datetime |
8 | | -from traitlets import Integer, default |
| 8 | +from traitlets import Bool, CRegExp, Integer, List, Unicode, Union, default |
9 | 9 | from traitlets.config import Configurable |
10 | 10 | from functools import partial |
11 | 11 |
|
12 | | -from config import NbGitPullerFeatures |
13 | 12 |
|
14 | 13 | def execute_cmd(cmd, **kwargs): |
15 | 14 | """ |
@@ -51,6 +50,35 @@ def flush(): |
51 | 50 |
|
52 | 51 |
|
53 | 52 | class GitPuller(Configurable): |
| 53 | + autorun_allow = Union( |
| 54 | + [List(CRegExp()), Bool()], |
| 55 | + default_value=False, |
| 56 | + config=True, |
| 57 | + help=""" |
| 58 | + List of URLs described as Python regular expressions (using re.match()) where we |
| 59 | + allow autorunning scripts in the pulled project as a pre-initialisation step. |
| 60 | + Enable this only if you understand and accept the risks of AUTORUN.INF. |
| 61 | +
|
| 62 | + When set to boolean True, all URLs are allowed, whilst False (default) autorun |
| 63 | + is disable completely. |
| 64 | + """ |
| 65 | + ) |
| 66 | + |
| 67 | + autorun_script = List( |
| 68 | + Unicode(), |
| 69 | + default_value=[], |
| 70 | + config=True, |
| 71 | + help=""" |
| 72 | + List of scripts to search for when attempting to autorun. The first match will |
| 73 | + be run with a single argument of 'init' or 'update' depending on what nbgitpuller |
| 74 | + is doing. |
| 75 | +
|
| 76 | + Only used if autorun_allow is changed from its default of False. |
| 77 | +
|
| 78 | + Enable this only if you understand and accept the risks of AUTORUN.INF. |
| 79 | + """ |
| 80 | + ) |
| 81 | + |
54 | 82 | depth = Integer( |
55 | 83 | config=True, |
56 | 84 | help=""" |
@@ -82,19 +110,6 @@ def __init__(self, git_url, repo_dir, **kwargs): |
82 | 110 | elif not self.branch_exists(self.branch_name): |
83 | 111 | raise ValueError(f"Branch: {self.branch_name} -- not found in repo: {self.git_url}") |
84 | 112 |
|
85 | | - features = NbGitPullerFeatures(parent=kwargs.get("parent")) |
86 | | - if features.autorun_allow is True: |
87 | | - self._autorun = True |
88 | | - elif isinstance(features.autorun_allow, list): |
89 | | - self._autorun = any(( re.match(pattern, git_url) for pattern in features.autorun_allow )) |
90 | | - else: |
91 | | - self._autorun = False |
92 | | - if self._autorun: |
93 | | - if isinstance(features.autorun_script, list): |
94 | | - self._autorun_script = features.autorun_script |
95 | | - else: |
96 | | - self._autorun = False |
97 | | - |
98 | 113 | self.repo_dir = repo_dir |
99 | 114 | newargs = {k: v for k, v in kwargs.items() if v is not None} |
100 | 115 | super(GitPuller, self).__init__(**newargs) |
@@ -162,7 +177,10 @@ def autorun(self, operation="method"): |
162 | 177 | """ |
163 | 178 | Search for and execute the autorun script. |
164 | 179 | """ |
165 | | - if not self._autorun: |
| 180 | + |
| 181 | + if not self.autorun_allow: |
| 182 | + return |
| 183 | + if not any(( re.match(pattern, self.git_url) for pattern in self.autorun_allow )): |
166 | 184 | return |
167 | 185 |
|
168 | 186 | script = next(( s for s in self._autorun_script if os.path.exists(os.path.join(self.repo_dir, s)) ), None) |
|
0 commit comments