##// END OF EJS Templates
add `ipython trust --reset
MinRK -
Show More
@@ -18,9 +18,9 b' import io'
18 import os
18 import os
19
19
20 from IPython.utils.py3compat import string_types, unicode_type, cast_bytes
20 from IPython.utils.py3compat import string_types, unicode_type, cast_bytes
21 from IPython.utils.traitlets import Instance, Bytes, Enum, Any, Unicode
21 from IPython.utils.traitlets import Instance, Bytes, Enum, Any, Unicode, Bool
22 from IPython.config import LoggingConfigurable, MultipleInstanceError
22 from IPython.config import LoggingConfigurable, MultipleInstanceError
23 from IPython.core.application import BaseIPythonApplication
23 from IPython.core.application import BaseIPythonApplication, base_flags
24
24
25 from .current import read, write
25 from .current import read, write
26
26
@@ -118,7 +118,7 b' class NotebookNotary(LoggingConfigurable):'
118
118
119 def _write_secret_file(self, secret):
119 def _write_secret_file(self, secret):
120 """write my secret to my secret_file"""
120 """write my secret to my secret_file"""
121 self.log.info("Writing output secret to %s", self.secret_file)
121 self.log.info("Writing notebook-signing key to %s", self.secret_file)
122 with io.open(self.secret_file, 'wb') as f:
122 with io.open(self.secret_file, 'wb') as f:
123 f.write(secret)
123 f.write(secret)
124 try:
124 try:
@@ -211,6 +211,18 b' class NotebookNotary(LoggingConfigurable):'
211 return True
211 return True
212
212
213
213
214 trust_flags = {
215 'reset' : (
216 {'TrustNotebookApp' : { 'reset' : True}},
217 """Generate a new key for notebook signature.
218 All previously signed notebooks will become untrusted.
219 """
220 ),
221 }
222 trust_flags.update(base_flags)
223 trust_flags.pop('init')
224
225
214 class TrustNotebookApp(BaseIPythonApplication):
226 class TrustNotebookApp(BaseIPythonApplication):
215
227
216 description="""Sign one or more IPython notebooks with your key,
228 description="""Sign one or more IPython notebooks with your key,
@@ -219,7 +231,15 b' class TrustNotebookApp(BaseIPythonApplication):'
219 Otherwise, you will have to re-execute the notebook to see output.
231 Otherwise, you will have to re-execute the notebook to see output.
220 """
232 """
221
233
222 examples="""ipython trust mynotebook.ipynb and_this_one.ipynb"""
234 examples = """ipython trust mynotebook.ipynb and_this_one.ipynb"""
235
236 flags = trust_flags
237
238 reset = Bool(False, config=True,
239 help="""If True, generate a new key for notebook signature.
240 After reset, all previously signed notebooks will become untrusted.
241 """
242 )
223
243
224 notary = Instance(NotebookNotary)
244 notary = Instance(NotebookNotary)
225 def _notary_default(self):
245 def _notary_default(self):
@@ -239,7 +259,15 b' class TrustNotebookApp(BaseIPythonApplication):'
239 with io.open(notebook_path, 'w', encoding='utf8') as f:
259 with io.open(notebook_path, 'w', encoding='utf8') as f:
240 write(nb, f, 'json')
260 write(nb, f, 'json')
241
261
262 def generate_new_key(self):
263 """Generate a new notebook signature key"""
264 print("Generating new notebook key: %s" % self.notary.secret_file)
265 self.notary._write_secret_file(os.urandom(1024))
266
242 def start(self):
267 def start(self):
268 if self.reset:
269 self.generate_new_key()
270 return
243 if not self.extra_args:
271 if not self.extra_args:
244 self.log.critical("Specify at least one notebook to sign.")
272 self.log.critical("Specify at least one notebook to sign.")
245 self.exit(1)
273 self.exit(1)
General Comments 0
You need to be logged in to leave comments. Login now