2026-04-13 13:40:18 +05:30
|
|
|
package cloud
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/safedep/dry/cloud"
|
|
|
|
|
"github.com/safedep/dry/log"
|
2026-05-24 12:22:19 +05:30
|
|
|
"github.com/safedep/dry/usefulerror"
|
|
|
|
|
"github.com/safedep/pmg/errcodes"
|
2026-05-24 12:46:06 +05:30
|
|
|
"github.com/safedep/pmg/internal/ui"
|
2026-04-13 13:40:18 +05:30
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func newLogoutCommand() *cobra.Command {
|
|
|
|
|
return &cobra.Command{
|
|
|
|
|
Use: "logout",
|
|
|
|
|
Short: "Clear stored SafeDep Cloud credentials",
|
|
|
|
|
RunE: runLogout,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runLogout(cmd *cobra.Command, args []string) error {
|
|
|
|
|
store, err := cloud.NewKeychainCredentialStore()
|
|
|
|
|
if err != nil {
|
2026-05-24 12:22:19 +05:30
|
|
|
ui.ErrorExit(usefulerror.NewUsefulError().
|
2026-04-13 13:40:18 +05:30
|
|
|
Wrap(err).
|
2026-05-24 12:22:19 +05:30
|
|
|
WithCode(errcodes.Lifecycle).
|
2026-04-13 13:40:18 +05:30
|
|
|
WithHumanError("Failed to initialize credential store").
|
|
|
|
|
WithHelp("Your system may not support secure credential storage"))
|
|
|
|
|
}
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := store.Close(); err != nil {
|
|
|
|
|
log.Warnf("failed to close credential store: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
if err := store.Clear(); err != nil {
|
2026-05-24 12:22:19 +05:30
|
|
|
ui.ErrorExit(usefulerror.NewUsefulError().
|
2026-04-13 13:40:18 +05:30
|
|
|
Wrap(err).
|
2026-05-24 12:22:19 +05:30
|
|
|
WithCode(errcodes.Lifecycle).
|
2026-04-13 13:40:18 +05:30
|
|
|
WithHumanError("Failed to clear credentials"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.Successf("Credentials cleared from keychain")
|
|
|
|
|
return nil
|
|
|
|
|
}
|