SCIM: Add successful SCIM-provisioned user login usage stat (#108273)
* SCIM: add usage stat boolean for successful login * revert unrelated change * rename scimSuccessfulLogins * clean up
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
claims "github.com/grafana/authlib/types"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
@@ -126,6 +127,18 @@ type UserSync struct {
|
||||
lastSeenSF *singleflight.Group
|
||||
scimUtil *scimutil.SCIMUtil
|
||||
staticConfig *StaticSCIMConfig
|
||||
scimSuccessfulLogin atomic.Bool
|
||||
}
|
||||
|
||||
// GetUsageStats implements registry.ProvidesUsageStats
|
||||
func (s *UserSync) GetUsageStats(ctx context.Context) map[string]any {
|
||||
stats := map[string]any{}
|
||||
if s.scimSuccessfulLogin.Load() {
|
||||
stats["stats.features.scim.has_successful_login.count"] = 1
|
||||
} else {
|
||||
stats["stats.features.scim.has_successful_login.count"] = 0
|
||||
}
|
||||
return stats
|
||||
}
|
||||
|
||||
// ValidateUserProvisioningHook validates if a user should be allowed access based on provisioning status and configuration
|
||||
@@ -169,6 +182,8 @@ func (s *UserSync) ValidateUserProvisioningHook(ctx context.Context, currentIden
|
||||
return errUserExternalUIDMismatch.Errorf("the provisioned user.ExternalUID does not match the authinfo.ExternalUID")
|
||||
}
|
||||
log.Debug("User is provisioned, access granted")
|
||||
s.scimSuccessfulLogin.Store(true)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user