Browse Source

add option to sign on import..

If the identity changed, generate a new uuid, and set created_by and
modified appropriately...
main
John-Mark Gurney 2 years ago
parent
commit
cf7a81b22a
2 changed files with 41 additions and 1 deletions
  1. +22
    -0
      ui/fixtures/cmd.import.json
  2. +19
    -1
      ui/medashare/cli.py

+ 22
- 0
ui/fixtures/cmd.import.json View File

@@ -0,0 +1,22 @@
[
{
"title": "gen ident",
"cmd": [ "genident", "name=A Test User" ],
"exit": 0
},
{
"title": "that a sign import can be done",
"cmd": [ "import", "--sign" ],
"stdin": "{\"created_by_ref\": \"2de7a389-410c-4755-8c62-f3254c7e971e\", \"dir\": \"\", \"filename\": \"FreeBSD-14.0-CURRENT-arm64-aarch64-ROCK64-20220331-d53927b0bae-254105.img.xz\", \"hashes\": [\"sha512:3eba2aa09a79fd7adec32ace93c6725e75b91a55192b5bfa827b893fae1c2cdbc040e282138387797f245c1f27da5e8ff7a02f59ff75c73b3d999d1e0a8752ad\"], \"id\": \"d9e8fc1a-9794-5e70-b67b-11d708ec8947\", \"modified\": \"2022-08-02T07:52:50.216428Z\", \"mtime\": \"2022-03-31T10:15:14.000000Z\", \"sig\": \"F3Ch1BQB57RAgFNKNF5btCRZS3jFmafhvcdoWuu6WHo5JzyhuQ7jNvZkv4tzgWqlMfPecLJMMmSAMcwqorykDWi854ZfKUm3F-JOTk8R7qRKdHd23rwVGDEXtVHv-kynkh8WemPsfc2V1HT8JKG9NhwA\", \"size\": 551750948, \"type\": \"file\", \"uuid\": \"89544934-6ed9-46ca-b8d0-77c5209f798d\"}\n"
},
{
"special": "verify store object cnt",
"comment": "and the objects were imported",
"count": 1
},
{
"title": "that the created_by_ref was changed",
"cmd": [ "dump" ],
"stdout_nre": "2de7a389-410c-4755-8c62-f3254c7e971|2022-08-02T07:52:50.216428Z|F3Ch1BQB57RAgFNKNF5btCRZS3jFmafhvcdoWuu6WHo5JzyhuQ7jNvZkv4tzgWqlMfPecLJMMmSAMcwqorykDWi854ZfKUm3F-JOTk8R7qRKdHd23rwVGDEXtVHv-kynkh8WemPsfc2V1HT8JKG9NhwA|89544934-6ed9-46ca-b8d0-77c5209f798d"
}
]

+ 19
- 1
ui/medashare/cli.py View File

@@ -975,8 +975,21 @@ def cmd_import(options):
inp = inp.strip()
jobj, endpos = jd.raw_decode(inp)

if options.sign:
cbr = _makeuuid(jobj['created_by_ref'])
if cbr != persona.uuid:
# new owner
jobj['created_by_ref'] = persona.uuid

# drop old parts
jobj.pop('uuid', None)
jobj.pop('modified', None)

obj = MDBase.create_obj(jobj)

if options.sign:
obj = persona.sign(obj)

objstr.loadobj(obj)

inp = inp[endpos:]
@@ -1042,6 +1055,8 @@ def main():
parser_dump.set_defaults(func=cmd_dump)

parser_import = subparsers.add_parser('import', help='import objects encoded as json')
parser_import.add_argument('--sign', action='store_true',
help='import as new identity, and sign objects (if created_by_ref is different, new uuid is created)')
parser_import.set_defaults(func=cmd_import)

parser_drop = subparsers.add_parser('drop', help='drop the object specified by UUID')
@@ -1590,8 +1605,11 @@ class _TestCases(unittest.TestCase):

# with the correct output
self.maxDiff = None
outnre = cmd.get('stdout_nre')
outre = cmd.get('stdout_re')
if outre:
if outnre:
self.assertNotRegex(stdout.getvalue(), outnre)
elif outre:
self.assertRegex(stdout.getvalue(), outre)
else:
self.assertEqual(stdout.getvalue(), cmd.get('stdout', ''))


Loading…
Cancel
Save