FRE-680: Initial project scaffold with auth & API client
- Set up Go module with Cobra CLI skeleton - Implemented login/logout/session commands with 2FA support - Created ProtonMail API client with rate limiting - Added config management for ~/.config/pop/ - Configured CI/CD pipeline with GitHub Actions - Added Makefile for build/test/lint targets Files: - main.go, go.mod, go.sum - cmd/root.go, cmd/auth.go - internal/auth/session.go - internal/config/config.go - internal/api/client.go - Makefile, README.md, .gitignore - .github/workflows/ci.yml
This commit is contained in:
60
cmd/auth.go
Normal file
60
cmd/auth.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/frenocorp/pop/internal/auth"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func loginCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "login",
|
||||
Short: "Log in to ProtonMail",
|
||||
Long: `Authenticate with ProtonMail API and store session credentials.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
manager := auth.NewSessionManager()
|
||||
return manager.Login()
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringP("email", "e", "", "ProtonMail email address")
|
||||
cmd.Flags().StringP("password", "p", "", "ProtonMail password")
|
||||
cmd.Flags().BoolP("interactive", "i", true, "Interactive prompt for credentials")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func logoutCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "logout",
|
||||
Short: "Log out from ProtonMail",
|
||||
Long: `Clear stored session credentials.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
manager := auth.NewSessionManager()
|
||||
return manager.Logout()
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func sessionCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "session",
|
||||
Short: "Show current session info",
|
||||
Long: `Display current authentication session details.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
manager := auth.NewSessionManager()
|
||||
session, err := manager.GetSession()
|
||||
if err != nil {
|
||||
return fmt.Errorf("no active session: %w", err)
|
||||
}
|
||||
fmt.Fprintf(os.Stdout, "Session: %s\n", session.UID)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
Reference in New Issue
Block a user