mirror of
https://github.com/Gouryella/drip.git
synced 2026-05-01 22:46:40 +00:00
- Add Bearer Token authentication, supporting tunnel access control via the --auth-bearer parameter - Refactor large modules into smaller, more focused components to improve code maintainability - Update dependency versions, including golang.org/x/crypto, golang.org/x/net, etc. - Add SilenceUsage and SilenceErrors configuration for all CLI commands - Modify connector configuration structure to support the new authentication method - Update recent change log in README with new feature descriptions BREAKING CHANGE: Authentication via Bearer Token is now supported, requiring the new --auth-bearer parameter
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"drip/pkg/config"
|
|
)
|
|
|
|
func buildDaemonArgs(tunnelType string, args []string, subdomain string, localAddress string) []string {
|
|
daemonArgs := append([]string{tunnelType}, args...)
|
|
daemonArgs = append(daemonArgs, "--daemon-child")
|
|
|
|
if subdomain != "" {
|
|
daemonArgs = append(daemonArgs, "--subdomain", subdomain)
|
|
}
|
|
if localAddress != "127.0.0.1" {
|
|
daemonArgs = append(daemonArgs, "--address", localAddress)
|
|
}
|
|
if serverURL != "" {
|
|
daemonArgs = append(daemonArgs, "--server", serverURL)
|
|
}
|
|
if authToken != "" {
|
|
daemonArgs = append(daemonArgs, "--token", authToken)
|
|
}
|
|
if authPass != "" {
|
|
daemonArgs = append(daemonArgs, "--auth", authPass)
|
|
}
|
|
if authBearer != "" {
|
|
daemonArgs = append(daemonArgs, "--auth-bearer", authBearer)
|
|
}
|
|
if insecure {
|
|
daemonArgs = append(daemonArgs, "--insecure")
|
|
}
|
|
if verbose {
|
|
daemonArgs = append(daemonArgs, "--verbose")
|
|
}
|
|
|
|
return daemonArgs
|
|
}
|
|
|
|
func resolveServerAddrAndToken(tunnelType string, port int) (string, string, error) {
|
|
if serverURL != "" {
|
|
return serverURL, authToken, nil
|
|
}
|
|
|
|
cfg, err := config.LoadClientConfig("")
|
|
if err != nil {
|
|
return "", "", fmt.Errorf(`configuration not found.
|
|
|
|
Please run 'drip config init' first, or use flags:
|
|
drip %s %d --server SERVER:PORT --token TOKEN`, tunnelType, port)
|
|
}
|
|
|
|
if cfg.Server == "" {
|
|
return "", "", fmt.Errorf("server address is required")
|
|
}
|
|
|
|
return cfg.Server, cfg.Token, nil
|
|
}
|
|
|
|
func newDaemonInfo(tunnelType string, port int, subdomain string, serverAddr string) *DaemonInfo {
|
|
return &DaemonInfo{
|
|
PID: os.Getpid(),
|
|
Type: tunnelType,
|
|
Port: port,
|
|
Subdomain: subdomain,
|
|
Server: serverAddr,
|
|
StartTime: time.Now(),
|
|
Executable: os.Args[0],
|
|
}
|
|
}
|