diff --git a/.dagger/publishimage.go b/.dagger/publishimage.go index 871a8a2b6..a56f22a1a 100644 --- a/.dagger/publishimage.go +++ b/.dagger/publishimage.go @@ -43,10 +43,10 @@ func (m *HarborCli) PublishImageAndSign( // Generate SBOM (SPDX JSON) for the published image sbom := m.GenerateSBOM( ctx, - addr, - registryUsername, + addr, + registryUsername, registryPassword, - ); + ) // Attest SBOM to the image using Cosign in-toto attestation if _, err := m.AttestSBOM( diff --git a/cmd/harbor/root/artifact/delete.go b/cmd/harbor/root/artifact/delete.go index 215233528..d128be6cd 100644 --- a/cmd/harbor/root/artifact/delete.go +++ b/cmd/harbor/root/artifact/delete.go @@ -17,9 +17,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/artifact/view.go b/cmd/harbor/root/artifact/view.go index 0b5a4065d..061057797 100644 --- a/cmd/harbor/root/artifact/view.go +++ b/cmd/harbor/root/artifact/view.go @@ -16,10 +16,10 @@ package artifact import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/artifact" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/artifact/view" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/cmd.go b/cmd/harbor/root/cmd.go index 039e39ea6..78d2e19c3 100644 --- a/cmd/harbor/root/cmd.go +++ b/cmd/harbor/root/cmd.go @@ -16,7 +16,6 @@ package root import ( "fmt" "io" - "time" "github.com/goharbor/harbor-cli/cmd/harbor/root/artifact" "github.com/goharbor/harbor-cli/cmd/harbor/root/configurations" @@ -38,8 +37,8 @@ import ( "github.com/goharbor/harbor-cli/cmd/harbor/root/user" "github.com/goharbor/harbor-cli/cmd/harbor/root/vulnerability" "github.com/goharbor/harbor-cli/cmd/harbor/root/webhook" + "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -69,17 +68,11 @@ harbor help // Initialize configuration utils.InitConfig(cfgFile, userSpecifiedConfig) - // Conditionally set the timestamp format only in verbose mode - formatter := &logrus.TextFormatter{} - if verbose { - formatter.FullTimestamp = true - formatter.TimestampFormat = time.RFC3339 - logrus.SetLevel(logrus.DebugLevel) + log.SetLevel(log.LevelDebug) } else { - logrus.SetOutput(io.Discard) + log.SetOutput(io.Discard) } - logrus.SetFormatter(formatter) return nil }, diff --git a/cmd/harbor/root/context/delete.go b/cmd/harbor/root/context/delete.go index a04a9b75a..7ada24f3c 100644 --- a/cmd/harbor/root/context/delete.go +++ b/cmd/harbor/root/context/delete.go @@ -18,8 +18,8 @@ import ( "reflect" "strings" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -81,9 +81,9 @@ If you specify --name, that credential (rather than the "current" one) will be u } if found { - logrus.Infof("Removed credential '%s' and cleared CurrentCredentialName", currentName) + log.Infof("Removed credential '%s' and cleared CurrentCredentialName", currentName) } else { - logrus.Infof("No credential named '%s' found; cleared CurrentCredentialName anyway", currentName) + log.Infof("No credential named '%s' found; cleared CurrentCredentialName anyway", currentName) } return nil @@ -111,7 +111,7 @@ If you specify --name, that credential (rather than the "current" one) will be u // 5. Confirm to the user (no error here) canonicalPath := strings.Join(actualSegments, ".") - logrus.Infof("Successfully cleared %s", canonicalPath) + log.Infof("Successfully cleared %s", canonicalPath) return nil }, diff --git a/cmd/harbor/root/context/update.go b/cmd/harbor/root/context/update.go index 2b479b545..eea5199ef 100644 --- a/cmd/harbor/root/context/update.go +++ b/cmd/harbor/root/context/update.go @@ -19,8 +19,8 @@ import ( "strconv" "strings" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -67,9 +67,9 @@ If you specify --name, that credential (rather than the "current" one) will be u return fmt.Errorf("failed to save updated config: %w", err) } - // 5. Confirm to the user (logrus.Info is fine here; no error) + // 5. Confirm to the user (log.Info is fine here; no error) canonicalPath := strings.Join(actualSegments, ".") - logrus.Infof("Successfully updated %s to '%s'", canonicalPath, newValue) + log.Infof("Successfully updated %s to '%s'", canonicalPath, newValue) return nil }, @@ -251,7 +251,7 @@ func encryptPassword(plaintext string) (string, error) { // Make sure a key exists if err := utils.GenerateEncryptionKey(); err != nil { // It's okay if the key already exists; that might not be a fatal error for you - logrus.Debugf("Encryption key might already exist: %v", err) + log.Debugf("Encryption key might already exist: %v", err) } key, err := utils.GetEncryptionKey() diff --git a/cmd/harbor/root/info.go b/cmd/harbor/root/info.go index 48df0c987..9c10fed45 100644 --- a/cmd/harbor/root/info.go +++ b/cmd/harbor/root/info.go @@ -18,9 +18,9 @@ import ( "github.com/goharbor/harbor-cli/cmd/harbor/internal/version" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/info/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/labels/list.go b/cmd/harbor/root/labels/list.go index a596ac95e..90710e4b3 100644 --- a/cmd/harbor/root/labels/list.go +++ b/cmd/harbor/root/labels/list.go @@ -17,9 +17,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/label/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/login.go b/cmd/harbor/root/login.go index 80a5c9803..d736ff40b 100644 --- a/cmd/harbor/root/login.go +++ b/cmd/harbor/root/login.go @@ -21,9 +21,9 @@ import ( "github.com/goharbor/go-client/pkg/harbor" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/user" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/login" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.org/x/term" ) diff --git a/cmd/harbor/root/logs.go b/cmd/harbor/root/logs.go index 580b52ec0..e52b4b1f2 100644 --- a/cmd/harbor/root/logs.go +++ b/cmd/harbor/root/logs.go @@ -21,9 +21,9 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" list "github.com/goharbor/harbor-cli/pkg/views/logs" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/project/create.go b/cmd/harbor/root/project/create.go index b6de76a78..f897350be 100644 --- a/cmd/harbor/root/project/create.go +++ b/cmd/harbor/root/project/create.go @@ -17,9 +17,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/project/create" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/project/delete.go b/cmd/harbor/root/project/delete.go index 4f787fc58..d1138bb73 100644 --- a/cmd/harbor/root/project/delete.go +++ b/cmd/harbor/root/project/delete.go @@ -19,9 +19,9 @@ import ( "sync" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/project/list.go b/cmd/harbor/root/project/list.go index b785b1639..ae8e3db96 100644 --- a/cmd/harbor/root/project/list.go +++ b/cmd/harbor/root/project/list.go @@ -19,9 +19,9 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/project" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" list "github.com/goharbor/harbor-cli/pkg/views/project/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/project/logs.go b/cmd/harbor/root/project/logs.go index 573de085d..8a50d3ef6 100644 --- a/cmd/harbor/root/project/logs.go +++ b/cmd/harbor/root/project/logs.go @@ -18,10 +18,10 @@ import ( proj "github.com/goharbor/go-client/pkg/sdk/v2.0/client/project" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" auditLog "github.com/goharbor/harbor-cli/pkg/views/project/logs" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" diff --git a/cmd/harbor/root/project/member/create.go b/cmd/harbor/root/project/member/create.go index 5fba323fe..7a7247100 100644 --- a/cmd/harbor/root/project/member/create.go +++ b/cmd/harbor/root/project/member/create.go @@ -18,7 +18,7 @@ import ( "fmt" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" - "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/api" "github.com/goharbor/harbor-cli/pkg/prompt" @@ -89,7 +89,7 @@ func CreateMemberCommand() *cobra.Command { } if err != nil { - logrus.Errorf("failed to create user: %v", err) + log.Errorf("failed to create user: %v", err) } fmt.Printf("successfully added user %s to project %s\n", createView.MemberUser.Username, opts.ProjectName) diff --git a/cmd/harbor/root/project/member/delete.go b/cmd/harbor/root/project/member/delete.go index 0967ed589..96d59aab8 100644 --- a/cmd/harbor/root/project/member/delete.go +++ b/cmd/harbor/root/project/member/delete.go @@ -17,9 +17,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/project/robot/create.go b/cmd/harbor/root/project/robot/create.go index 86536e781..6fd597fca 100644 --- a/cmd/harbor/root/project/robot/create.go +++ b/cmd/harbor/root/project/robot/create.go @@ -22,10 +22,10 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" config "github.com/goharbor/harbor-cli/pkg/config/robot" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/robot/create" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -102,7 +102,7 @@ Examples: if loadErr != nil { return fmt.Errorf("failed to load robot config from file: %v", loadErr) } - logrus.Info("Successfully loaded robot configuration") + log.Info("Successfully loaded robot configuration") opts = *loadedOpts if opts.ProjectName == "" { opts.ProjectName = opts.Permissions[0].Namespace @@ -196,7 +196,7 @@ Examples: return fmt.Errorf("failed to create robot: %v", utils.ParseHarborErrorMsg(err)) } - logrus.Infof("Successfully created robot account '%s' (ID: %d)", + log.Infof("Successfully created robot account '%s' (ID: %d)", response.Payload.Name, response.Payload.ID) FormatFlag := viper.GetString("output-format") @@ -209,14 +209,14 @@ Examples: name, secret := response.Payload.Name, response.Payload.Secret if exportToFile { - logrus.Info("Exporting robot credentials to file") + log.Info("Exporting robot credentials to file") exportSecretToFile(name, secret, response.Payload.CreationTime.String(), response.Payload.ExpiresAt) return nil } else { create.CreateRobotSecretView(name, secret) err = clipboard.WriteAll(response.Payload.Secret) if err != nil { - logrus.Errorf("failed to write to clipboard") + log.Errorf("failed to write to clipboard") return nil } fmt.Println("secret copied to clipboard.") @@ -246,10 +246,10 @@ func exportSecretToFile(name, secret, creationTime string, expiresAt int64) { filename := fmt.Sprintf("%s-secret.json", name) jsonData, err := json.MarshalIndent(secretJson, "", " ") if err != nil { - logrus.Errorf("Failed to marshal secret to JSON: %v", err) + log.Errorf("Failed to marshal secret to JSON: %v", err) } else { if err := os.WriteFile(filename, jsonData, 0600); err != nil { - logrus.Errorf("Failed to write secret to file: %v", err) + log.Errorf("Failed to write secret to file: %v", err) } else { fmt.Printf("Secret saved to %s\n", filename) } diff --git a/cmd/harbor/root/project/robot/delete.go b/cmd/harbor/root/project/robot/delete.go index 1473d7b3d..678f60637 100644 --- a/cmd/harbor/root/project/robot/delete.go +++ b/cmd/harbor/root/project/robot/delete.go @@ -18,9 +18,9 @@ import ( "strconv" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/project/robot/list.go b/cmd/harbor/root/project/robot/list.go index 1c76012be..54bec20db 100644 --- a/cmd/harbor/root/project/robot/list.go +++ b/cmd/harbor/root/project/robot/list.go @@ -19,10 +19,10 @@ import ( "github.com/goharbor/harbor-cli/pkg/api" "github.com/goharbor/harbor-cli/pkg/constants" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/robot/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/project/robot/refresh.go b/cmd/harbor/root/project/robot/refresh.go index c2ce4c07c..198fc83bb 100644 --- a/cmd/harbor/root/project/robot/refresh.go +++ b/cmd/harbor/root/project/robot/refresh.go @@ -19,10 +19,10 @@ import ( "github.com/atotto/clipboard" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/robot/create" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/project/search.go b/cmd/harbor/root/project/search.go index 1265e2743..81510ccca 100644 --- a/cmd/harbor/root/project/search.go +++ b/cmd/harbor/root/project/search.go @@ -17,9 +17,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/project/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/project/view.go b/cmd/harbor/root/project/view.go index df2f6bdb4..929aaf74a 100644 --- a/cmd/harbor/root/project/view.go +++ b/cmd/harbor/root/project/view.go @@ -18,10 +18,10 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/project" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/project/view" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/quota/update.go b/cmd/harbor/root/quota/update.go index a3ef87cee..a7ddba1ae 100644 --- a/cmd/harbor/root/quota/update.go +++ b/cmd/harbor/root/quota/update.go @@ -19,10 +19,10 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/quota/update" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/registry/list.go b/cmd/harbor/root/registry/list.go index ab3925ef6..5b18fc68b 100644 --- a/cmd/harbor/root/registry/list.go +++ b/cmd/harbor/root/registry/list.go @@ -17,9 +17,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/registry/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/replication/executions/list.go b/cmd/harbor/root/replication/executions/list.go index 979df020d..9eeef0cef 100644 --- a/cmd/harbor/root/replication/executions/list.go +++ b/cmd/harbor/root/replication/executions/list.go @@ -18,10 +18,10 @@ import ( "strconv" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/replication/execution/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/replication/policies/create.go b/cmd/harbor/root/replication/policies/create.go index b72dce17e..a1f4443fb 100644 --- a/cmd/harbor/root/replication/policies/create.go +++ b/cmd/harbor/root/replication/policies/create.go @@ -22,10 +22,10 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" config "github.com/goharbor/harbor-cli/pkg/config/replication" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/replication/policies/create" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/replication/policies/list.go b/cmd/harbor/root/replication/policies/list.go index 1f7c1fd0a..251c7cd89 100644 --- a/cmd/harbor/root/replication/policies/list.go +++ b/cmd/harbor/root/replication/policies/list.go @@ -17,9 +17,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/replication/policies/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/replication/policies/update.go b/cmd/harbor/root/replication/policies/update.go index c944995ed..8843bc43e 100644 --- a/cmd/harbor/root/replication/policies/update.go +++ b/cmd/harbor/root/replication/policies/update.go @@ -19,9 +19,9 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/views/replication/policies/create" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/replication/start.go b/cmd/harbor/root/replication/start.go index f2eefc959..ebbf9368e 100644 --- a/cmd/harbor/root/replication/start.go +++ b/cmd/harbor/root/replication/start.go @@ -18,9 +18,9 @@ import ( "strconv" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/replication/stop.go b/cmd/harbor/root/replication/stop.go index 64a959782..e6b66f585 100644 --- a/cmd/harbor/root/replication/stop.go +++ b/cmd/harbor/root/replication/stop.go @@ -18,9 +18,9 @@ import ( "strconv" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/repository/list.go b/cmd/harbor/root/repository/list.go index beb2b8a22..a93edcaa6 100644 --- a/cmd/harbor/root/repository/list.go +++ b/cmd/harbor/root/repository/list.go @@ -18,10 +18,10 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/repository" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/repository/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/robot/create.go b/cmd/harbor/root/robot/create.go index 72bc2e743..dbdcbc430 100644 --- a/cmd/harbor/root/robot/create.go +++ b/cmd/harbor/root/robot/create.go @@ -23,10 +23,10 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" config "github.com/goharbor/harbor-cli/pkg/config/robot" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/robot/create" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -129,7 +129,7 @@ func loadFromConfigFile(opts *create.CreateView, configFile string, permissions return fmt.Errorf("failed to load robot config from file: %v", err) } - logrus.Info("Successfully loaded robot configuration") + log.Info("Successfully loaded robot configuration") *opts = *loadedOpts if opts.Level != "system" { @@ -158,7 +158,7 @@ func loadFromConfigFile(opts *create.CreateView, configFile string, permissions } } - logrus.Infof("Loaded system robot with %d system permissions and %d project-specific permissions", + log.Infof("Loaded system robot with %d system permissions and %d project-specific permissions", len(*permissions), len(projectPermissionsMap)) return nil @@ -326,7 +326,7 @@ func createRobotAndHandleResponse(opts *create.CreateView, exportToFile bool) er } } - logrus.Infof("Successfully created robot account '%s' (ID: %d)", + log.Infof("Successfully created robot account '%s' (ID: %d)", response.Payload.Name, response.Payload.ID) // Handle output format @@ -340,14 +340,14 @@ func createRobotAndHandleResponse(opts *create.CreateView, exportToFile bool) er name, secret := response.Payload.Name, response.Payload.Secret if exportToFile { - logrus.Info("Exporting robot credentials to file") + log.Info("Exporting robot credentials to file") exportSecretToFile(name, secret, response.Payload.CreationTime.String(), response.Payload.ExpiresAt) return nil } create.CreateRobotSecretView(name, secret) if err := clipboard.WriteAll(secret); err != nil { - logrus.Errorf("failed to write to clipboard") + log.Errorf("failed to write to clipboard") } else { fmt.Println("secret copied to clipboard.") } @@ -377,12 +377,12 @@ func exportSecretToFile(name, secret, creationTime string, expiresAt int64) { filename := fmt.Sprintf("%s-secret.json", name) jsonData, err := json.MarshalIndent(secretJson, "", " ") if err != nil { - logrus.Errorf("Failed to marshal secret to JSON: %v", err) + log.Errorf("Failed to marshal secret to JSON: %v", err) return } if err := os.WriteFile(filename, jsonData, 0600); err != nil { - logrus.Errorf("Failed to write secret to file: %v", err) + log.Errorf("Failed to write secret to file: %v", err) return } diff --git a/cmd/harbor/root/robot/refresh.go b/cmd/harbor/root/robot/refresh.go index 13fb6671e..6f91c6454 100644 --- a/cmd/harbor/root/robot/refresh.go +++ b/cmd/harbor/root/robot/refresh.go @@ -19,10 +19,10 @@ import ( "github.com/atotto/clipboard" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/robot/create" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/robot/update.go b/cmd/harbor/root/robot/update.go index f9d093a24..be4bab74c 100644 --- a/cmd/harbor/root/robot/update.go +++ b/cmd/harbor/root/robot/update.go @@ -21,10 +21,10 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" config "github.com/goharbor/harbor-cli/pkg/config/robot" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/robot/update" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -144,7 +144,7 @@ Examples: } } - logrus.Infof("Loaded robot with %d system permissions and %d project-specific permissions", + log.Infof("Loaded robot with %d system permissions and %d project-specific permissions", len(permissions), len(projectPermissionsMap)) // Handle configuration from file or interactive input @@ -187,7 +187,7 @@ func loadFromConfigFileForUpdate(opts *update.UpdateView, configFile string, per return fmt.Errorf("failed to load robot config from file: %v", err) } - logrus.Info("Successfully loaded robot configuration") + log.Info("Successfully loaded robot configuration") // Only update fields that should be updated from the config file // IMPORTANT: Do not update name or level as the Harbor API doesn't allow this @@ -230,7 +230,7 @@ func loadFromConfigFileForUpdate(opts *update.UpdateView, configFile string, per } } - logrus.Infof("Loaded robot update with %d system permissions and %d project-specific permissions", + log.Infof("Loaded robot update with %d system permissions and %d project-specific permissions", len(*permissions), len(projectPermissionsMap)) return nil @@ -264,7 +264,7 @@ func handleInteractiveInputForUpdate(opts *update.UpdateView, all bool, permissi } if !updatePerms { - logrus.Info("Keeping existing permissions") + log.Info("Keeping existing permissions") return nil } @@ -296,7 +296,7 @@ func getSystemPermissionsForUpdate(all bool, permissions *[]models.Permission) e } if !updateSystem { - logrus.Info("Keeping existing system permissions") + log.Info("Keeping existing system permissions") return nil } @@ -328,10 +328,10 @@ func getProjectPermissionsForUpdate(opts *update.UpdateView, projectPermissionsM switch permissionMode { case "keep": - logrus.Info("Keeping existing project permissions") + log.Info("Keeping existing project permissions") return nil case "clear": - logrus.Info("Clearing all project permissions") + log.Info("Clearing all project permissions") // Clear the map to remove all project permissions for k := range projectPermissionsMap { delete(projectPermissionsMap, k) @@ -538,7 +538,7 @@ func validateProjectPermissions(permissions []models.Permission) ([]models.Permi // Warn about invalid permissions if len(invalidPerms) > 0 { - logrus.Warnf("Removed %d invalid project permissions: %v", len(invalidPerms), invalidPerms) + log.Warnf("Removed %d invalid project permissions: %v", len(invalidPerms), invalidPerms) } return validPerms, nil @@ -583,7 +583,7 @@ func updateRobotAndHandleResponse(opts *update.UpdateView) error { return fmt.Errorf("failed to update robot: %v", utils.ParseHarborErrorMsg(err)) } - logrus.Infof("Successfully updated robot account '%s' (ID: %d)", opts.Name, opts.ID) + log.Infof("Successfully updated robot account '%s' (ID: %d)", opts.Name, opts.ID) // Handle output format if formatFlag := viper.GetString("output-format"); formatFlag != "" { diff --git a/cmd/harbor/root/scan_all/metrics.go b/cmd/harbor/root/scan_all/metrics.go index 6ee571fab..5b8b6d601 100644 --- a/cmd/harbor/root/scan_all/metrics.go +++ b/cmd/harbor/root/scan_all/metrics.go @@ -15,9 +15,9 @@ package scan_all import ( "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" view "github.com/goharbor/harbor-cli/pkg/views/scan-all/metrics" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -54,10 +54,10 @@ Examples: harbor-cli scan-all metrics --output-format json`, Args: cobra.MaximumNArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - logrus.Info("Retrieving scan all metrics") + log.Info("Retrieving scan all metrics") metrics, err := api.GetScanAllMetrics(scheduled) if err != nil { - logrus.Errorf("Failed to retrieve scan all metrics: %v", utils.ParseHarborErrorMsg(err)) + log.Errorf("Failed to retrieve scan all metrics: %v", utils.ParseHarborErrorMsg(err)) return err } diff --git a/cmd/harbor/root/scan_all/run.go b/cmd/harbor/root/scan_all/run.go index 345eec97c..1a7dcd3e6 100644 --- a/cmd/harbor/root/scan_all/run.go +++ b/cmd/harbor/root/scan_all/run.go @@ -19,8 +19,8 @@ import ( "github.com/go-openapi/strfmt" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -54,7 +54,7 @@ The scan progress and results can be monitored through the metrics command or through the Harbor web interface.`, Args: cobra.MaximumNArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - logrus.Info("Initiating manual scan of all artifacts") + log.Info("Initiating manual scan of all artifacts") // Random cron expression and random time need to be passed to the API, even though they are not used, otherwise it returns bad request randomCron := "0 * * * * *" randomTime := strfmt.DateTime{} @@ -62,7 +62,7 @@ or through the Harbor web interface.`, if err != nil { return fmt.Errorf("failed to start scan all operation: %v", utils.ParseHarborErrorMsg(err)) } - logrus.Info("Successfully started scan all operation") + log.Info("Successfully started scan all operation") return nil }, } diff --git a/cmd/harbor/root/scan_all/stop.go b/cmd/harbor/root/scan_all/stop.go index 529e1a823..65da983be 100644 --- a/cmd/harbor/root/scan_all/stop.go +++ b/cmd/harbor/root/scan_all/stop.go @@ -15,8 +15,8 @@ package scan_all import ( "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -37,13 +37,13 @@ Examples: harbor-cli scan-all stop && harbor-cli scan-all metrics`, Args: cobra.MaximumNArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - logrus.Info("Stopping scan all operation") + log.Info("Stopping scan all operation") err := api.StopScanAll() if err != nil { - logrus.Errorf("Failed to stop scan all operation: %v", utils.ParseHarborErrorMsg(err)) + log.Errorf("Failed to stop scan all operation: %v", utils.ParseHarborErrorMsg(err)) return err } - logrus.Info("Successfully stopped scan all operation") + log.Info("Successfully stopped scan all operation") return nil }, } diff --git a/cmd/harbor/root/scan_all/update_schedule.go b/cmd/harbor/root/scan_all/update_schedule.go index 4c2dd0f5f..1fa22f838 100644 --- a/cmd/harbor/root/scan_all/update_schedule.go +++ b/cmd/harbor/root/scan_all/update_schedule.go @@ -21,9 +21,9 @@ import ( "github.com/go-openapi/strfmt" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/scan-all/update" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -84,7 +84,7 @@ Note: For custom schedules, if you provide a 5-field cron expression, the CLI wi return fmt.Errorf("invalid schedule type: %s. Valid types are: none, hourly, daily, weekly, custom", args[0]) } - logrus.Infof("Updating scan all schedule to type: %s", scheduleType) + log.Infof("Updating scan all schedule to type: %s", scheduleType) switch scheduleType { case "None": @@ -108,17 +108,17 @@ Note: For custom schedules, if you provide a 5-field cron expression, the CLI wi } func updateScheduleToNone() error { - logrus.Info("Setting scan all schedule to None (disabled)") + log.Info("Setting scan all schedule to None (disabled)") err := api.UpdateScanAllSchedule(models.ScheduleObj{Type: "None"}) if err != nil { return fmt.Errorf("failed to disable scan schedule: %v", utils.ParseHarborErrorMsg(err)) } - logrus.Info("Successfully disabled scan all schedule") + log.Info("Successfully disabled scan all schedule") return nil } func updatePredefinedSchedule(scheduleType string) error { - logrus.Infof("Setting scan all schedule to %s", scheduleType) + log.Infof("Setting scan all schedule to %s", scheduleType) // Random cron expression and time needed by API randomCron := "0 0 * * * * " @@ -134,13 +134,13 @@ func updatePredefinedSchedule(scheduleType string) error { return fmt.Errorf("failed to update scan schedule: %v", utils.ParseHarborErrorMsg(err)) } - logrus.Infof("Successfully set scan all schedule to %s", scheduleType) + log.Infof("Successfully set scan all schedule to %s", scheduleType) return nil } func updateCustomSchedule(cron string) error { if cron == "" { - logrus.Info("Opening interactive form for custom schedule configuration") + log.Info("Opening interactive form for custom schedule configuration") update.UpdateSchedule(&cron) } @@ -148,7 +148,7 @@ func updateCustomSchedule(cron string) error { return err } - logrus.Infof("Setting scan all schedule with custom cron expression: %s", cron) + log.Infof("Setting scan all schedule with custom cron expression: %s", cron) // Random time needed by API randomTime := strfmt.DateTime{} @@ -166,7 +166,7 @@ func updateCustomSchedule(cron string) error { return fmt.Errorf("failed to update scan schedule: %v", errMsg) } - logrus.Info("Successfully set scan all schedule with custom cron expression") + log.Info("Successfully set scan all schedule with custom cron expression") return nil } @@ -177,7 +177,7 @@ func validateCron(cron string) error { fields := strings.Fields(cron) if len(fields) < 6 { if len(fields) == 5 { - logrus.Infof("Converting 5-field cron to 6-field by adding '0' for seconds") + log.Infof("Converting 5-field cron to 6-field by adding '0' for seconds") return fmt.Errorf("harbor requires 6-field cron format (including seconds). Try: '0 %s'", cron) } return fmt.Errorf("harbor requires 6-field cron format (seconds minute hour day month weekday)") diff --git a/cmd/harbor/root/scan_all/view_schedule.go b/cmd/harbor/root/scan_all/view_schedule.go index 0ed2a05e9..8a9210180 100644 --- a/cmd/harbor/root/scan_all/view_schedule.go +++ b/cmd/harbor/root/scan_all/view_schedule.go @@ -15,9 +15,9 @@ package scan_all import ( "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/scan-all/view-schedule" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -50,10 +50,10 @@ You can use this command to verify changes after updating the schedule with the Args: cobra.MaximumNArgs(0), Aliases: []string{"vs"}, RunE: func(cmd *cobra.Command, args []string) error { - logrus.Info("Retrieving scan all schedule configuration") + log.Info("Retrieving scan all schedule configuration") schedule, err := api.GetScanAllSchedule() if err != nil { - logrus.Errorf("Failed to retrieve scan all schedule: %v", utils.ParseHarborErrorMsg(err)) + log.Errorf("Failed to retrieve scan all schedule: %v", utils.ParseHarborErrorMsg(err)) return err } diff --git a/cmd/harbor/root/scanner/delete.go b/cmd/harbor/root/scanner/delete.go index 1f397f22a..6f1f001b5 100644 --- a/cmd/harbor/root/scanner/delete.go +++ b/cmd/harbor/root/scanner/delete.go @@ -17,8 +17,8 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/scanner/list.go b/cmd/harbor/root/scanner/list.go index 603ebf1f7..4f2babf40 100644 --- a/cmd/harbor/root/scanner/list.go +++ b/cmd/harbor/root/scanner/list.go @@ -17,9 +17,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" list "github.com/goharbor/harbor-cli/pkg/views/scanner/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/scanner/update.go b/cmd/harbor/root/scanner/update.go index a79d250dd..ef52eac36 100644 --- a/cmd/harbor/root/scanner/update.go +++ b/cmd/harbor/root/scanner/update.go @@ -19,11 +19,11 @@ import ( "github.com/go-openapi/strfmt" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/scanner/create" "github.com/goharbor/harbor-cli/pkg/views/scanner/update" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/user/delete.go b/cmd/harbor/root/user/delete.go index e758685ff..f734cfeee 100644 --- a/cmd/harbor/root/user/delete.go +++ b/cmd/harbor/root/user/delete.go @@ -18,8 +18,8 @@ import ( "sync" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/user/elevate.go b/cmd/harbor/root/user/elevate.go index 56a91aed6..cec2d2679 100644 --- a/cmd/harbor/root/user/elevate.go +++ b/cmd/harbor/root/user/elevate.go @@ -18,9 +18,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/views" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/user/elevate_test.go b/cmd/harbor/root/user/elevate_test.go index 57124d719..d47dbf46f 100644 --- a/cmd/harbor/root/user/elevate_test.go +++ b/cmd/harbor/root/user/elevate_test.go @@ -19,7 +19,7 @@ import ( "strings" "testing" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/stretchr/testify/assert" ) diff --git a/cmd/harbor/root/user/list.go b/cmd/harbor/root/user/list.go index 4f72a09a8..4ba100b24 100644 --- a/cmd/harbor/root/user/list.go +++ b/cmd/harbor/root/user/list.go @@ -18,9 +18,9 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/user/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/harbor/root/user/password.go b/cmd/harbor/root/user/password.go index 5eb35ff50..5e934cd59 100644 --- a/cmd/harbor/root/user/password.go +++ b/cmd/harbor/root/user/password.go @@ -18,9 +18,9 @@ import ( "fmt" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/prompt" "github.com/goharbor/harbor-cli/pkg/views/password/reset" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/harbor/root/vulnerability/list.go b/cmd/harbor/root/vulnerability/list.go index e6a269932..3ad334547 100644 --- a/cmd/harbor/root/vulnerability/list.go +++ b/cmd/harbor/root/vulnerability/list.go @@ -18,9 +18,9 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" vulnlist "github.com/goharbor/harbor-cli/pkg/views/vulnerability/list" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/doc/doc.go b/doc/doc.go index 3da43e105..f01d09695 100644 --- a/doc/doc.go +++ b/doc/doc.go @@ -23,7 +23,7 @@ import ( "strings" cmd "github.com/goharbor/harbor-cli/cmd/harbor/root" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/spf13/cobra" "go.yaml.in/yaml/v4" ) diff --git a/doc/doc_test.go b/doc/doc_test.go index 3a2053142..6399b511c 100644 --- a/doc/doc_test.go +++ b/doc/doc_test.go @@ -23,7 +23,7 @@ import ( "regexp" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/spf13/cobra" "go.yaml.in/yaml/v4" ) diff --git a/doc/man-docs/man_doc.go b/doc/man-docs/man_doc.go index 1c32603cc..61410d355 100644 --- a/doc/man-docs/man_doc.go +++ b/doc/man-docs/man_doc.go @@ -22,7 +22,7 @@ import ( "strings" cmd "github.com/goharbor/harbor-cli/cmd/harbor/root" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/spf13/cobra/doc" ) diff --git a/go.mod b/go.mod index 460722842..5977c0c13 100644 --- a/go.mod +++ b/go.mod @@ -11,13 +11,12 @@ require ( github.com/charmbracelet/x/ansi v0.11.6 github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 github.com/sahilm/fuzzy v0.1.1 - github.com/sirupsen/logrus v1.9.4 github.com/spf13/cobra v1.10.2 github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 github.com/zalando/go-keyring v0.2.8 go.yaml.in/yaml/v4 v4.0.0-rc.4 - golang.org/x/term v0.42.0 + golang.org/x/term v0.40.0 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index c82e4f273..17e426bf9 100644 --- a/go.sum +++ b/go.sum @@ -146,8 +146,6 @@ github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDc github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA= github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= -github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= -github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= @@ -197,8 +195,8 @@ golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI= golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/term v0.42.0 h1:UiKe+zDFmJobeJ5ggPwOshJIVt6/Ft0rcfrXZDLWAWY= -golang.org/x/term v0.42.0/go.mod h1:Dq/D+snpsbazcBG5+F9Q1n2rXV8Ma+71xEjTRufARgY= +golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg= +golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM= golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg= golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/api/artifact_handler.go b/pkg/api/artifact_handler.go index d45e43370..5d521bf91 100644 --- a/pkg/api/artifact_handler.go +++ b/pkg/api/artifact_handler.go @@ -17,8 +17,8 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/artifact" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/scan" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) // DeleteArtifact handles the deletion of an artifact. diff --git a/pkg/api/cveallowlist_handler.go b/pkg/api/cveallowlist_handler.go index 075b2477f..c4fb03bc9 100644 --- a/pkg/api/cveallowlist_handler.go +++ b/pkg/api/cveallowlist_handler.go @@ -19,9 +19,9 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/system_cve_allowlist" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/cveallowlist/update" - log "github.com/sirupsen/logrus" ) func ListSystemCve() (system_cve_allowlist.GetSystemCVEAllowlistOK, error) { diff --git a/pkg/api/immutable_handler.go b/pkg/api/immutable_handler.go index 279865264..3a1189df7 100644 --- a/pkg/api/immutable_handler.go +++ b/pkg/api/immutable_handler.go @@ -16,9 +16,9 @@ package api import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/immutable" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/immutable/create" - log "github.com/sirupsen/logrus" ) func CreateImmutable(opts create.CreateView, projectName string) error { diff --git a/pkg/api/instance_handler.go b/pkg/api/instance_handler.go index be0d9f6f2..c2a8d1a5b 100644 --- a/pkg/api/instance_handler.go +++ b/pkg/api/instance_handler.go @@ -19,9 +19,9 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/preheat" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/instance/create" - log "github.com/sirupsen/logrus" ) func CreateInstance(opts create.CreateView) error { diff --git a/pkg/api/member_handler.go b/pkg/api/member_handler.go index 91fbcbdf4..c1a8388dc 100644 --- a/pkg/api/member_handler.go +++ b/pkg/api/member_handler.go @@ -21,9 +21,9 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/member" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/member/create" - log "github.com/sirupsen/logrus" ) // Function variables for testing - these can be swapped in tests diff --git a/pkg/api/ping_handler.go b/pkg/api/ping_handler.go index efc8cde20..50af09750 100644 --- a/pkg/api/ping_handler.go +++ b/pkg/api/ping_handler.go @@ -15,20 +15,20 @@ package api import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/ping" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - "github.com/sirupsen/logrus" ) func Ping() error { ctx, client, err := utils.ContextWithClient() if err != nil { - logrus.Errorf("failed to get client: %v", err) + log.Errorf("failed to get client: %v", err) return err } _, err = client.Ping.GetPing(ctx, &ping.GetPingParams{}) if err != nil { - logrus.Errorf("failed to ping the server: %v", err) + log.Errorf("failed to ping the server: %v", err) return err } diff --git a/pkg/api/project_config_handler.go b/pkg/api/project_config_handler.go index 87bed79a9..51708fa0b 100644 --- a/pkg/api/project_config_handler.go +++ b/pkg/api/project_config_handler.go @@ -18,8 +18,8 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/project_metadata" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) func ListConfig(isID bool, projectNameOrID string) (*project_metadata.ListProjectMetadatasOK, error) { diff --git a/pkg/api/project_handler.go b/pkg/api/project_handler.go index 0a4aacb18..6e3fe6a0f 100644 --- a/pkg/api/project_handler.go +++ b/pkg/api/project_handler.go @@ -20,9 +20,9 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/repository" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/search" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/project/create" - log "github.com/sirupsen/logrus" ) func CreateProject(opts create.CreateView) error { diff --git a/pkg/api/registry_handler.go b/pkg/api/registry_handler.go index 61658fdbe..20da62ca8 100644 --- a/pkg/api/registry_handler.go +++ b/pkg/api/registry_handler.go @@ -18,8 +18,8 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) func ListRegistries(opts ...ListFlags) (*registry.ListRegistriesOK, error) { diff --git a/pkg/api/repository_handler.go b/pkg/api/repository_handler.go index f8fb3c203..310f8d97a 100644 --- a/pkg/api/repository_handler.go +++ b/pkg/api/repository_handler.go @@ -16,8 +16,8 @@ package api import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/repository" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/search" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) func RepoDelete(projectNameOrID, repoName string, useProjectID bool) error { diff --git a/pkg/api/robot_handler.go b/pkg/api/robot_handler.go index 7dae05d23..43b96110d 100644 --- a/pkg/api/robot_handler.go +++ b/pkg/api/robot_handler.go @@ -22,10 +22,10 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/robot" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" "github.com/goharbor/harbor-cli/pkg/constants" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/robot/create" "github.com/goharbor/harbor-cli/pkg/views/robot/update" - log "github.com/sirupsen/logrus" ) func ListRobot(opts ListFlags) (*robot.ListRobotOK, error) { diff --git a/pkg/api/scan_all_handler.go b/pkg/api/scan_all_handler.go index 62c3b904b..0bac4cbeb 100644 --- a/pkg/api/scan_all_handler.go +++ b/pkg/api/scan_all_handler.go @@ -16,8 +16,8 @@ package api import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/scan_all" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) func CreateScanAllSchedule(schedule models.ScheduleObj) error { diff --git a/pkg/api/user_handler.go b/pkg/api/user_handler.go index 5049483d2..ef742ee1c 100644 --- a/pkg/api/user_handler.go +++ b/pkg/api/user_handler.go @@ -20,7 +20,7 @@ import ( "github.com/goharbor/harbor-cli/pkg/views/password/reset" "github.com/goharbor/harbor-cli/pkg/views/user/create" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) func CreateUser(opts create.CreateView) error { diff --git a/pkg/api/webhook_handler.go b/pkg/api/webhook_handler.go index 0fa7b2699..5535bcc66 100644 --- a/pkg/api/webhook_handler.go +++ b/pkg/api/webhook_handler.go @@ -19,10 +19,10 @@ import ( "github.com/goharbor/go-client/pkg/sdk/v2.0/client/webhook" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" "github.com/goharbor/harbor-cli/pkg/views/webhook/create" "github.com/goharbor/harbor-cli/pkg/views/webhook/edit" - log "github.com/sirupsen/logrus" ) func ListWebhooks(projectName string) (webhook.ListWebhookPoliciesOfProjectOK, error) { diff --git a/pkg/config/replication/policies.go b/pkg/config/replication/policies.go index 628720e48..322c9c090 100644 --- a/pkg/config/replication/policies.go +++ b/pkg/config/replication/policies.go @@ -20,8 +20,8 @@ import ( "path/filepath" "strings" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/views/replication/policies/create" - log "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" ) diff --git a/pkg/log/log.go b/pkg/log/log.go new file mode 100644 index 000000000..27a3ffd07 --- /dev/null +++ b/pkg/log/log.go @@ -0,0 +1,302 @@ +// Copyright Project Harbor Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package log + +import ( + "fmt" + "io" + "log/slog" + "os" + "sync" + "time" +) + +// Fields is a type alias for structured log fields, matching logrus.Fields. +type Fields map[string]any + +// Level represents a log severity level. +type Level = slog.Level + +const ( + LevelDebug = slog.LevelDebug + LevelInfo = slog.LevelInfo + LevelWarn = slog.LevelWarn + LevelError = slog.LevelError + + // Logrus-compatible aliases. + InfoLevel = slog.LevelInfo + DebugLevel = slog.LevelDebug + WarnLevel = slog.LevelWarn + ErrorLevel = slog.LevelError +) + +// TextFormatter mirrors logrus.TextFormatter for backward-compatible configuration. +type TextFormatter struct { + FullTimestamp bool + TimestampFormat string + DisableColors bool +} + +// Logger wraps slog.Logger to provide a logrus-compatible API surface. +type Logger struct { + logger *slog.Logger + Out io.Writer // exported field matching logrus.Logger.Out + level Level + formatter *TextFormatter +} + +var ( + mu sync.Mutex + defaultLogger *Logger + currentLevel Level = LevelInfo + currentOutput io.Writer = os.Stderr +) + +func init() { + rebuildDefaultLogger() +} + +func rebuildDefaultLogger() { + opts := &slog.HandlerOptions{Level: currentLevel} + defaultLogger = &Logger{ + logger: slog.New(slog.NewTextHandler(currentOutput, opts)), + Out: currentOutput, + level: currentLevel, + } +} + +// SetLevel sets the minimum log level on the default logger. +func SetLevel(level Level) { + mu.Lock() + defer mu.Unlock() + currentLevel = level + rebuildDefaultLogger() +} + +// SetOutput sets the output destination on the default logger. +func SetOutput(w io.Writer) { + mu.Lock() + defer mu.Unlock() + currentOutput = w + rebuildDefaultLogger() +} + +// New creates a new Logger instance. +func New() *Logger { + return &Logger{ + logger: slog.New(slog.NewTextHandler(os.Stderr, nil)), + Out: os.Stderr, + level: LevelInfo, + } +} + +// StandardLogger returns the default package-level logger. +func StandardLogger() *Logger { + return defaultLogger +} + +// Out returns the underlying io.Writer. + +// SetLevel sets the minimum log level on this Logger instance. +func (l *Logger) SetLevel(level Level) { + l.level = level + l.rebuildHandler() +} + +// SetFormatter configures the formatter for this Logger instance. +func (l *Logger) SetFormatter(f *TextFormatter) { + l.formatter = f + l.rebuildHandler() +} + +// SetOutput sets the output destination on this Logger instance. +func (l *Logger) SetOutput(w io.Writer) { + l.Out = w + l.rebuildHandler() +} + +func (l *Logger) rebuildHandler() { + opts := &slog.HandlerOptions{Level: l.level} + if l.formatter != nil && l.formatter.TimestampFormat != "" { + opts.ReplaceAttr = func(groups []string, a slog.Attr) slog.Attr { + if a.Key == slog.TimeKey && len(groups) == 0 { + a.Value = slog.StringValue(time.Now().Format(l.formatter.TimestampFormat)) + } + return a + } + } + l.logger = slog.New(slog.NewTextHandler(l.Out, opts)) +} + +// WithTime returns a Logger with the given time added as the "time" attribute. +func (l *Logger) WithTime(t time.Time) *Logger { + return l.WithField("time", t) +} + +// WithField returns a Logger with the given key-value pair added to its context. +func WithField(key string, value any) *Logger { + return defaultLogger.WithField(key, value) +} + +// WithField returns a Logger with the given key-value pair added to its context. +func (l *Logger) WithField(key string, value any) *Logger { + return &Logger{ + logger: l.logger.With(key, value), + Out: l.Out, + level: l.level, + formatter: l.formatter, + } +} + +// WithFields returns a Logger with the given key-value pairs added to its context. +func WithFields(fields Fields) *Logger { + return defaultLogger.WithFields(fields) +} + +// WithFields returns a Logger with the given key-value pairs added to its context. +func (l *Logger) WithFields(fields Fields) *Logger { + attrs := make([]any, 0, len(fields)*2) + for k, v := range fields { + attrs = append(attrs, k, v) + } + return &Logger{ + logger: l.logger.With(attrs...), + Out: l.Out, + level: l.level, + formatter: l.formatter, + } +} + +// --- Package-level convenience methods --- + +// Debug logs a message at Debug level. +func Debug(args ...any) { + defaultLogger.logger.Debug(fmt.Sprint(args...)) +} + +func (l *Logger) Debug(args ...any) { + l.logger.Debug(fmt.Sprint(args...)) +} + +// Debugf logs a formatted message at Debug level. +func Debugf(format string, args ...any) { + defaultLogger.logger.Debug(fmt.Sprintf(format, args...)) +} + +func (l *Logger) Debugf(format string, args ...any) { + l.logger.Debug(fmt.Sprintf(format, args...)) +} + +// Info logs a message at Info level. +func Info(args ...any) { + defaultLogger.logger.Info(fmt.Sprint(args...)) +} + +func (l *Logger) Info(args ...any) { + l.logger.Info(fmt.Sprint(args...)) +} + +// Infof logs a formatted message at Info level. +func Infof(format string, args ...any) { + defaultLogger.logger.Info(fmt.Sprintf(format, args...)) +} + +func (l *Logger) Infof(format string, args ...any) { + l.logger.Info(fmt.Sprintf(format, args...)) +} + +// Warn logs a message at Warn level. +func Warn(args ...any) { + defaultLogger.logger.Warn(fmt.Sprint(args...)) +} + +func (l *Logger) Warn(args ...any) { + l.logger.Warn(fmt.Sprint(args...)) +} + +// Warnf logs a formatted message at Warn level. +func Warnf(format string, args ...any) { + defaultLogger.logger.Warn(fmt.Sprintf(format, args...)) +} + +func (l *Logger) Warnf(format string, args ...any) { + l.logger.Warn(fmt.Sprintf(format, args...)) +} + +// Warningf is an alias for Warnf. +func Warningf(format string, args ...any) { + Warnf(format, args...) +} + +func (l *Logger) Warningf(format string, args ...any) { + l.Warnf(format, args...) +} + +// Error logs a message at Error level. +func Error(args ...any) { + defaultLogger.logger.Error(fmt.Sprint(args...)) +} + +func (l *Logger) Error(args ...any) { + l.logger.Error(fmt.Sprint(args...)) +} + +// Errorf logs a formatted message at Error level. +func Errorf(format string, args ...any) { + defaultLogger.logger.Error(fmt.Sprintf(format, args...)) +} + +func (l *Logger) Errorf(format string, args ...any) { + l.logger.Error(fmt.Sprintf(format, args...)) +} + +// Fatal logs a message at Error level and exits with status 1. +func Fatal(args ...any) { + defaultLogger.logger.Error(fmt.Sprint(args...)) + os.Exit(1) +} + +func (l *Logger) Fatal(args ...any) { + l.logger.Error(fmt.Sprint(args...)) + os.Exit(1) +} + +// Fatalf logs a formatted message at Error level and exits with status 1. +func Fatalf(format string, args ...any) { + defaultLogger.logger.Error(fmt.Sprintf(format, args...)) + os.Exit(1) +} + +func (l *Logger) Fatalf(format string, args ...any) { + l.logger.Error(fmt.Sprintf(format, args...)) + os.Exit(1) +} + +// Printf logs a formatted message at Info level. +func Printf(format string, args ...any) { + defaultLogger.logger.Info(fmt.Sprintf(format, args...)) +} + +func (l *Logger) Printf(format string, args ...any) { + l.logger.Info(fmt.Sprintf(format, args...)) +} + +// Println logs a message at Info level. +func Println(args ...any) { + defaultLogger.logger.Info(fmt.Sprintln(args...)) +} + +func (l *Logger) Println(args ...any) { + l.logger.Info(fmt.Sprintln(args...)) +} diff --git a/pkg/prompt/prompt.go b/pkg/prompt/prompt.go index 2ed2e2890..f27de0312 100644 --- a/pkg/prompt/prompt.go +++ b/pkg/prompt/prompt.go @@ -37,12 +37,12 @@ import ( rpolicies "github.com/goharbor/harbor-cli/pkg/views/replication/policies/select" rtasks "github.com/goharbor/harbor-cli/pkg/views/replication/task/select" + log "github.com/goharbor/harbor-cli/pkg/log" repoView "github.com/goharbor/harbor-cli/pkg/views/repository/select" robotView "github.com/goharbor/harbor-cli/pkg/views/robot/select" sview "github.com/goharbor/harbor-cli/pkg/views/scanner/select" uview "github.com/goharbor/harbor-cli/pkg/views/user/select" wview "github.com/goharbor/harbor-cli/pkg/views/webhook/select" - log "github.com/sirupsen/logrus" ) func GetRegistryNameFromUser() int64 { diff --git a/pkg/utils/client.go b/pkg/utils/client.go index 8929661ca..6241e6751 100644 --- a/pkg/utils/client.go +++ b/pkg/utils/client.go @@ -20,7 +20,7 @@ import ( "github.com/goharbor/go-client/pkg/harbor" v2client "github.com/goharbor/go-client/pkg/sdk/v2.0/client" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) var ( diff --git a/pkg/utils/config.go b/pkg/utils/config.go index 0a28e0ee0..185d148d4 100644 --- a/pkg/utils/config.go +++ b/pkg/utils/config.go @@ -21,7 +21,7 @@ import ( "sync" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/spf13/viper" ) diff --git a/pkg/utils/encryption.go b/pkg/utils/encryption.go index 0f61840c8..8a9b955e4 100644 --- a/pkg/utils/encryption.go +++ b/pkg/utils/encryption.go @@ -25,7 +25,7 @@ import ( "strings" "sync" - "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/zalando/go-keyring" ) @@ -127,7 +127,7 @@ func GetKeyringProvider() KeyringProvider { // Priority 1: Check for environment variable configuration envKeyName := "HARBOR_ENCRYPTION_KEY" if envKey := os.Getenv(envKeyName); envKey != "" { - logrus.Debug("Using environment-based encryption key") + log.Debug("Using environment-based encryption key") return &EnvironmentKeyring{ EnvVarName: envKeyName, } @@ -138,9 +138,9 @@ func GetKeyringProvider() KeyringProvider { // Clean up the test entry err = keyring.Delete("harbor-cli-test", "test-user") if err != nil { - logrus.Warnf("Failed to delete test entry from system keyring: %v", err) + log.Warnf("Failed to delete test entry from system keyring: %v", err) } - logrus.Debug("Using system keyring") + log.Debug("Using system keyring") return &SystemKeyring{} } @@ -153,7 +153,7 @@ func GetKeyringProvider() KeyringProvider { BaseDir: filepath.Join(homeDir, ".harbor", "keyring"), } - logrus.Info("System keyring not available, using file-based keyring") + log.Info("System keyring not available, using file-based keyring") return fileKeyring } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 118b2a364..aa7afafc4 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -27,8 +27,8 @@ import ( "github.com/charmbracelet/bubbles/table" "github.com/gocarina/gocsv" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/user" + log "github.com/goharbor/harbor-cli/pkg/log" uview "github.com/goharbor/harbor-cli/pkg/views/user/select" - log "github.com/sirupsen/logrus" "github.com/spf13/viper" "go.yaml.in/yaml/v4" "golang.org/x/term" diff --git a/pkg/views/artifact/tags/create/view.go b/pkg/views/artifact/tags/create/view.go index ce52f47e8..3ac301cd9 100644 --- a/pkg/views/artifact/tags/create/view.go +++ b/pkg/views/artifact/tags/create/view.go @@ -18,8 +18,8 @@ import ( "strings" "github.com/charmbracelet/huh" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) func CreateTagView(tagName *string) { diff --git a/pkg/views/confirmation.go b/pkg/views/confirmation.go index a8348dc6b..d2296d278 100644 --- a/pkg/views/confirmation.go +++ b/pkg/views/confirmation.go @@ -15,7 +15,7 @@ package views import ( "github.com/charmbracelet/huh" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) func ConfirmElevation() (bool, error) { diff --git a/pkg/views/cveallowlist/update/view.go b/pkg/views/cveallowlist/update/view.go index d938cd9f3..94fe69659 100644 --- a/pkg/views/cveallowlist/update/view.go +++ b/pkg/views/cveallowlist/update/view.go @@ -17,7 +17,7 @@ import ( "errors" "github.com/charmbracelet/huh" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) type UpdateView struct { diff --git a/pkg/views/immutable/create/view.go b/pkg/views/immutable/create/view.go index d81ea5424..fe7246f69 100644 --- a/pkg/views/immutable/create/view.go +++ b/pkg/views/immutable/create/view.go @@ -17,7 +17,7 @@ import ( "errors" "github.com/charmbracelet/huh" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) type CreateView struct { diff --git a/pkg/views/instance/create/view.go b/pkg/views/instance/create/view.go index 13dc896e3..0c5bd17c3 100644 --- a/pkg/views/instance/create/view.go +++ b/pkg/views/instance/create/view.go @@ -18,8 +18,8 @@ import ( "strings" "github.com/charmbracelet/huh" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) type CreateView struct { diff --git a/pkg/views/label/create/view.go b/pkg/views/label/create/view.go index 366b8a757..674cb241c 100644 --- a/pkg/views/label/create/view.go +++ b/pkg/views/label/create/view.go @@ -17,7 +17,7 @@ import ( "errors" "github.com/charmbracelet/huh" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) type CreateView struct { diff --git a/pkg/views/label/update/view.go b/pkg/views/label/update/view.go index cf62d9393..98d79a20d 100644 --- a/pkg/views/label/update/view.go +++ b/pkg/views/label/update/view.go @@ -18,7 +18,7 @@ import ( "github.com/charmbracelet/huh" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) func UpdateLabelView(updateView *models.Label) { diff --git a/pkg/views/login/create.go b/pkg/views/login/create.go index 9542dcde2..4ee90c1c3 100644 --- a/pkg/views/login/create.go +++ b/pkg/views/login/create.go @@ -18,8 +18,8 @@ import ( "strings" "github.com/charmbracelet/huh" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) type LoginView struct { diff --git a/pkg/views/password/change/view.go b/pkg/views/password/change/view.go index 16385e116..8836dfac9 100644 --- a/pkg/views/password/change/view.go +++ b/pkg/views/password/change/view.go @@ -18,8 +18,8 @@ import ( "strings" "github.com/charmbracelet/huh" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) type PasswordChangeView struct { diff --git a/pkg/views/password/reset/view.go b/pkg/views/password/reset/view.go index c9f4c4ecf..eea920662 100644 --- a/pkg/views/password/reset/view.go +++ b/pkg/views/password/reset/view.go @@ -18,8 +18,8 @@ import ( "strings" "github.com/charmbracelet/huh" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) type PasswordChangeView struct { diff --git a/pkg/views/project/config/update/view.go b/pkg/views/project/config/update/view.go index ff5a06997..e17ffd000 100644 --- a/pkg/views/project/config/update/view.go +++ b/pkg/views/project/config/update/view.go @@ -16,7 +16,7 @@ package update import ( "github.com/charmbracelet/huh" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) func validateValue(value *string) *string { diff --git a/pkg/views/project/create/view.go b/pkg/views/project/create/view.go index aba8ecadb..28d7b4d97 100644 --- a/pkg/views/project/create/view.go +++ b/pkg/views/project/create/view.go @@ -21,8 +21,8 @@ import ( "github.com/charmbracelet/huh" "github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" "github.com/spf13/viper" ) diff --git a/pkg/views/quota/update/view.go b/pkg/views/quota/update/view.go index f3bb299a0..c65525523 100644 --- a/pkg/views/quota/update/view.go +++ b/pkg/views/quota/update/view.go @@ -22,8 +22,8 @@ import ( "github.com/charmbracelet/huh" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/views/quota/list" - log "github.com/sirupsen/logrus" ) type CreateView struct { diff --git a/pkg/views/registry/create/view.go b/pkg/views/registry/create/view.go index afff393d0..9d50d0774 100644 --- a/pkg/views/registry/create/view.go +++ b/pkg/views/registry/create/view.go @@ -20,8 +20,8 @@ import ( "github.com/charmbracelet/huh" "github.com/goharbor/harbor-cli/pkg/api" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) // struct to hold registry options diff --git a/pkg/views/registry/update/view.go b/pkg/views/registry/update/view.go index 3330f6b15..220b97166 100644 --- a/pkg/views/registry/update/view.go +++ b/pkg/views/registry/update/view.go @@ -19,8 +19,8 @@ import ( "github.com/charmbracelet/huh" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) func UpdateRegistryView(updateView *models.Registry) { diff --git a/pkg/views/replication/policies/create/view.go b/pkg/views/replication/policies/create/view.go index 8d26660fa..64a949a7d 100644 --- a/pkg/views/replication/policies/create/view.go +++ b/pkg/views/replication/policies/create/view.go @@ -21,7 +21,7 @@ import ( "github.com/charmbracelet/huh" "github.com/charmbracelet/lipgloss" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) type CreateView struct { diff --git a/pkg/views/robot/create/view.go b/pkg/views/robot/create/view.go index 1f649fb65..18aec7e81 100644 --- a/pkg/views/robot/create/view.go +++ b/pkg/views/robot/create/view.go @@ -20,7 +20,7 @@ import ( "github.com/charmbracelet/huh" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) type CreateView struct { diff --git a/pkg/views/robot/update/view.go b/pkg/views/robot/update/view.go index 8d4d1a715..37cdc118d 100644 --- a/pkg/views/robot/update/view.go +++ b/pkg/views/robot/update/view.go @@ -20,7 +20,7 @@ import ( "github.com/charmbracelet/huh" "github.com/go-openapi/strfmt" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) type UpdateView struct { diff --git a/pkg/views/scan-all/update/view.go b/pkg/views/scan-all/update/view.go index d2a451b42..58c16269d 100644 --- a/pkg/views/scan-all/update/view.go +++ b/pkg/views/scan-all/update/view.go @@ -20,7 +20,7 @@ import ( "strings" "github.com/charmbracelet/huh" - log "github.com/sirupsen/logrus" + log "github.com/goharbor/harbor-cli/pkg/log" ) func UpdateSchedule(cron *string) { diff --git a/pkg/views/scanner/create/view.go b/pkg/views/scanner/create/view.go index e38765f4e..c5070beaa 100644 --- a/pkg/views/scanner/create/view.go +++ b/pkg/views/scanner/create/view.go @@ -18,8 +18,8 @@ import ( "strings" "github.com/charmbracelet/huh" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) type CreateView struct { diff --git a/pkg/views/scanner/update/view.go b/pkg/views/scanner/update/view.go index 17019b46e..3d5eb9c51 100644 --- a/pkg/views/scanner/update/view.go +++ b/pkg/views/scanner/update/view.go @@ -20,8 +20,8 @@ import ( "github.com/charmbracelet/huh" "github.com/go-openapi/strfmt" "github.com/goharbor/go-client/pkg/sdk/v2.0/models" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) func UpdateScannerView(scanner *models.ScannerRegistration) { diff --git a/pkg/views/user/create/view.go b/pkg/views/user/create/view.go index b11b1d8b6..9ba89e78e 100644 --- a/pkg/views/user/create/view.go +++ b/pkg/views/user/create/view.go @@ -18,8 +18,8 @@ import ( "strings" "github.com/charmbracelet/huh" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) type CreateView struct { diff --git a/pkg/views/webhook/edit/view.go b/pkg/views/webhook/edit/view.go index 6c2b5e3d9..80442b4ff 100644 --- a/pkg/views/webhook/edit/view.go +++ b/pkg/views/webhook/edit/view.go @@ -18,8 +18,8 @@ import ( "strings" "github.com/charmbracelet/huh" + log "github.com/goharbor/harbor-cli/pkg/log" "github.com/goharbor/harbor-cli/pkg/utils" - log "github.com/sirupsen/logrus" ) type EditView struct {