mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-03 19:15:13 +00:00

# 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>
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package metadata
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
const bulkIDPrefix = "bulkid:"
|
|
|
|
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, scimContextKey, data)
|
|
}
|
|
|
|
func GetScimContextData(ctx context.Context) 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
|
|
}
|