Skip to content

Commit

Permalink
[cpackget] Debug log level not working on some commands #131 (#181)
Browse files Browse the repository at this point in the history
fixed:
- initializing verbose option
- fixed crash in sanitizeVersionForSignature() accessing [0] of empty string
  • Loading branch information
thorstendb-ARM authored Jun 14, 2023
1 parent 1dbce2f commit 11f073f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions cmd/commands/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: configureInstallerVerbose,
RunE: func(cmd *cobra.Command, args []string) error {
return cryptography.GenerateChecksum(args[0], checksumCreateCmdFlags.outputDir, checksumCreateCmdFlags.hashAlgorithm)
},
Expand All @@ -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: configureInstallerVerbose,
RunE: func(cmd *cobra.Command, args []string) error {
if checksumVerifyCmdFlags.checksumPath != "" {
return cryptography.VerifyChecksum(args[0], checksumVerifyCmdFlags.checksumPath)
Expand Down
13 changes: 11 additions & 2 deletions cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const defaultPublicIndex = "https://www.keil.com/pack/index.pidx"

var viper *viperType.Viper

// configureInstaller configures cpackget installer for adding or removing pack/pdsc
func configureInstaller(cmd *cobra.Command, args []string) error {
func configureInstallerVerbose(cmd *cobra.Command, args []string) error {
verbosiness := viper.GetBool("verbose")
quiet := viper.GetBool("quiet")
if quiet && verbosiness {
Expand All @@ -61,6 +60,16 @@ func configureInstaller(cmd *cobra.Command, args []string) error {
log.SetLevel(log.DebugLevel)
}

return nil
}

// configureInstaller configures cpackget installer for adding or removing pack/pdsc
func configureInstaller(cmd *cobra.Command, args []string) error {
err := configureInstallerVerbose(cmd, args)
if err != nil {
return err
}

targetPackRoot := viper.GetString("pack-root")
if targetPackRoot == installer.GetDefaultCmsisPackRoot() {
// If using the default pack root path and the public index is not found,
Expand Down
6 changes: 4 additions & 2 deletions cmd/commands/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: configureInstallerVerbose,
RunE: func(cmd *cobra.Command, args []string) error {
if signatureCreateflags.keyPath == "" {
if !signatureCreateflags.certOnly {
Expand Down Expand Up @@ -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: configureInstallerVerbose,
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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/cryptography/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11f073f

Please sign in to comment.