LBAC for datasources: Override lbac rules if present when updating via datasources endpoints (#94608)

bloc updates to datasources
This commit is contained in:
Eric Leijonmarck 2024-10-17 11:29:30 +01:00 committed by GitHub
parent 573b40ab98
commit a46ff09bf9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -205,6 +205,8 @@ type UpdateDataSourceCommand struct {
EncryptedSecureJsonData map[string][]byte `json:"-"`
UpdateSecretFn UpdateSecretFn `json:"-"`
IgnoreOldSecureJsonData bool `json:"-"`
OnlyUpdateLBACRulesFromAPI bool `json:"-"`
}
// DeleteDataSourceCommand will delete a DataSource based on OrgID as well as the UID (preferred), ID, or Name.

View File

@ -534,6 +534,24 @@ func (s *Service) UpdateDataSource(ctx context.Context, cmd *datasources.UpdateD
}
}
// TODO: we will eventually remove this check for moving the resource to it's separate API
if s.features != nil && s.features.IsEnabled(ctx, featuremgmt.FlagTeamHttpHeaders) && !cmd.OnlyUpdateLBACRulesFromAPI {
s.logger.Debug("Overriding LBAC rules with stored ones",
"reason", "update_lbac_rules_from_datasource_api",
"action", "use_updateLBACRules_API",
"datasource_id", dataSource.ID,
"datasource_uid", dataSource.UID)
if dataSource.JsonData != nil {
previousRules := dataSource.JsonData.Get("teamHttpHeaders")
if previousRules == nil {
cmd.JsonData.Del("teamHttpHeaders")
} else {
cmd.JsonData.Set("teamHttpHeaders", previousRules)
}
}
}
if cmd.Name != "" && cmd.Name != dataSource.Name {
query := &datasources.GetDataSourceQuery{
Name: cmd.Name,