Explorar o código

archiver: Move key management commands to new key subcommand.

Martin Hostettler %!s(int64=8) %!d(string=hai) anos
pai
achega
29b5136da7
Modificáronse 3 ficheiros con 20 adicións e 12 borrados
  1. 10 2
      borg/archiver.py
  2. 1 1
      borg/keymanager.py
  3. 9 9
      borg/testsuite/archiver.py

+ 10 - 2
borg/archiver.py

@@ -1110,7 +1110,15 @@ class Archiver:
         subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
         subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
                                type=location_validator(archive=False))
                                type=location_validator(archive=False))
 
 
-        subparser = subparsers.add_parser('key-export', parents=[common_parser],
+        subparser = subparsers.add_parser('key',
+                                          description="Manage a keyfile or repokey of a repository",
+                                          epilog="",
+                                          formatter_class=argparse.RawDescriptionHelpFormatter,
+                                          help='manage repository key')
+
+        key_parsers = subparser.add_subparsers(title='required arguments', metavar='<command>')
+
+        subparser = key_parsers.add_parser('export', parents=[common_parser],
                                           description=self.do_key_export.__doc__,
                                           description=self.do_key_export.__doc__,
                                           epilog="",
                                           epilog="",
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -1124,7 +1132,7 @@ class Archiver:
                                default=False,
                                default=False,
                                help='Create an export suitable for printing and later type-in')
                                help='Create an export suitable for printing and later type-in')
 
 
-        subparser = subparsers.add_parser('key-import', parents=[common_parser],
+        subparser = key_parsers.add_parser('import', parents=[common_parser],
                                           description=self.do_key_import.__doc__,
                                           description=self.do_key_import.__doc__,
                                           epilog="",
                                           epilog="",
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,

+ 1 - 1
borg/keymanager.py

@@ -98,7 +98,7 @@ class KeyManager:
                 i += 1
                 i += 1
             return ret
             return ret
 
 
-        export = 'To restore key use borg key-import --paper /path/to/repo\n\n'
+        export = 'To restore key use borg key import --paper /path/to/repo\n\n'
 
 
         binary = a2b_base64(self.keyblob)
         binary = a2b_base64(self.keyblob)
         export += 'BORG PAPER KEY v1\n'
         export += 'BORG PAPER KEY v1\n'

+ 9 - 9
borg/testsuite/archiver.py

@@ -1200,7 +1200,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         export_file = self.output_path + '/exported'
         export_file = self.output_path + '/exported'
         self.cmd('init', self.repository_location, '--encryption', 'keyfile')
         self.cmd('init', self.repository_location, '--encryption', 'keyfile')
         repo_id = self._extract_repository_id(self.repository_path)
         repo_id = self._extract_repository_id(self.repository_path)
-        self.cmd('key-export', self.repository_location, export_file)
+        self.cmd('key', 'export', self.repository_location, export_file)
 
 
         with open(export_file, 'r') as fd:
         with open(export_file, 'r') as fd:
             export_contents = fd.read()
             export_contents = fd.read()
@@ -1216,7 +1216,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
 
 
         os.unlink(key_file)
         os.unlink(key_file)
 
 
-        self.cmd('key-import', self.repository_location, export_file)
+        self.cmd('key', 'import', self.repository_location, export_file)
 
 
         with open(key_file, 'r') as fd:
         with open(key_file, 'r') as fd:
             key_contents2 = fd.read()
             key_contents2 = fd.read()
@@ -1227,7 +1227,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         export_file = self.output_path + '/exported'
         export_file = self.output_path + '/exported'
         self.cmd('init', self.repository_location, '--encryption', 'repokey')
         self.cmd('init', self.repository_location, '--encryption', 'repokey')
         repo_id = self._extract_repository_id(self.repository_path)
         repo_id = self._extract_repository_id(self.repository_path)
-        self.cmd('key-export', self.repository_location, export_file)
+        self.cmd('key', 'export', self.repository_location, export_file)
 
 
         with open(export_file, 'r') as fd:
         with open(export_file, 'r') as fd:
             export_contents = fd.read()
             export_contents = fd.read()
@@ -1246,7 +1246,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         with Repository(self.repository_path) as repository:
         with Repository(self.repository_path) as repository:
             repository.save_key(b'')
             repository.save_key(b'')
 
 
-        self.cmd('key-import', self.repository_location, export_file)
+        self.cmd('key', 'import', self.repository_location, export_file)
 
 
         with Repository(self.repository_path) as repository:
         with Repository(self.repository_path) as repository:
             repo_key2 = RepoKey(repository)
             repo_key2 = RepoKey(repository)
@@ -1258,17 +1258,17 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         export_file = self.output_path + '/exported'
         export_file = self.output_path + '/exported'
         self.cmd('init', self.repository_location, '--encryption', 'keyfile')
         self.cmd('init', self.repository_location, '--encryption', 'keyfile')
 
 
-        self.cmd('key-import', self.repository_location, export_file, exit_code=EXIT_ERROR)
+        self.cmd('key', 'import', self.repository_location, export_file, exit_code=EXIT_ERROR)
 
 
         with open(export_file, 'w') as fd:
         with open(export_file, 'w') as fd:
             fd.write('something not a key\n')
             fd.write('something not a key\n')
 
 
-        self.assert_raises(NotABorgKeyFile, lambda: self.cmd('key-import', self.repository_location, export_file))
+        self.assert_raises(NotABorgKeyFile, lambda: self.cmd('key', 'import', self.repository_location, export_file))
 
 
         with open(export_file, 'w') as fd:
         with open(export_file, 'w') as fd:
             fd.write('BORG_KEY a0a0a0\n')
             fd.write('BORG_KEY a0a0a0\n')
 
 
-        self.assert_raises(RepoIdMismatch, lambda: self.cmd('key-import', self.repository_location, export_file))
+        self.assert_raises(RepoIdMismatch, lambda: self.cmd('key', 'import', self.repository_location, export_file))
 
 
     def test_key_export_paperkey(self):
     def test_key_export_paperkey(self):
         repo_id = 'e294423506da4e1ea76e8dcdf1a3919624ae3ae496fddf905610c351d3f09239'
         repo_id = 'e294423506da4e1ea76e8dcdf1a3919624ae3ae496fddf905610c351d3f09239'
@@ -1283,12 +1283,12 @@ class ArchiverTestCase(ArchiverTestCaseBase):
             fd.write(KeyfileKey.FILE_ID + ' ' + repo_id + '\n')
             fd.write(KeyfileKey.FILE_ID + ' ' + repo_id + '\n')
             fd.write(b2a_base64(b'abcdefghijklmnopqrstu').decode())
             fd.write(b2a_base64(b'abcdefghijklmnopqrstu').decode())
 
 
-        self.cmd('key-export', '--paper', self.repository_location, export_file)
+        self.cmd('key', 'export', '--paper', self.repository_location, export_file)
 
 
         with open(export_file, 'r') as fd:
         with open(export_file, 'r') as fd:
             export_contents = fd.read()
             export_contents = fd.read()
 
 
-        assert export_contents == """To restore key use borg key-import --paper /path/to/repo
+        assert export_contents == """To restore key use borg key import --paper /path/to/repo
 
 
 BORG PAPER KEY v1
 BORG PAPER KEY v1
 id: 2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02
 id: 2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02