Skip to content

Commit

Permalink
Flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jenting committed Dec 8, 2024
1 parent 35b9217 commit e7cf824
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
Expand All @@ -19,6 +20,14 @@ import (
)

func main() {
// Define flags for configuration
redisAddr := flag.String("redis-addr", "localhost:16379", "Redis server address")
redisDB := flag.Int("redis-db", 1, "Redis database number")
proxyBackend := flag.String("proxy-backend", "http://localhost:8080", "Backend URL for reverse proxy")

// Parse command-line flags
flag.Parse()

config := ctrl.GetConfigOrDie()

clientset, err := kubernetes.NewForConfig(config)
Expand All @@ -28,9 +37,11 @@ func main() {

userToObjectPatternMapping, groupToObjectPatternMapping := loadRBACPolicyFromConfigMap(clientset, "argocd", "argocd-rbac-cm")

redisClient := initializeRedis("localhost:16379", "", 1)
// Initialize Redis client
redisClient := initializeRedis(*redisAddr, *redisDB)

proxy := createReverseProxy("http://localhost:8080")
// Create a reverse proxy
proxy := createReverseProxy(*proxyBackend)

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
handleRequest(w, r, proxy, redisClient, userToObjectPatternMapping, groupToObjectPatternMapping)
Expand Down Expand Up @@ -63,10 +74,9 @@ func loadRBACPolicyFromConfigMap(clientset *kubernetes.Clientset, namespace, con
return parsePolicyCSV(policyCSV)
}

func initializeRedis(addr, password string, db int) *redis.Client {
func initializeRedis(addr string, db int) *redis.Client {
client := redis.NewClient(&redis.Options{
Addr: addr,
Password: password,
DB: db,
DialTimeout: 5 * time.Second,
})
Expand Down

0 comments on commit e7cf824

Please sign in to comment.