refactor: fold auth and crypto into deezer domain

This commit is contained in:
Mathis Maquenne
2026-08-05 11:40:14 +02:00
parent 16c71c8688
commit dbd7837b17
11 changed files with 60 additions and 72 deletions
+26 -4
View File
@@ -1,10 +1,14 @@
package cmd
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/mathismqn/godeez/internal/auth"
"github.com/mathismqn/godeez/internal/deezer"
"github.com/spf13/cobra"
"golang.org/x/term"
)
func newLoginCmd() *cobra.Command {
@@ -13,16 +17,16 @@ func newLoginCmd() *cobra.Command {
Short: "Log in to Deezer with your email and password",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if err := auth.CheckGatewayEnv(); err != nil {
if err := deezer.CheckGatewayEnv(); err != nil {
return err
}
email, password, err := auth.PromptCredentials()
email, password, err := promptCredentials()
if err != nil {
return err
}
_, username, err := auth.Login(cmd.Context(), email, password)
_, username, err := deezer.Login(cmd.Context(), email, password)
if err != nil {
return err
}
@@ -33,3 +37,21 @@ func newLoginCmd() *cobra.Command {
},
}
}
func promptCredentials() (string, string, error) {
fmt.Print("Email: ")
line, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return "", "", err
}
email := strings.TrimSpace(line)
fmt.Print("Password: ")
passwordBytes, err := term.ReadPassword(int(os.Stdin.Fd()))
fmt.Println()
if err != nil {
return "", "", err
}
return email, string(passwordBytes), nil
}
+2 -2
View File
@@ -3,7 +3,7 @@ package cmd
import (
"fmt"
"github.com/mathismqn/godeez/internal/auth"
"github.com/mathismqn/godeez/internal/deezer"
"github.com/spf13/cobra"
)
@@ -13,7 +13,7 @@ func newLogoutCmd() *cobra.Command {
Short: "Remove stored Deezer credentials",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if err := auth.Clear(); err != nil {
if err := deezer.ClearCredentials(); err != nil {
return err
}