mirror of
https://github.com/Gouryella/drip.git
synced 2026-02-24 05:10:43 +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
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"drip/internal/shared/protocol"
|
|
)
|
|
|
|
// TunnelURLBuilder helps construct tunnel URLs consistently.
|
|
type TunnelURLBuilder struct {
|
|
tunnelDomain string
|
|
publicPort int
|
|
}
|
|
|
|
// NewTunnelURLBuilder creates a new URL builder.
|
|
func NewTunnelURLBuilder(tunnelDomain string, publicPort int) *TunnelURLBuilder {
|
|
return &TunnelURLBuilder{
|
|
tunnelDomain: tunnelDomain,
|
|
publicPort: publicPort,
|
|
}
|
|
}
|
|
|
|
// BuildHTTPURL builds an HTTP/HTTPS tunnel URL.
|
|
func (b *TunnelURLBuilder) BuildHTTPURL(subdomain string) string {
|
|
if b.publicPort == 443 {
|
|
return fmt.Sprintf("https://%s.%s", subdomain, b.tunnelDomain)
|
|
}
|
|
return fmt.Sprintf("https://%s.%s:%d", subdomain, b.tunnelDomain, b.publicPort)
|
|
}
|
|
|
|
// BuildTCPURL builds a TCP tunnel URL.
|
|
func (b *TunnelURLBuilder) BuildTCPURL(port int) string {
|
|
return fmt.Sprintf("tcp://%s:%d", b.tunnelDomain, port)
|
|
}
|
|
|
|
// BuildURL builds a tunnel URL based on the tunnel type.
|
|
func (b *TunnelURLBuilder) BuildURL(subdomain string, tunnelType protocol.TunnelType, port int) string {
|
|
if tunnelType == protocol.TunnelTypeHTTP || tunnelType == protocol.TunnelTypeHTTPS {
|
|
return b.BuildHTTPURL(subdomain)
|
|
}
|
|
return b.BuildTCPURL(port)
|
|
}
|