Skip to content

Commit

Permalink
additional validation of user-provided URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
avelanarius committed Oct 31, 2024
1 parent 2548a84 commit 17ef2cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
24 changes: 10 additions & 14 deletions quesma/quesma/config/config_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,22 @@ const (
)

type QuesmaNewConfiguration struct {
BackendConnectors []BackendConnector `koanf:"backendConnectors"`
FrontendConnectors []FrontendConnector `koanf:"frontendConnectors"`
InstallationId string `koanf:"installationId"`
LicenseKey string `koanf:"licenseKey"`
Logging LoggingConfiguration `koanf:"logging"`
IngestStatistics bool `koanf:"ingestStatistics"`
QuesmaInternalTelemetryUrl *Url `koanf:"internalTelemetryUrl"`
Processors []Processor `koanf:"processors"`
Pipelines []Pipeline `koanf:"pipelines"`
DisableTelemetry bool `koanf:"disableTelemetry"`
BackendConnectors []BackendConnector `koanf:"backendConnectors"`
FrontendConnectors []FrontendConnector `koanf:"frontendConnectors"`
InstallationId string `koanf:"installationId"`
LicenseKey string `koanf:"licenseKey"`
Logging LoggingConfiguration `koanf:"logging"`
IngestStatistics bool `koanf:"ingestStatistics"`
Processors []Processor `koanf:"processors"`
Pipelines []Pipeline `koanf:"pipelines"`
DisableTelemetry bool `koanf:"disableTelemetry"`
}

type LoggingConfiguration struct {
Path string `koanf:"path"`
Level *zerolog.Level `koanf:"level"`
RemoteLogDrainUrl *Url `koanf:"remoteUrl"`
FileLogging bool `koanf:"fileLogging"`
RemoteLogDrainUrl *Url
}

type Pipeline struct {
Expand Down Expand Up @@ -118,9 +117,6 @@ type QuesmaProcessorConfig struct {

func LoadV2Config() QuesmaNewConfiguration {
var v2config QuesmaNewConfiguration
v2config.QuesmaInternalTelemetryUrl = telemetryUrl
v2config.Logging.RemoteLogDrainUrl = telemetryUrl

loadConfigFile()
// We have to use custom env provider to allow array overrides
if err := k.Load(Env2JsonProvider("QUESMA_", "_", nil), json.Parser(), koanf.WithMergeFunc(mergeDictFunc)); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion quesma/quesma/config/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: Elastic-2.0
package config

import "net/url"
import (
"fmt"
"net/url"
)

type Url url.URL

Expand All @@ -15,6 +18,12 @@ func (u *Url) UnmarshalText(text []byte) error {
if err != nil {
return err
}
if len(urlValue.Scheme) == 0 {
return fmt.Errorf("URL scheme (e.g. http:// or clickhouse://) is missing from the provided URL: %s", urlValue)
}
if len(urlValue.Port()) == 0 {
return fmt.Errorf("URL port (e.g. 8123 in 'http://localhost:8123') is missing from the provided URL: %s", urlValue)
}
*u = Url(*urlValue)
return nil
}
Expand Down

0 comments on commit 17ef2cd

Please sign in to comment.