Skip to content

Commit c28e679

Browse files
committed
refactored new code andded file validation
1 parent 2e981e0 commit c28e679

File tree

7 files changed

+820
-577
lines changed

7 files changed

+820
-577
lines changed

internal/config/config.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ func registerExternalDataSourceFlags(fs *flag.FlagSet) {
506506
[]string{},
507507
"List of allowed domains for external data sources.",
508508
)
509+
fs.StringSlice(
510+
ExternalDataSourceAllowedFileTypesKey,
511+
[]string{},
512+
"List of allowed file types for external data sources.",
513+
)
509514
fs.Int64(
510515
ExternalDataSourceMaxBytesKey,
511516
DefExternalDataSourceMaxBytes,
@@ -1610,9 +1615,10 @@ func resolveExternalDataSource() *ExternalDataSource {
16101615
URL: viperInstance.GetString(ExternalDataSourceProxyUrlKey),
16111616
}
16121617
externalDataSource := &ExternalDataSource{
1613-
ProxyURL: proxyURLStruct,
1614-
AllowedDomains: viperInstance.GetStringSlice(ExternalDataSourceAllowDomainsKey),
1615-
MaxBytes: viperInstance.GetInt64(ExternalDataSourceMaxBytesKey),
1618+
ProxyURL: proxyURLStruct,
1619+
AllowedDomains: viperInstance.GetStringSlice(ExternalDataSourceAllowDomainsKey),
1620+
AllowedFileTypes: viperInstance.GetStringSlice(ExternalDataSourceAllowedFileTypesKey),
1621+
MaxBytes: viperInstance.GetInt64(ExternalDataSourceMaxBytesKey),
16161622
}
16171623

16181624
if err := validateAllowedDomains(externalDataSource.AllowedDomains); err != nil {

internal/config/flags.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ var (
146146
FileWatcherMonitoringFrequencyKey = pre(FileWatcherKey) + "monitoring_frequency"
147147
NginxExcludeFilesKey = pre(FileWatcherKey) + "exclude_files"
148148

149-
ExternalDataSourceProxyKey = pre(ExternalDataSourceRootKey) + "proxy"
150-
ExternalDataSourceProxyUrlKey = pre(ExternalDataSourceProxyKey) + "url"
151-
ExternalDataSourceMaxBytesKey = pre(ExternalDataSourceRootKey) + "max_bytes"
152-
ExternalDataSourceAllowDomainsKey = pre(ExternalDataSourceRootKey) + "allowed_domains"
149+
ExternalDataSourceProxyKey = pre(ExternalDataSourceRootKey) + "proxy"
150+
ExternalDataSourceProxyUrlKey = pre(ExternalDataSourceProxyKey) + "url"
151+
ExternalDataSourceMaxBytesKey = pre(ExternalDataSourceRootKey) + "max_bytes"
152+
ExternalDataSourceAllowDomainsKey = pre(ExternalDataSourceRootKey) + "allowed_domains"
153+
ExternalDataSourceAllowedFileTypesKey = pre(ExternalDataSourceRootKey) + "allowed_file_types"
153154
)
154155

155156
func pre(prefixes ...string) string {

internal/config/types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,10 @@ type (
368368
}
369369

370370
ExternalDataSource struct {
371-
ProxyURL ProxyURL `yaml:"proxy" mapstructure:"proxy"`
372-
AllowedDomains []string `yaml:"allowed_domains" mapstructure:"allowed_domains"`
373-
MaxBytes int64 `yaml:"max_bytes" mapstructure:"max_bytes"`
371+
ProxyURL ProxyURL `yaml:"proxy" mapstructure:"proxy"`
372+
AllowedDomains []string `yaml:"allowed_domains" mapstructure:"allowed_domains"`
373+
AllowedFileTypes []string `yaml:"allowed_file_types" mapstructure:"allowed_file_types"`
374+
MaxBytes int64 `yaml:"max_bytes" mapstructure:"max_bytes"`
374375
}
375376
)
376377

0 commit comments

Comments
 (0)