Added flags on cli auth login

This commit is contained in:
anonpenguin23 2026-01-31 07:27:55 +02:00
parent 810094771d
commit 04f345f9ee
3 changed files with 33 additions and 23 deletions

View File

@ -16,20 +16,22 @@ import (
// PerformSimpleAuthentication performs a simple authentication flow where the user
// provides a wallet address and receives an API key without signature verification
func PerformSimpleAuthentication(gatewayURL string) (*Credentials, error) {
func PerformSimpleAuthentication(gatewayURL, wallet, namespace string) (*Credentials, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Println("\n🔐 Simple Wallet Authentication")
fmt.Println("================================")
// Read wallet address
// Read wallet address (skip prompt if provided via flag)
if wallet == "" {
fmt.Print("Enter your wallet address (0x...): ")
walletInput, err := reader.ReadString('\n')
if err != nil {
return nil, fmt.Errorf("failed to read wallet address: %w", err)
}
wallet = strings.TrimSpace(walletInput)
}
wallet := strings.TrimSpace(walletInput)
if wallet == "" {
return nil, fmt.Errorf("wallet address cannot be empty")
}
@ -43,8 +45,8 @@ func PerformSimpleAuthentication(gatewayURL string) (*Credentials, error) {
return nil, fmt.Errorf("invalid wallet address format")
}
// Read namespace (required)
var namespace string
// Read namespace (skip prompt if provided via flag)
if namespace == "" {
for {
fmt.Print("Enter namespace (required): ")
nsInput, err := reader.ReadString('\n')
@ -58,6 +60,7 @@ func PerformSimpleAuthentication(gatewayURL string) (*Credentials, error) {
}
fmt.Println("⚠️ Namespace cannot be empty. Please enter a namespace.")
}
}
fmt.Printf("\n✅ Wallet: %s\n", wallet)
fmt.Printf("✅ Namespace: %s\n", namespace)

View File

@ -2,6 +2,7 @@ package cli
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
@ -19,7 +20,12 @@ func HandleAuthCommand(args []string) {
subcommand := args[0]
switch subcommand {
case "login":
handleAuthLogin()
var wallet, namespace string
fs := flag.NewFlagSet("auth login", flag.ExitOnError)
fs.StringVar(&wallet, "wallet", "", "Wallet address (0x...)")
fs.StringVar(&namespace, "namespace", "", "Namespace name")
_ = fs.Parse(args[1:])
handleAuthLogin(wallet, namespace)
case "logout":
handleAuthLogout()
case "whoami":
@ -49,6 +55,7 @@ func showAuthHelp() {
fmt.Printf(" switch - Switch between stored credentials\n\n")
fmt.Printf("Examples:\n")
fmt.Printf(" orama auth login # Enter wallet address interactively\n")
fmt.Printf(" orama auth login --wallet 0x... --namespace myns # Non-interactive\n")
fmt.Printf(" orama auth whoami # Check who you're logged in as\n")
fmt.Printf(" orama auth status # View detailed authentication info\n")
fmt.Printf(" orama auth logout # Clear all stored credentials\n\n")
@ -63,7 +70,7 @@ func showAuthHelp() {
fmt.Printf(" Use 'orama env current' to see your active environment.\n")
}
func handleAuthLogin() {
func handleAuthLogin(wallet, namespace string) {
// Get gateway URL from active environment
gatewayURL := getGatewayURL()
@ -123,7 +130,7 @@ func handleAuthLogin() {
}
// Perform simple authentication to add a new credential
creds, err := auth.PerformSimpleAuthentication(gatewayURL)
creds, err := auth.PerformSimpleAuthentication(gatewayURL, wallet, namespace)
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Authentication failed: %v\n", err)
os.Exit(1)

View File

@ -298,7 +298,7 @@ func (cm *ClusterManager) startOlricCluster(ctx context.Context, cluster *Namesp
NodeID: node.NodeID,
HTTPPort: portBlocks[i].OlricHTTPPort,
MemberlistPort: portBlocks[i].OlricMemberlistPort,
BindAddr: "0.0.0.0",
BindAddr: node.InternalIP,
AdvertiseAddr: node.InternalIP,
PeerAddresses: peerAddresses,
}