feature(keyringctl): unify import subcommand for condensed api

Both commands are basically doing the same with the same params except
the target directory differs. Lets condense this behavior by using a
single subcommand with a boolean options.
This commit is contained in:
Levente Polyak 2021-10-20 20:02:08 +02:00
parent 2f9ef0ef1d
commit 8bc0ae1da0
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
2 changed files with 14 additions and 35 deletions

View File

@ -24,23 +24,23 @@ of the distribution.
Import of a new main key is done using Import of a new main key is done using
```bash ```bash
./keyringctl import-main --name <username> <file> ./keyringctl import --main --name <username> <file>
``` ```
Updates to existing main keys is done using Updates to existing main keys is done using
```bash ```bash
./keyringctl import-main <file_or_directory> ./keyringctl import --main <file_or_directory>
``` ```
Import of a new packager key is done using Import of a new packager key is done using
```bash ```bash
./keyringctl import-packager --name <username> <file> ./keyringctl import --name <username> <file>
``` ```
Updates to existing packager keys is done using Updates to existing packager keys is done using
```bash ```bash
./keyringctl import-packager <file_or_directory> ./keyringctl import <file_or_directory>
``` ```

View File

@ -1129,7 +1129,7 @@ if __name__ == "__main__":
convert_parser = subcommands.add_parser( convert_parser = subcommands.add_parser(
"convert", "convert",
help="import one or multiple PGP public keys and convert them to a decomposed directory structure", help="convert one or multiple PGP public keys to a decomposed directory structure",
) )
convert_parser.add_argument("source", type=absolute_path, help="File or directory to convert") convert_parser.add_argument("source", type=absolute_path, help="File or directory to convert")
convert_parser.add_argument("--target", type=absolute_path, help="target directory") convert_parser.add_argument("--target", type=absolute_path, help="target directory")
@ -1140,27 +1140,18 @@ if __name__ == "__main__":
help="override the username to use (only useful when using a single file as source)", help="override the username to use (only useful when using a single file as source)",
) )
import_main_parser = subcommands.add_parser( import_parser = subcommands.add_parser(
"import-main", help="import one or several PGP keys to the main signing keys" "import",
help="import one or several PGP keys to the keyring directory structure",
) )
import_main_parser.add_argument("source", type=absolute_path, help="File or directory") import_parser.add_argument("source", type=absolute_path, help="File or directory")
import_main_parser.add_argument( import_parser.add_argument(
"--name",
type=Username,
default=None,
help="override the username to use (only useful when using a single file as source)",
)
import_packager_parser = subcommands.add_parser(
"import-packager", help="import one or several PGP keys to the packager keys"
)
import_packager_parser.add_argument("source", type=absolute_path, help="File or directory")
import_packager_parser.add_argument(
"--name", "--name",
type=Username, type=Username,
default=None, default=None,
help="override the username to use (only useful when using a single file as source)", help="override the username to use (only useful when using a single file as source)",
) )
import_parser.add_argument("--main", action="store_true", help="Import a main signing key into the keyring")
export_keyring_parser = subcommands.add_parser( export_keyring_parser = subcommands.add_parser(
"export-keyring", "export-keyring",
@ -1209,25 +1200,13 @@ if __name__ == "__main__":
with cwd(working_dir): with cwd(working_dir):
if "convert" == args.subcommand: if "convert" == args.subcommand:
print(convert(working_dir, args.source, target_dir=Path(mkdtemp(prefix="arch-keyringctl-")).absolute())) print(convert(working_dir, args.source, target_dir=Path(mkdtemp(prefix="arch-keyringctl-")).absolute()))
elif "import-main" == args.subcommand: elif "import" == args.subcommand:
target_dir = "main" if args.main else "packager"
print( print(
convert( convert(
working_dir=working_dir, working_dir=working_dir,
source=args.source, source=args.source,
target_dir=keyring_root / "main", target_dir=keyring_root / target_dir,
name_override=args.name,
fingerprint_filter=get_fingerprints(
working_dir=working_dir,
decomposed_paths=[keyring_root / "main", keyring_root / "packager"],
),
)
)
elif "import-packager" == args.subcommand:
print(
convert(
working_dir=working_dir,
source=args.source,
target_dir=keyring_root / "packager",
name_override=args.name, name_override=args.name,
fingerprint_filter=get_fingerprints( fingerprint_filter=get_fingerprints(
working_dir=working_dir, working_dir=working_dir,