providers/saml: fix SAML metadata import API requiring flow slug inst… (#6729)

* providers/saml: fix SAML metadata import API requiring flow slug instead of pk

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* replace format_exc_info with dict_tracebacks, and only for json logger

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-09-01 12:59:25 +02:00 committed by GitHub
parent 8f219a813b
commit a39fef11b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 11 deletions

View File

@ -13,10 +13,9 @@ from rest_framework.decorators import action
from rest_framework.fields import CharField, FileField, SerializerMethodField from rest_framework.fields import CharField, FileField, SerializerMethodField
from rest_framework.parsers import MultiPartParser from rest_framework.parsers import MultiPartParser
from rest_framework.permissions import AllowAny from rest_framework.permissions import AllowAny
from rest_framework.relations import SlugRelatedField
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.serializers import ValidationError from rest_framework.serializers import PrimaryKeyRelatedField, ValidationError
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
from structlog.stdlib import get_logger from structlog.stdlib import get_logger
@ -168,10 +167,8 @@ class SAMLProviderImportSerializer(PassiveSerializer):
"""Import saml provider from XML Metadata""" """Import saml provider from XML Metadata"""
name = CharField(required=True) name = CharField(required=True)
# Using SlugField because https://github.com/OpenAPITools/openapi-generator/issues/3278 authorization_flow = PrimaryKeyRelatedField(
authorization_flow = SlugRelatedField(
queryset=Flow.objects.filter(designation=FlowDesignation.AUTHORIZATION), queryset=Flow.objects.filter(designation=FlowDesignation.AUTHORIZATION),
slug_field="slug",
) )
file = FileField() file = FileField()

View File

@ -89,7 +89,7 @@ class TestSAMLProviderAPI(APITestCase):
{ {
"file": metadata, "file": metadata,
"name": generate_id(), "name": generate_id(),
"authorization_flow": create_test_flow(FlowDesignation.AUTHORIZATION).slug, "authorization_flow": create_test_flow(FlowDesignation.AUTHORIZATION).pk,
}, },
format="multipart", format="multipart",
) )
@ -106,7 +106,7 @@ class TestSAMLProviderAPI(APITestCase):
{ {
"file": metadata, "file": metadata,
"name": generate_id(), "name": generate_id(),
"authorization_flow": create_test_flow().slug, "authorization_flow": create_test_flow().pk,
}, },
format="multipart", format="multipart",
) )

View File

@ -402,7 +402,6 @@ LOG_PRE_CHAIN = [
structlog.stdlib.add_logger_name, structlog.stdlib.add_logger_name,
structlog.processors.TimeStamper(), structlog.processors.TimeStamper(),
structlog.processors.StackInfoRenderer(), structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
] ]
LOGGING = { LOGGING = {
@ -412,7 +411,7 @@ LOGGING = {
"json": { "json": {
"()": structlog.stdlib.ProcessorFormatter, "()": structlog.stdlib.ProcessorFormatter,
"processor": structlog.processors.JSONRenderer(sort_keys=True), "processor": structlog.processors.JSONRenderer(sort_keys=True),
"foreign_pre_chain": LOG_PRE_CHAIN, "foreign_pre_chain": LOG_PRE_CHAIN + [structlog.processors.dict_tracebacks],
}, },
"console": { "console": {
"()": structlog.stdlib.ProcessorFormatter, "()": structlog.stdlib.ProcessorFormatter,

View File

@ -38459,8 +38459,7 @@ components:
minLength: 1 minLength: 1
authorization_flow: authorization_flow:
type: string type: string
minLength: 1 format: uuid
description: Visible in the URL.
file: file:
type: string type: string
format: binary format: binary