From c2f80b7d9f12eefd40fc430f838c7c56237bb8b9 Mon Sep 17 00:00:00 2001 From: Thorsten de Buhr Date: Tue, 13 Jun 2023 14:16:53 +0200 Subject: [PATCH] [cpackget] Debug log level not working on some commands #131 fixed: - Init was missing in COBRA structs: PersistentPreRunE: configureInstaller - function crashes on empty string: sanitizeVersionForSignature() --- cmd/commands/checksum.go | 6 ++++-- cmd/commands/init.go | 3 ++- cmd/commands/signature.go | 6 ++++-- cmd/cryptography/utils.go | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/commands/checksum.go b/cmd/commands/checksum.go index fab1c07..13056ea 100755 --- a/cmd/commands/checksum.go +++ b/cmd/commands/checksum.go @@ -55,7 +55,8 @@ The default Cryptographic Hash Function used is "` + cryptography.Hashes[0] + `" might be supported. The used function will be prefixed to the ".checksum" extension. By default the checksum file will be created in the same directory as the provided pack.`, - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(1), + PersistentPreRunE: configureInstaller, RunE: func(cmd *cobra.Command, args []string) error { return cryptography.GenerateChecksum(args[0], checksumCreateCmdFlags.outputDir, checksumCreateCmdFlags.hashAlgorithm) }, @@ -73,7 +74,8 @@ with "checksum-create"), present in the same directory: The used hash function is inferred from the checksum filename, and if any of the digests computed doesn't match the one provided in the checksum file an error will be thrown. If the .checksum file is in another directory, specify it with the -p/--path flag`, - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(1), + PersistentPreRunE: configureInstaller, RunE: func(cmd *cobra.Command, args []string) error { if checksumVerifyCmdFlags.checksumPath != "" { return cryptography.VerifyChecksum(args[0], checksumVerifyCmdFlags.checksumPath) diff --git a/cmd/commands/init.go b/cmd/commands/init.go index 6882b71..b3f000d 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -24,7 +24,8 @@ or via the CMSIS_PACK_ROOT environment variable with the following contents: - .Web/ - .Web/index.pidx (downloaded from ) The index-url is mandatory. Ex "cpackget init --pack-root path/to/mypackroot https://www.keil.com/pack/index.pidx"`, - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(1), + PersistentPreRunE: configureInstaller, RunE: func(cmd *cobra.Command, args []string) error { packRoot := viper.GetString("pack-root") indexPath := args[0] diff --git a/cmd/commands/signature.go b/cmd/commands/signature.go index 8d40e49..e719fe1 100644 --- a/cmd/commands/signature.go +++ b/cmd/commands/signature.go @@ -96,7 +96,8 @@ These can be viewed with any text/hex editor or dedicated zip tools like "zipinf The referenced pack must be in its original/compressed form (.pack), and be present locally: $ cpackget signature-create Vendor.Pack.1.2.3.pack -k private.key -c certificate.pem`, - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(1), + PersistentPreRunE: configureInstaller, RunE: func(cmd *cobra.Command, args []string) error { if signatureCreateflags.keyPath == "" { if !signatureCreateflags.certOnly { @@ -152,7 +153,8 @@ the publisher's public PGP key. The referenced pack must be in its original/compressed form (.pack), and be present locally: $ cpackget signature-verify Vendor.Pack.1.2.3.pack.signed`, - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(1), + PersistentPreRunE: configureInstaller, RunE: func(cmd *cobra.Command, args []string) error { if signatureVerifyflags.export && (signatureVerifyflags.skipCertValidation || signatureVerifyflags.skipInfo) { log.Error("-e/--export does not need any other flags") diff --git a/cmd/cryptography/utils.go b/cmd/cryptography/utils.go index a2ed92a..2099317 100644 --- a/cmd/cryptography/utils.go +++ b/cmd/cryptography/utils.go @@ -200,7 +200,7 @@ func isPrivateKeyFromCertificate(cert *x509.Certificate, keyDER []byte, keyType // from source vs an automated release. func sanitizeVersionForSignature(version string) string { v := sigVersionPrefix - if string(version[0]) != "v" { + if version != "" && string(version[0]) != "v" { return v + "v" + version } return v + version