-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathmain.go
More file actions
117 lines (104 loc) · 4.48 KB
/
main.go
File metadata and controls
117 lines (104 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"os"
"strings"
mcpproxy "github.com/sigbit/mcp-auth-proxy/pkg/mcp-proxy"
"github.com/spf13/cobra"
)
func getEnvWithDefault(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}
func getEnvBoolWithDefault(key string, defaultValue bool) bool {
if value := os.Getenv(key); value != "" {
if strings.ToLower(value) == "true" || value == "1" {
return true
}
return false
}
return defaultValue
}
func main() {
var listen string
var listenTLS string
var tlsHost string
var tlsDirectoryURL string
var tlsAcceptTOS bool
var dataPath string
var externalURL string
var proxyURL string
var globalSecret string
var googleClientID string
var googleClientSecret string
var googleAllowedUsers string
var githubClientID string
var githubClientSecret string
var githubAllowedUsers string
var password string
var passwordHash string
rootCmd := &cobra.Command{
Use: "mcp-warp",
Run: func(cmd *cobra.Command, args []string) {
var googleAllowedUsersList []string
if googleAllowedUsers != "" {
googleAllowedUsersList = strings.Split(googleAllowedUsers, ",")
for i := range googleAllowedUsersList {
googleAllowedUsersList[i] = strings.TrimSpace(googleAllowedUsersList[i])
}
}
var githubAllowedUsersList []string
if githubAllowedUsers != "" {
githubAllowedUsersList = strings.Split(githubAllowedUsers, ",")
for i := range githubAllowedUsersList {
githubAllowedUsersList[i] = strings.TrimSpace(githubAllowedUsersList[i])
}
}
if err := mcpproxy.Run(
listen,
listenTLS,
tlsHost,
tlsDirectoryURL,
tlsAcceptTOS,
dataPath,
externalURL,
proxyURL,
globalSecret,
googleClientID,
googleClientSecret,
googleAllowedUsersList,
githubClientID,
githubClientSecret,
githubAllowedUsersList,
password,
passwordHash,
); err != nil {
panic(err)
}
},
}
rootCmd.Flags().StringVar(&listen, "listen", getEnvWithDefault("LISTEN", ":80"), "Address to listen on")
rootCmd.Flags().StringVar(&listenTLS, "listen-tls", getEnvWithDefault("TLS_LISTEN", ":443"), "Address to listen on for TLS")
rootCmd.Flags().StringVarP(&tlsHost, "tls-host", "H", getEnvWithDefault("TLS_HOST", ""), "Host name for TLS")
rootCmd.Flags().StringVar(&tlsDirectoryURL, "tls-directory-url", getEnvWithDefault("TLS_DIRECTORY_URL", "https://acme-v02.api.letsencrypt.org/directory"), "ACME directory URL for TLS certificates")
rootCmd.Flags().BoolVar(&tlsAcceptTOS, "tls-accept-tos", getEnvBoolWithDefault("TLS_ACCEPT_TOS", false), "Accept TLS terms of service")
rootCmd.Flags().StringVarP(&dataPath, "data", "d", getEnvWithDefault("DATA_PATH", "./data"), "Path to the data directory")
rootCmd.Flags().StringVarP(&externalURL, "external-url", "e", getEnvWithDefault("EXTERNAL_URL", "http://localhost"), "External URL for the proxy")
rootCmd.Flags().StringVarP(&proxyURL, "proxy-url", "p", getEnvWithDefault("PROXY_URL", "http://localhost:8080"), "Proxy URL for the proxy")
rootCmd.Flags().StringVarP(&globalSecret, "global-secret", "s", getEnvWithDefault("GLOBAL_SECRET", "supersecret"), "Global secret for the proxy")
// Google OAuth configuration
rootCmd.Flags().StringVar(&googleClientID, "google-client-id", getEnvWithDefault("GOOGLE_CLIENT_ID", ""), "Google OAuth client ID")
rootCmd.Flags().StringVar(&googleClientSecret, "google-client-secret", getEnvWithDefault("GOOGLE_CLIENT_SECRET", ""), "Google OAuth client secret")
rootCmd.Flags().StringVar(&googleAllowedUsers, "google-allowed-users", getEnvWithDefault("GOOGLE_ALLOWED_USERS", ""), "Comma-separated list of allowed Google users (emails)")
// GitHub OAuth configuration
rootCmd.Flags().StringVar(&githubClientID, "github-client-id", getEnvWithDefault("GITHUB_CLIENT_ID", ""), "GitHub OAuth client ID")
rootCmd.Flags().StringVar(&githubClientSecret, "github-client-secret", getEnvWithDefault("GITHUB_CLIENT_SECRET", ""), "GitHub OAuth client secret")
rootCmd.Flags().StringVar(&githubAllowedUsers, "github-allowed-users", getEnvWithDefault("GITHUB_ALLOWED_USERS", ""), "Comma-separated list of allowed GitHub users (usernames)")
// Password authentication
rootCmd.Flags().StringVar(&password, "password", getEnvWithDefault("PASSWORD", ""), "Plain text password for authentication (will be hashed with bcrypt)")
rootCmd.Flags().StringVar(&passwordHash, "password-hash", getEnvWithDefault("PASSWORD_HASH", ""), "Bcrypt hash of password for authentication")
if err := rootCmd.Execute(); err != nil {
panic(err)
}
}