Skip to content

Commit

Permalink
Remove Config Backwards Compatibility: Account GDPR/CCPA Integration …
Browse files Browse the repository at this point in the history
…Enabled (prebid#3155)
  • Loading branch information
bsardo authored Oct 3, 2023
1 parent 1360786 commit a2e387f
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 526 deletions.
20 changes: 0 additions & 20 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ func GetAccount(ctx context.Context, cfg *config.Configuration, fetcher stored_r
Message: fmt.Sprintf("The prebid-server account config for account id \"%s\" is malformed. Please reach out to the prebid server host.", accountID),
}}
}
usingGDPRChannelEnabled := useGDPRChannelEnabled(account)
usingCCPAChannelEnabled := useCCPAChannelEnabled(account)

if usingGDPRChannelEnabled {
me.RecordAccountGDPRChannelEnabledWarning(accountID)
}
if usingCCPAChannelEnabled {
me.RecordAccountCCPAChannelEnabledWarning(accountID)
}
if usingGDPRChannelEnabled || usingCCPAChannelEnabled {
me.RecordAccountUpgradeStatus(accountID)
}

if err != nil {
errs = append(errs, err)
Expand Down Expand Up @@ -154,11 +142,3 @@ func setDerivedConfig(account *config.Account) {
}
}
}

func useGDPRChannelEnabled(account *config.Account) bool {
return account.GDPR.ChannelEnabled.IsSet() && !account.GDPR.IntegrationEnabled.IsSet()
}

func useCCPAChannelEnabled(account *config.Account) bool {
return account.CCPA.ChannelEnabled.IsSet() && !account.CCPA.IntegrationEnabled.IsSet()
}
103 changes: 0 additions & 103 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,106 +214,3 @@ func TestSetDerivedConfig(t *testing.T) {
assert.Equal(t, account.GDPR.Purpose1.EnforceAlgoID, tt.wantEnforceAlgoID, tt.description)
}
}

func TestGdprCcpaChannelEnabledMetrics(t *testing.T) {
cfg := &config.Configuration{}
fetcher := &mockAccountFetcher{}
assert.NoError(t, cfg.MarshalAccountDefaults())

testCases := []struct {
name string
givenAccountID string
givenMetric string
expectedMetricCount int
}{
{
name: "ChannelEnabledGDPR",
givenAccountID: "gdpr_channel_enabled_acct",
givenMetric: "RecordAccountGDPRChannelEnabledWarning",
expectedMetricCount: 1,
},
{
name: "ChannelEnabledCCPA",
givenAccountID: "ccpa_channel_enabled_acct",
givenMetric: "RecordAccountCCPAChannelEnabledWarning",
expectedMetricCount: 1,
},
{
name: "NotChannelEnabledCCPA",
givenAccountID: "valid_acct",
givenMetric: "RecordAccountCCPAChannelEnabledWarning",
expectedMetricCount: 0,
},
{
name: "NotChannelEnabledGDPR",
givenAccountID: "valid_acct",
givenMetric: "RecordAccountGDPRChannelEnabledWarning",
expectedMetricCount: 0,
},
}

for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
metrics := &metrics.MetricsEngineMock{}
metrics.Mock.On(test.givenMetric, mock.Anything, mock.Anything).Return()
metrics.Mock.On("RecordAccountUpgradeStatus", mock.Anything, mock.Anything).Return()

_, _ = GetAccount(context.Background(), cfg, fetcher, test.givenAccountID, metrics)

metrics.AssertNumberOfCalls(t, test.givenMetric, test.expectedMetricCount)
})
}
}

func TestAccountUpgradeStatusGetAccount(t *testing.T) {
cfg := &config.Configuration{}
fetcher := &mockAccountFetcher{}
assert.NoError(t, cfg.MarshalAccountDefaults())

testCases := []struct {
name string
givenAccountIDs []string
givenMetrics []string
expectedMetricCount int
}{
{
name: "ZeroDeprecatedConfigs",
givenAccountIDs: []string{"valid_acct"},
givenMetrics: []string{},
expectedMetricCount: 0,
},
{
name: "OneDeprecatedConfigGDPRChannelEnabled",
givenAccountIDs: []string{"gdpr_channel_enabled_acct"},
givenMetrics: []string{"RecordAccountGDPRChannelEnabledWarning"},
expectedMetricCount: 1,
},
{
name: "OneDeprecatedConfigCCPAChannelEnabled",
givenAccountIDs: []string{"ccpa_channel_enabled_acct"},
givenMetrics: []string{"RecordAccountCCPAChannelEnabledWarning"},
expectedMetricCount: 1,
},
{
name: "MultipleAccountsWithDeprecatedConfigs",
givenAccountIDs: []string{"gdpr_channel_enabled_acct", "ccpa_channel_enabled_acct"},
givenMetrics: []string{"RecordAccountGDPRChannelEnabledWarning", "RecordAccountCCPAChannelEnabledWarning"},
expectedMetricCount: 2,
},
}

for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
metrics := &metrics.MetricsEngineMock{}
for _, metric := range test.givenMetrics {
metrics.Mock.On(metric, mock.Anything, mock.Anything).Return()
}
metrics.Mock.On("RecordAccountUpgradeStatus", mock.Anything, mock.Anything).Return()

for _, accountID := range test.givenAccountIDs {
_, _ = GetAccount(context.Background(), cfg, fetcher, accountID, metrics)
}
metrics.AssertNumberOfCalls(t, "RecordAccountUpgradeStatus", test.expectedMetricCount)
})
}
}
18 changes: 4 additions & 14 deletions config/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ type CookieSync struct {

// AccountCCPA represents account-specific CCPA configuration
type AccountCCPA struct {
Enabled *bool `mapstructure:"enabled" json:"enabled,omitempty"`
IntegrationEnabled AccountChannel `mapstructure:"integration_enabled" json:"integration_enabled"`
ChannelEnabled AccountChannel `mapstructure:"channel_enabled" json:"channel_enabled"`
Enabled *bool `mapstructure:"enabled" json:"enabled,omitempty"`
ChannelEnabled AccountChannel `mapstructure:"channel_enabled" json:"channel_enabled"`
}

type AccountPriceFloors struct {
Expand Down Expand Up @@ -94,17 +93,14 @@ func (pf *AccountPriceFloors) IsAdjustForBidAdjustmentEnabled() bool {
func (a *AccountCCPA) EnabledForChannelType(channelType ChannelType) *bool {
if channelEnabled := a.ChannelEnabled.GetByChannelType(channelType); channelEnabled != nil {
return channelEnabled
} else if integrationEnabled := a.IntegrationEnabled.GetByChannelType(channelType); integrationEnabled != nil {
return integrationEnabled
}
return a.Enabled
}

// AccountGDPR represents account-specific GDPR configuration
type AccountGDPR struct {
Enabled *bool `mapstructure:"enabled" json:"enabled,omitempty"`
IntegrationEnabled AccountChannel `mapstructure:"integration_enabled" json:"integration_enabled"`
ChannelEnabled AccountChannel `mapstructure:"channel_enabled" json:"channel_enabled"`
Enabled *bool `mapstructure:"enabled" json:"enabled,omitempty"`
ChannelEnabled AccountChannel `mapstructure:"channel_enabled" json:"channel_enabled"`
// Array of basic enforcement vendors that is used to create the hash table so vendor names can be instantly accessed
BasicEnforcementVendors []string `mapstructure:"basic_enforcement_vendors" json:"basic_enforcement_vendors"`
BasicEnforcementVendorsMap map[string]struct{}
Expand All @@ -129,8 +125,6 @@ type AccountGDPR struct {
func (a *AccountGDPR) EnabledForChannelType(channelType ChannelType) *bool {
if channelEnabled := a.ChannelEnabled.GetByChannelType(channelType); channelEnabled != nil {
return channelEnabled
} else if integrationEnabled := a.IntegrationEnabled.GetByChannelType(channelType); integrationEnabled != nil {
return integrationEnabled
}
return a.Enabled
}
Expand Down Expand Up @@ -298,10 +292,6 @@ func (m AccountModules) ModuleConfig(id string) (json.RawMessage, error) {
return m[vendor][module], nil
}

func (a *AccountChannel) IsSet() bool {
return a.AMP != nil || a.App != nil || a.Video != nil || a.Web != nil || a.DOOH != nil
}

type AccountPrivacy struct {
AllowActivities *AllowActivities `mapstructure:"allowactivities" json:"allowactivities"`
IPv6Config IPv6 `mapstructure:"ipv6" json:"ipv6"`
Expand Down
Loading

0 comments on commit a2e387f

Please sign in to comment.