From 229e76975514f90a619cbd477ad9cfaa72f0ed43 Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Wed, 22 Oct 2025 08:34:42 +0300 Subject: [PATCH 1/2] Enhance gateway configuration by adding RQLiteDSN support and updating default connection settings. Updated config parsing to include RQLiteDSN from YAML and environment variables. Changed default RQLite connection URL from port 4001 to 5001. --- cmd/gateway/config.go | 8 ++++++++ pkg/config/config.go | 10 +++++----- pkg/gateway/gateway.go | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/gateway/config.go b/cmd/gateway/config.go index cc8f345..acfbdcc 100644 --- a/cmd/gateway/config.go +++ b/cmd/gateway/config.go @@ -45,6 +45,7 @@ func parseGatewayConfig(logger *logging.ColoredLogger) *gateway.Config { ListenAddr: ":6001", ClientNamespace: "default", BootstrapPeers: nil, + RQLiteDSN: "", } // 1) YAML (optional) @@ -52,6 +53,7 @@ func parseGatewayConfig(logger *logging.ColoredLogger) *gateway.Config { type yamlCfg struct { ListenAddr string `yaml:"listen_addr"` ClientNamespace string `yaml:"client_namespace"` + RQLiteDSN string `yaml:"rqlite_dsn"` BootstrapPeers []string `yaml:"bootstrap_peers"` } const path = "configs/gateway.yaml" @@ -66,6 +68,9 @@ func parseGatewayConfig(logger *logging.ColoredLogger) *gateway.Config { if v := strings.TrimSpace(y.ClientNamespace); v != "" { cfg.ClientNamespace = v } + if v := strings.TrimSpace(y.RQLiteDSN); v != "" { + cfg.RQLiteDSN = v + } if len(y.BootstrapPeers) > 0 { var bp []string for _, p := range y.BootstrapPeers { @@ -89,6 +94,9 @@ func parseGatewayConfig(logger *logging.ColoredLogger) *gateway.Config { if v := strings.TrimSpace(os.Getenv("GATEWAY_NAMESPACE")); v != "" { cfg.ClientNamespace = v } + if v := strings.TrimSpace(os.Getenv("GATEWAY_RQLITE_DSN")); v != "" { + cfg.RQLiteDSN = v + } if v := strings.TrimSpace(os.Getenv("GATEWAY_BOOTSTRAP_PEERS")); v != "" { parts := strings.Split(v, ",") var bp []string diff --git a/pkg/config/config.go b/pkg/config/config.go index 39bef1b..85e595d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -109,11 +109,11 @@ func DefaultConfig() *Config { }, Discovery: DiscoveryConfig{ BootstrapPeers: []string{ - "/ip4/217.76.54.168/tcp/4001/p2p/12D3KooWDp7xeShVY9uHfqNVPSsJeCKUatAviFZV8Y1joox5nUvx", - "/ip4/217.76.54.178/tcp/4001/p2p/12D3KooWKZnirPwNT4URtNSWK45f6vLkEs4xyUZ792F8Uj1oYnm1", - "/ip4/51.83.128.181/tcp/4001/p2p/12D3KooWBn2Zf1R8v9pEfmz7hDZ5b3oADxfejA3zJBYzKRCzgvhR", - "/ip4/155.133.27.199/tcp/4001/p2p/12D3KooWC69SBzM5QUgrLrfLWUykE8au32X5LwT7zwv9bixrQPm1", - "/ip4/217.76.56.2/tcp/4001/p2p/12D3KooWEiqJHvznxqJ5p2y8mUs6Ky6dfU1xTYFQbyKRCABfcZz4", + "/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj", + // "/ip4/217.76.54.178/tcp/4001/p2p/12D3KooWKZnirPwNT4URtNSWK45f6vLkEs4xyUZ792F8Uj1oYnm1", + // "/ip4/51.83.128.181/tcp/4001/p2p/12D3KooWBn2Zf1R8v9pEfmz7hDZ5b3oADxfejA3zJBYzKRCzgvhR", + // "/ip4/155.133.27.199/tcp/4001/p2p/12D3KooWC69SBzM5QUgrLrfLWUykE8au32X5LwT7zwv9bixrQPm1", + // "/ip4/217.76.56.2/tcp/4001/p2p/12D3KooWEiqJHvznxqJ5p2y8mUs6Ky6dfU1xTYFQbyKRCABfcZz4", }, BootstrapPort: 4001, // Default LibP2P port DiscoveryInterval: time.Second * 15, // Back to 15 seconds for testing diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index 4e140ed..8887237 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -90,7 +90,7 @@ func New(logger *logging.ColoredLogger, cfg *Config) (*Gateway, error) { logger.ComponentInfo(logging.ComponentGeneral, "Initializing RQLite ORM HTTP gateway...") dsn := cfg.RQLiteDSN if dsn == "" { - dsn = "http://localhost:4001" + dsn = "http://localhost:5001" } db, dbErr := sql.Open("rqlite", dsn) if dbErr != nil { From 3694a2de93708e71b3e426639bf325d15fa580d4 Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Wed, 22 Oct 2025 08:41:15 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md for version 0.51.2, enhance API key extraction to support query parameters, and implement internal auth context in status and storage handlers. --- CHANGELOG.md | 14 ++++++++++++-- pkg/gateway/middleware.go | 12 ++++++++++-- pkg/gateway/status_handlers.go | 3 ++- pkg/gateway/storage_handlers.go | 8 ++++++-- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec08ed2..f00c8c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,16 @@ The format is based on [Keep a Changelog][keepachangelog] and adheres to [Semant ### Fixed -## [0.51.0] - 2025-09-26 +## [0.51.2] - 2025-09-26 + +### Added + +### Changed + +- Enhance gateway configuration by adding RQLiteDSN support and updating default connection settings. Updated config parsing to include RQLiteDSN from YAML and environment variables. Changed default RQLite connection URL from port 4001 to 5001. +- Update CHANGELOG.md for version 0.51.2, enhance API key extraction to support query parameters, and implement internal auth context in status and storage handlers. + +## [0.51.1] - 2025-09-26 ### Added @@ -29,6 +38,7 @@ The format is based on [Keep a Changelog][keepachangelog] and adheres to [Semant - Updated node/node.go on loadOrCreateIdentity to use encryption.identity - Updated cli/main.go to remove fallbacks for identity - Updated install-debros-network.sh script to use new ./cmd/identity and fixed port order on print +- Updated makefile and changelog ### Deprecated @@ -37,7 +47,7 @@ The format is based on [Keep a Changelog][keepachangelog] and adheres to [Semant ### Fixed -## [0.50.1] - 2025-09-23 +## [0.50.0] - 2025-09-23 ### Added diff --git a/pkg/gateway/middleware.go b/pkg/gateway/middleware.go index 8f786a3..b22c5bc 100644 --- a/pkg/gateway/middleware.go +++ b/pkg/gateway/middleware.go @@ -130,7 +130,7 @@ func (g *Gateway) authMiddleware(next http.Handler) http.Handler { }) } -// extractAPIKey extracts API key from Authorization or X-API-Key +// extractAPIKey extracts API key from Authorization, X-API-Key header, or query parameters func extractAPIKey(r *http.Request) string { // Prefer Authorization header auth := r.Header.Get("Authorization") @@ -148,10 +148,18 @@ func extractAPIKey(r *http.Request) string { return strings.TrimSpace(auth) } } - // Fallback header + // Fallback to X-API-Key header if v := strings.TrimSpace(r.Header.Get("X-API-Key")); v != "" { return v } + // Fallback to query parameter (for WebSocket support) + if v := strings.TrimSpace(r.URL.Query().Get("api_key")); v != "" { + return v + } + // Also check token query parameter (alternative name) + if v := strings.TrimSpace(r.URL.Query().Get("token")); v != "" { + return v + } return "" } diff --git a/pkg/gateway/status_handlers.go b/pkg/gateway/status_handlers.go index 37d6448..f0666c3 100644 --- a/pkg/gateway/status_handlers.go +++ b/pkg/gateway/status_handlers.go @@ -60,7 +60,8 @@ func (g *Gateway) statusHandler(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusServiceUnavailable, "client not initialized") return } - ctx := r.Context() + // Use internal auth context to bypass client credential requirements + ctx := client.WithInternalAuth(r.Context()) status, err := g.client.Network().GetStatus(ctx) if err != nil { writeError(w, http.StatusInternalServerError, err.Error()) diff --git a/pkg/gateway/storage_handlers.go b/pkg/gateway/storage_handlers.go index 01d0ef0..3c283e1 100644 --- a/pkg/gateway/storage_handlers.go +++ b/pkg/gateway/storage_handlers.go @@ -3,6 +3,8 @@ package gateway import ( "encoding/json" "net/http" + + "github.com/DeBrosOfficial/network/pkg/client" ) // Database HTTP handlers @@ -12,7 +14,8 @@ func (g *Gateway) networkStatusHandler(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusServiceUnavailable, "client not initialized") return } - ctx := r.Context() + // Use internal auth context to bypass client credential requirements + ctx := client.WithInternalAuth(r.Context()) status, err := g.client.Network().GetStatus(ctx) if err != nil { writeError(w, http.StatusInternalServerError, err.Error()) @@ -26,7 +29,8 @@ func (g *Gateway) networkPeersHandler(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusServiceUnavailable, "client not initialized") return } - ctx := r.Context() + // Use internal auth context to bypass client credential requirements + ctx := client.WithInternalAuth(r.Context()) peers, err := g.client.Network().GetPeers(ctx) if err != nil { writeError(w, http.StatusInternalServerError, err.Error())