mirror of
https://github.com/DeBrosOfficial/orama.git
synced 2026-03-17 09:46:59 +00:00
Added flags on cli auth login
This commit is contained in:
parent
810094771d
commit
04f345f9ee
@ -16,20 +16,22 @@ import (
|
|||||||
|
|
||||||
// PerformSimpleAuthentication performs a simple authentication flow where the user
|
// PerformSimpleAuthentication performs a simple authentication flow where the user
|
||||||
// provides a wallet address and receives an API key without signature verification
|
// 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)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
fmt.Println("\n🔐 Simple Wallet Authentication")
|
fmt.Println("\n🔐 Simple Wallet Authentication")
|
||||||
fmt.Println("================================")
|
fmt.Println("================================")
|
||||||
|
|
||||||
// Read wallet address
|
// Read wallet address (skip prompt if provided via flag)
|
||||||
fmt.Print("Enter your wallet address (0x...): ")
|
if wallet == "" {
|
||||||
walletInput, err := reader.ReadString('\n')
|
fmt.Print("Enter your wallet address (0x...): ")
|
||||||
if err != nil {
|
walletInput, err := reader.ReadString('\n')
|
||||||
return nil, fmt.Errorf("failed to read wallet address: %w", err)
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to read wallet address: %w", err)
|
||||||
|
}
|
||||||
|
wallet = strings.TrimSpace(walletInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
wallet := strings.TrimSpace(walletInput)
|
|
||||||
if wallet == "" {
|
if wallet == "" {
|
||||||
return nil, fmt.Errorf("wallet address cannot be empty")
|
return nil, fmt.Errorf("wallet address cannot be empty")
|
||||||
}
|
}
|
||||||
@ -43,20 +45,21 @@ func PerformSimpleAuthentication(gatewayURL string) (*Credentials, error) {
|
|||||||
return nil, fmt.Errorf("invalid wallet address format")
|
return nil, fmt.Errorf("invalid wallet address format")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read namespace (required)
|
// Read namespace (skip prompt if provided via flag)
|
||||||
var namespace string
|
if namespace == "" {
|
||||||
for {
|
for {
|
||||||
fmt.Print("Enter namespace (required): ")
|
fmt.Print("Enter namespace (required): ")
|
||||||
nsInput, err := reader.ReadString('\n')
|
nsInput, err := reader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read namespace: %w", err)
|
return nil, fmt.Errorf("failed to read namespace: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace = strings.TrimSpace(nsInput)
|
namespace = strings.TrimSpace(nsInput)
|
||||||
if namespace != "" {
|
if namespace != "" {
|
||||||
break
|
break
|
||||||
|
}
|
||||||
|
fmt.Println("⚠️ Namespace cannot be empty. Please enter a namespace.")
|
||||||
}
|
}
|
||||||
fmt.Println("⚠️ Namespace cannot be empty. Please enter a namespace.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\n✅ Wallet: %s\n", wallet)
|
fmt.Printf("\n✅ Wallet: %s\n", wallet)
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -19,7 +20,12 @@ func HandleAuthCommand(args []string) {
|
|||||||
subcommand := args[0]
|
subcommand := args[0]
|
||||||
switch subcommand {
|
switch subcommand {
|
||||||
case "login":
|
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":
|
case "logout":
|
||||||
handleAuthLogout()
|
handleAuthLogout()
|
||||||
case "whoami":
|
case "whoami":
|
||||||
@ -49,6 +55,7 @@ func showAuthHelp() {
|
|||||||
fmt.Printf(" switch - Switch between stored credentials\n\n")
|
fmt.Printf(" switch - Switch between stored credentials\n\n")
|
||||||
fmt.Printf("Examples:\n")
|
fmt.Printf("Examples:\n")
|
||||||
fmt.Printf(" orama auth login # Enter wallet address interactively\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 whoami # Check who you're logged in as\n")
|
||||||
fmt.Printf(" orama auth status # View detailed authentication info\n")
|
fmt.Printf(" orama auth status # View detailed authentication info\n")
|
||||||
fmt.Printf(" orama auth logout # Clear all stored credentials\n\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")
|
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
|
// Get gateway URL from active environment
|
||||||
gatewayURL := getGatewayURL()
|
gatewayURL := getGatewayURL()
|
||||||
|
|
||||||
@ -123,7 +130,7 @@ func handleAuthLogin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform simple authentication to add a new credential
|
// Perform simple authentication to add a new credential
|
||||||
creds, err := auth.PerformSimpleAuthentication(gatewayURL)
|
creds, err := auth.PerformSimpleAuthentication(gatewayURL, wallet, namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "❌ Authentication failed: %v\n", err)
|
fmt.Fprintf(os.Stderr, "❌ Authentication failed: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@ -298,7 +298,7 @@ func (cm *ClusterManager) startOlricCluster(ctx context.Context, cluster *Namesp
|
|||||||
NodeID: node.NodeID,
|
NodeID: node.NodeID,
|
||||||
HTTPPort: portBlocks[i].OlricHTTPPort,
|
HTTPPort: portBlocks[i].OlricHTTPPort,
|
||||||
MemberlistPort: portBlocks[i].OlricMemberlistPort,
|
MemberlistPort: portBlocks[i].OlricMemberlistPort,
|
||||||
BindAddr: "0.0.0.0",
|
BindAddr: node.InternalIP,
|
||||||
AdvertiseAddr: node.InternalIP,
|
AdvertiseAddr: node.InternalIP,
|
||||||
PeerAddresses: peerAddresses,
|
PeerAddresses: peerAddresses,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user