fix: Return 0 on successful auth setup

This commit is contained in:
abhisek 2023-11-20 16:04:55 +05:30
parent d56b950030
commit 092d9a78d9
No known key found for this signature in database
GPG Key ID: CB92A4990C02A88F

22
auth.go
View File

@ -4,13 +4,13 @@ import (
"errors"
"fmt"
"os"
"syscall"
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"
"golang.org/x/term"
"github.com/safedep/vet/internal/auth"
"github.com/safedep/vet/internal/ui"
"github.com/safedep/vet/pkg/common/logger"
)
var (
@ -43,19 +43,21 @@ func configureAuthCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "configure",
RunE: func(cmd *cobra.Command, args []string) error {
var key []byte
var key string
var err error
if !authCommunity {
fmt.Print("Enter API Key: ")
key, err = term.ReadPassword(syscall.Stdin)
if err != nil {
panic(err)
}
err = survey.AskOne(&survey.Password{
Message: "Enter the API key",
}, &key)
} else {
authInsightApiBaseUrl = auth.DefaultCommunityApiUrl()
}
if err != nil {
logger.Fatalf("Failed to setup auth: %v", err)
}
err = auth.Configure(auth.Config{
ApiUrl: authInsightApiBaseUrl,
ApiKey: string(key),
@ -64,10 +66,10 @@ func configureAuthCommand() *cobra.Command {
})
if err != nil {
panic(err)
logger.Fatalf("Failed to configure auth: %v", err)
}
os.Exit(1)
os.Exit(0)
return nil
},
}