Skip to content

Commit

Permalink
added input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mmelograno committed Jan 17, 2024
1 parent 80fae64 commit 0d2ade1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/splitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func main() {
fmt.Println("error reading config: ", err.Error())
os.Exit(1)
}
fmt.Println("cfg.SDK.FlagSetsFilter", cfg.SDK.FlagSetsFilter)
handleFlags(cfg)

loggerCfg, err := cfg.Logger.ToLoggerOptions()
Expand Down
2 changes: 1 addition & 1 deletion splitio/commitsha.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package splitio

const CommitSHA = "b98165e"
const CommitSHA = "80fae64"
6 changes: 5 additions & 1 deletion splitio/conf/splitd.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ type SDK struct {
URLs URLs `yaml:"urls"`
FeatureFlags FeatureFlags `yaml:"featureFlags"`
Impressions Impressions `yaml:"impressions"`
Events Events `yank:"events"`
Events Events `yaml:"events"`
FlagSetsFilter []string `yaml:"flagSetsFilter"`
}

func (s *SDK) PopulateWithDefaults() {
Expand All @@ -139,6 +140,7 @@ func (s *SDK) PopulateWithDefaults() {
s.FeatureFlags.PopulateWithDefaults()
s.Impressions.PopulateWithDefaults()
s.Events.PopulateWithDefaults()
s.FlagSetsFilter = []string{}
}

type FeatureFlags struct {
Expand Down Expand Up @@ -209,6 +211,8 @@ func (s *SDK) ToSDKConf() *sdkConf.Config {
lang.SetIfNotEmpty(&cfg.Events.QueueSize, s.Events.QueueSize)
lang.MapIfNotNil(&cfg.Events.SyncPeriod, s.Events.RefreshRateSeconds, durationFromSeconds)
s.URLs.updateSDKConfURLs(&cfg.URLs)
// lang.SetIfNotNil(&cfg.FlagSetsFilter, s.FlagSetsFilter)
fmt.Println("TOSDKCONFIG", s.FlagSetsFilter)
return cfg
}

Expand Down
1 change: 1 addition & 0 deletions splitio/sdk/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func DefaultConfig() *Config {
Streaming: "https://streaming.split.io/sse",
Telemetry: "https://telemetry.split.io/api/v1",
},
FlagSetsFilter: []string{},
}
}

Expand Down
1 change: 1 addition & 0 deletions splitio/sdk/conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ func TestSDKConf(t *testing.T) {
assert.Equal(t, int64(dc.Segments.UpdateBufferSize), adv.SegmentUpdateQueueSize)
assert.Equal(t, int(dc.Splits.SyncPeriod.Seconds()), adv.SplitsRefreshRate)
assert.Equal(t, int(dc.Segments.SyncPeriod.Seconds()), adv.SegmentsRefreshRate)
assert.Equal(t, dc.FlagSetsFilter, adv.FlagSetsFilter)
}
10 changes: 9 additions & 1 deletion splitio/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ func New(logger logging.LoggerInterface, apikey string, c *conf.Config) (*Impl,
md := dtos.Metadata{SDKVersion: fmt.Sprintf("splitd-%s", splitio.Version)}
advCfg := c.ToAdvancedConfig()

flagSetsFilter := flagsets.NewFlagSetFilter(advCfg.FlagSetsFilter)
flagSets, errs := flagsets.SanitizeMany(advCfg.FlagSetsFilter)
if len(errs) != 0 {
for _, err := range errs {
if errType, ok := err.(dtos.FlagSetValidatonError); ok {
logger.Warning(errType.Message)
}
}
}
flagSetsFilter := flagsets.NewFlagSetFilter(flagSets)

stores := setupStorages(c, flagSetsFilter)
impc, err := setupImpressionsComponents(&c.Impressions, stores.telemetry)
Expand Down

0 comments on commit 0d2ade1

Please sign in to comment.