The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/services/scimsettings/scimsettingsimpl/scim_settings.go

64 lines
2.0 KiB

package scimsettingsimpl
import (
"context"
"errors"
"fmt"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/scimsettings"
scimsettingsdb "github.com/grafana/grafana/pkg/services/scimsettings/database"
"github.com/grafana/grafana/pkg/services/scimsettings/models"
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
)
type ServiceImpl struct {
store scimsettings.Store
log log.Logger
}
// ProvideService creates a new instance of the SCIM settings service.
func ProvideService(store scimsettings.Store) scimsettings.Service {
return &ServiceImpl{
store: store,
log: log.New("scimsettings.service"),
}
}
var _ scimsettings.Service = (*ServiceImpl)(nil)
// Get retrieves the current SCIM settings from the store.
// It propagates errors, including scimsettings.ErrSettingsNotFound.
func (s *ServiceImpl) Get(ctx context.Context) (*models.ScimSettings, error) {
settings, err := s.store.Get(ctx)
if err != nil {
if !errors.Is(err, scimsettings.ErrSettingsNotFound) {
// Log unexpected errors
s.log.Error("Failed to get SCIM settings from store", "error", err)
}
// Propagate the error (could be ErrSettingsNotFound or other DB error)
return nil, err
}
return settings, nil
}
// Update persists the given SCIM settings to the store.
func (s *ServiceImpl) Update(ctx context.Context, settings *models.ScimSettings) error {
if settings == nil {
return fmt.Errorf("settings cannot be nil")
}
// Add validation logic here if needed before saving.
s.log.Info("Updating SCIM settings", "userSyncEnabled", settings.UserSyncEnabled, "groupSyncEnabled", settings.GroupSyncEnabled)
err := s.store.Update(ctx, settings)
if err != nil {
s.log.Error("Failed to update SCIM settings in store", "error", err)
return fmt.Errorf("failed to update scim settings: %w", err)
}
return nil
}
// AddMigration implements registry.DatabaseMigrator
func (s *ServiceImpl) AddMigration(mg *migrator.Migrator) {
scimsettingsdb.AddMigration(mg)
}