mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:37:31 +00:00
feat: bulk scim v2 endpoint (#9256)
# Which Problems Are Solved * Adds support for the bulk SCIM v2 endpoint # How the Problems Are Solved * Adds support for the bulk SCIM v2 endpoint under `POST /scim/v2/{orgID}/Bulk` # Additional Context Part of #8140 Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
This commit is contained in:
@@ -2,22 +2,57 @@ package metadata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type provisioningDomainKeyType struct{}
|
||||
const bulkIDPrefix = "bulkid:"
|
||||
|
||||
var provisioningDomainKey provisioningDomainKeyType
|
||||
type scimContextKeyType struct{}
|
||||
|
||||
var scimContextKey scimContextKeyType
|
||||
|
||||
type ScimContextData struct {
|
||||
ProvisioningDomain string
|
||||
ExternalIDScopedMetadataKey ScopedKey
|
||||
bulkIDMapping map[string]string
|
||||
}
|
||||
|
||||
func NewScimContextData() ScimContextData {
|
||||
return ScimContextData{
|
||||
ExternalIDScopedMetadataKey: ScopedKey(KeyExternalId),
|
||||
bulkIDMapping: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func SetScimContextData(ctx context.Context, data ScimContextData) context.Context {
|
||||
return context.WithValue(ctx, provisioningDomainKey, data)
|
||||
return context.WithValue(ctx, scimContextKey, data)
|
||||
}
|
||||
|
||||
func GetScimContextData(ctx context.Context) ScimContextData {
|
||||
data, _ := ctx.Value(provisioningDomainKey).(ScimContextData)
|
||||
data, _ := ctx.Value(scimContextKey).(ScimContextData)
|
||||
return data
|
||||
}
|
||||
|
||||
func SetScimBulkIDMapping(ctx context.Context, bulkID, zitadelID string) context.Context {
|
||||
data := GetScimContextData(ctx)
|
||||
data.bulkIDMapping[bulkID] = zitadelID
|
||||
return ctx
|
||||
}
|
||||
|
||||
func ResolveScimBulkIDIfNeeded(ctx context.Context, resourceID string) (string, error) {
|
||||
lowerResourceID := strings.ToLower(resourceID)
|
||||
if !strings.HasPrefix(lowerResourceID, bulkIDPrefix) {
|
||||
return resourceID, nil
|
||||
}
|
||||
|
||||
bulkID := strings.TrimPrefix(lowerResourceID, bulkIDPrefix)
|
||||
data := GetScimContextData(ctx)
|
||||
zitadelID, ok := data.bulkIDMapping[bulkID]
|
||||
if !ok {
|
||||
return bulkID, zerrors.ThrowInvalidArgumentf(nil, "SCIM-BLK4", "Could not resolve bulkID %v to created ID", bulkID)
|
||||
}
|
||||
|
||||
return zitadelID, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user